Loading…

Maximum Adverse Excursion Budget

Most stop distances are picked from habit, a round number of pips, or whatever a rule of thumb suggested. Maximum adverse excursion asks a more direct question: how far did price actually move against your winning trades before they turned around and became winners. A stop tighter than that worst moment cuts a trade off before it had the chance to work, which quietly turns winners into losers for no reason connected to the edge itself. MT4's order history stores an open price and a close price, nothing about what happened in between. This script reconstructs the missing piece from M1 bar data: for every winning trade in the history matching the filter, it walks the M1 low (for a buy) or high (for a sell) across the trade's own open-to-close window and finds the worst point reached, converted to pips. Losing trades are left out on purpose - they define nothing about how tight a stop the edge can tolerate, only how well the exit was already working. The result is a distribution, not a single number, reported pooled and per symbol: median, 75th, 90th and 95th percentile MAE, plus the single worst case. A stop set at the 90th percentile would have let roughly nine in ten of these winners run to their result; the remaining tenth went through more heat than that before turning around. Notes and limitations - Only winning trades (net of swap and commission) are measured. Losers are excluded by design - they cannot tell you how tight a profitable stop could have been. - A trade whose open-to-close window falls outside the locally downloaded M1 history is skipped and counted as skipped, never estimated. The skipped count is printed so a suspiciously small measured sample is not mistaken for a complete one. - The stop that was actually on the trade, if any, is not used for anything here - the measurement is what price did, independent of where the real stop happened to sit. - Spread is not subtracted from the excursion figure. On a wide-spread symbol the true worst price for a long includes crossing the spread to exit, which this script does not model. - A percentile computed from a small or unusual sample of winners reflects that sample, not a permanent property of the strategy - revisit it as more trades accumulate. - On MQL5, a position built from more than one entry fill or closed via more than one partial exit is folded into a single trade: the earliest entry deal supplies the open time/price and every deal on the position is summed for net P/L. This matches the common single-fill case exactly but is an approximation for a position that was scaled in or partially closed - the MQL4 version has no partial-close concept at all, since MT4 orders are never partially closed in place.

Script · MT5 · v1.0 · Free

About Maximum Adverse Excursion Budget

Maximum Adverse Excursion Budget is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Symbol filter, Magic filter and From date. MQL source code included.

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

Settings

SettingDefaultWhat it does
Symbol filterSymbol filter ("" = every symbol)
Magic filter-1Magic number filter (-1 = every magic; long: MQL5 magic is 64-bit)
From date0Earliest close time (0 = all loaded history)
To date0Latest close time (0 = up to now)
Min winners10Minimum winning trades required before reporting

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 → Scripts.
  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 script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria