Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Fresh: Metatrader 5 Script | After-Exit Analyzer - what price did after you closed: stopped-out trades that…

Fresh MQL5 code release – perfect for enhancing your MT4/MT5 strategies.

Most trade reports end at the exit. This script looks at what happened next.

For every closed position in the selected period it reads the following M1 bars and measures, from the exit price: the best move in the trade's direction (how much was left on the table), the worst move against it (how much the exit saved), and whether the take-profit level was reached after the exit, and how many minutes later.

What the results tell you

  • Stop-loss exits - how many later reached their take profit, the median time until they did, and the median move after the stop. Many stopped-out trades that later reach the target point to a stop that is too tight or placed at an obvious level.
  • Take-profit exits - how far price kept running after the target, and how often it ran a further 1R or more. A large share suggests the target or exit rule cuts winners short.
  • Other exits (manual, EA logic, mobile, stop out) - the median move left after the exit and how often the original target was still reached.

Moves are shown in R (multiples of the initial stop distance) when the position had a stop loss, otherwise in points.

Recover from drawdowns intelligently with the Auto Recovery Expert Advisor for MT4/MT5. Perfect for hedging strategies. Learn more.

Image for After-Exit Analyzer - what price did after you closed: stopped-out trades that later hit TP, profit left after exits

Output

  • A summary panel on the chart.
  • A per-position table in the Experts tab, newest exit first.
  • A CSV file in MQL5\Files (AfterExit_<login>.csv) with one row per position for your own analysis.

Inputs

Input Default Meaning
History to analyse (days) 90 Exit time window
Symbol filter "" Empty = all symbols
Magic number filter -1 -1 = all, 0 = manual trades
Market hours to watch after each exit 24 Counted in M1 bars, so weekends do not use up the window
Positions listed in the Experts log 25 Rows printed in the Experts tab
Write a CSV file true Writes AfterExit_<login>.csv
Draw the summary panel true false removes the panel from the chart

How it is measured

  • Positions are built from deals by position ID. Commission, swap and fee are included in the net result.
  • Positions with more than one entry deal, reversals and partly closed positions are skipped, because they do not have one clear entry and stop.
  • The initial stop is the SL recorded on the entry deal (or on the exit deal if the entry had none). The tested target is the TP at exit time.
  • M1 bars hold bid prices. For sell positions the ask is estimated as bid plus the bar's recorded spread.
  • A position counts as "watched" only when the full window of M1 bars after the exit exists. Recent exits are shown as "window open" and are left out of the statistics.
  • Results inside one bar are approximate: M1 data does not show the order of the high and the low within a minute.
  • The script only reads history. It does not trade, uses no DLLs and changes no terminal settings.

Run it on any chart: drag the script from the Navigator, set the inputs and press OK. Run it again with Draw the summary panel = false to remove the panel.


Complement community code with advanced automation from RobotFX.

79102

Best MetaTrader Indicators + Profitable Expert Advisors