Loading…

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 · MT5 · v1.0 · Free

About MAE Based Stop Adjuster

MAE Based Stop Adjuster is an expert advisor (trading robot) for MetaTrader 5. It increases the lot size after a losing trade (martingale). It has 10 settings, such as Lookback trades, Min samples and Mae multiplier. MQL source code included.

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

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

Settings

SettingDefaultWhat it does
Lookback trades20Most recent winning closed trades sampled for MAE
Min samples5Minimum winners required before adjusting any stop
Mae multiplier1.5Safety multiplier applied to the average MAE
Min stop pips8Floor stop distance regardless of measured MAE
Max stop pips200Cap stop distance regardless of measured MAE
Magic filter-1Magic number filter (-1 = every magic)
Current symbol onlytrueRestrict to this chart's symbol
Recalc interval min30Minutes between rescans of trade history
Max retries5PositionModify attempts 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: Martingale · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria