MAE Based Stop Adjuster
A stop distance picked from a round number of pips, or from an indicator value with no connection to the strategy's own trade history, is a guess. This EA replaces the guess with a measurement: it walks the account's closed WINNING trades, measures how far each one dipped against its entry before eventually closing in profit (its maximum adverse excursion, MAE), and keeps a rolling average of that distance over the most recent InpLookbackTrades winners. Open positions matching the magic/symbol filter then have their stop calibrated to InpMaeMultiplier times that rolling average, bounded by InpMinStopPips and InpMaxStopPips. A stop only ever tightens toward the calibrated distance - it never widens an existing tighter stop - so this EA is safe to run alongside a separate breakeven or trailing tool without fighting over the same ticket. The terminal keeps no MAE figure anywhere; it has to be reconstructed from price history after the fact by walking M1 bars between each trade's open and close time. M1 history depth is broker-limited, so trades whose history has already rolled off are simply skipped rather than guessed at - the average is built only from trades that can actually be measured. Recalculation is throttled to InpRecalcIntervalMin because a full history walk is not something to repeat every tick. Notes and limitations - Needs real trade history to work from; on a brand-new account or magic number it does nothing until enough winners accumulate. - MAE is measured on M1 bar highs/lows, which is a close approximation of intra-bar adverse excursion, not a tick-perfect one. - Trades whose M1 history has rolled off the broker's retention window are skipped for measurement, not estimated by any other means - the sample size reported is always trades that were actually measurable. - Only tightens stops, and only on positions that already have one moved or a fresh one applied where none existed; it does not set take-profit or manage anything besides the stop loss. - A calibrated stop that would land inside the broker's stop or freeze level is skipped for that pass and logged. - This EA never opens a new position; it only manages trades already open that match its filters.
Expert advisor · MT4 · v1.0 · Free
About MAE Based Stop Adjuster
MAE Based Stop Adjuster is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 10 settings, such as Lookback trades, Min samples and Mae multiplier. MQL source code included.
Files in the download: MaeBasedStopAdjuster.ex4, MaeBasedStopAdjuster.mq4, MaeBasedStopAdjuster.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Lookback trades | 20 | Most recent winning closed trades sampled for MAE |
| Min samples | 5 | Minimum winners required before adjusting any stop |
| Mae multiplier | 1.5 | Safety multiplier applied to the average MAE |
| Min stop pips | 8 | Floor stop distance regardless of measured MAE |
| Max stop pips | 200 | Cap stop distance regardless of measured MAE |
| Magic filter | -1 | Magic number filter (-1 = every magic) |
| Current symbol only | true | Restrict to this chart's symbol |
| Recalc interval min | 30 | Minutes between rescans of trade history |
| Max retries | 5 | OrderModify attempts before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Alerts · MT4 Expert Advisor · MQL4 Source Code