Excursion Analyser
Most stop and target distances are chosen from a round number or a textbook multiple of ATR, then kept unquestioned. This EA measures instead of guessing: every tick it walks the open trades matching its filters and tracks the maximum favourable excursion (MFE - the best price ever reached in the trade's favour) and the maximum adverse excursion (MAE - the worst it ever moved against it), both in pips, relative to the trade's own open price. The moment a tracked trade disappears from the open pool it is looked up in history, logged to CSV with its final profit, MFE and MAE, and folded into a running recommendation. The recommendation is deliberately asymmetric and deliberately winners only. The suggested stop is a high percentile (80% by default) of MAE measured on trades that went on to WIN - how far price dipped against them before turning - because a stop derived from losers is meaningless: by definition nothing you set there would have saved them, since they never turned. Sizing the stop from what winners tolerated means it is wide enough to let a typical winning trade breathe instead of shaking it out on noise. The suggested target is the median MFE of the same winners - the distance price has actually tended to reach before giving profit back - rather than an arbitrary multiple of the stop. Both percentiles are configurable, so a more conservative trader can widen the stop percentile toward the extreme end of the distribution, or narrow the target percentile to bank profit earlier. Notes and limitations Excursion is measured only while this EA is attached and running - a trade opened before attach, or while the terminal was closed, is picked up mid-flight with whatever excursion happens from that point forward, and a trade that closes while the EA is detached is never logged. The recommendation reflects the recent past, not a guarantee about the next trade; it should inform a stop and target choice, not replace judgement about changing market conditions. Pip conversion uses the account server's own tick data for each symbol, so results are specific to this broker's quoting. This EA assumes no partial closes; a position that is partially closed and later fully closed is logged once, at final close, using the whole deal history tied to that position id.
Expert advisor · MT5 · v1.0 · Free
About Excursion Analyser
Excursion Analyser is a script for MetaTrader 5. It has 7 settings, such as Magic filter, This symbol only and Min closed for recommendation. MQL source code included.
Files in the download: ExcursionAnalyser.ex5, ExcursionAnalyser.mq5, ExcursionAnalyser.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Magic filter | -1 | Magic number to watch, -1 = every magic number |
| This symbol only | false | Restrict tracking to this chart's symbol only |
| Min closed for recommendation | 20 | Closed winners required before a recommendation is shown |
| Mae stop percentile | 80 | Percentile of winners' MAE used for the recommended stop |
| Mfe target percentile | 50 | Percentile of winners' MFE used for the recommended target |
| Max history trades | 300 | Closed trades kept in memory for the recommendation (oldest dropped first) |
| Csv file name | ExcursionAnalyser.csv | Per-trade log, in MQL5\Files |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: ATR · MT5 Expert Advisor · MQL5 Source Code