Loading…

Managed Re Entry After Stop

A stop-out is not always proof the underlying idea was wrong; sometimes the stop was simply tighter than the noise on the way to being right. This scans closed trade history for tickets matching a magic number that closed on their own stop-loss - not a manual close, not a take-profit - and, if the original direction still checks out against a plain moving- average trend filter, sends one reduced-size re-entry at the same stop and target distance (in points) as the original trade. The tool does not know the real strategy's entry logic - nothing in MQL4 exposes that to a separate program - so the "condition still holds" check is a documented generic proxy: is price still on the correct side of a configurable moving average. This is stated plainly rather than pretending to reconstruct the original signal exactly. The one-shot behaviour is the entire point, and it is enforced two ways. Every original stop-out ticket's number is recorded in a GlobalVariable the moment it has been evaluated, so it is never processed twice, even across an EA restart. And the re-entry order itself is tagged in its own order comment; if that re-entry later stops out too, the tag is recognised and the chain is stood down rather than re-entered again. Without both guards this degenerates into an unbounded martingale chase disguised as a single "second chance". Notes and limitations - The "original condition still holds" check is a generic trend-agreement proxy, not a reconstruction of whatever actually opened the original trade. On a choppy symbol this can approve or refuse a re-entry for reasons unrelated to the real original signal. - Only one re-entry is ever attempted per original stop-out, and a re-entry's own stop-out is never re-entered again, by design. - Trades that closed via manual intervention, take-profit, or any other reason besides touching their own recorded stop-loss are not treated as stop-outs and are never re-entered. - If AutoTrading is off at the moment a re-entry qualifies, the decision is deferred and retried on the next scan rather than abandoned outright - once trading resumes, a qualifying re-entry still fires as long as it has not aged past whatever trend condition it depends on.

Expert advisor · MT5 · v1.0 · Free

About Managed Re Entry After Stop

Managed Re Entry After Stop is an expert advisor (trading robot) for MetaTrader 5 based on Moving Average. It increases the lot size after a losing trade (martingale). It has 8 settings, such as Magic filter, Reentry risk multiplier and Trend filter ma period. MQL source code included.

Files in the download: ManagedReentryAfterStop.ex5, ManagedReentryAfterStop.mq5, ManagedReentryAfterStop.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Magic filter12345Magic number of trades to watch and re-enter for
Reentry risk multiplier0.5Re-entry lot size as a fraction of the stopped-out trade's lot size
Trend filter ma period50Period of the simple MA used as the "original condition still holds" proxy
Trend filter ma methodMODE_SMAMethod for the trend filter MA
Reentry cooldown sec30Minimum seconds after the stop-out before the re-entry is sent
Scan interval sec15Seconds between history scans for newly closed tickets
Max retries5Attempts per order send before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Trend · Martingale · Moving Average · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria