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

Metatrader 5 Script | Trade Excursion Report: MFE and MAE of every closed trade, to CSV | MQL5 Code

RobotFX curates the best open-source MetaTrader code to inspire your trading automation.

What it writes

One line per closed position, grouped by DEAL_POSITION_ID (works on hedging and netting accounts; tested on a hedging demo). Columns: ticket, symbol, direction, entry time, exit time, entry price, exit price, profit points, MFE points, MAE points, capture ratio, bars spanned, holding time.

Inputs

Never miss news-driven moves – use the News OCO Expert Advisor to place pending orders safely around economic releases. Find out more.

  • InpDias — how many days of history to read (365)
  • InpSoEsteAtivo — only the chart symbol, or every symbol in history (false)
  • InpTF — timeframe used to measure the excursions (current chart)
  • InpArquivo — CSV file name in MQL5\Files

Summary printed to the Experts log

Trade count, won/lost, net result, median MFE and MAE of winners, median MAE of losers, median CAPTURE ratio, median bars per trade, the number of single-bar trades, and the number of trades that could not be measured because the terminal has no bars for that symbol any more (expired futures, for instance) — those are reported, not silently written as zero.

Measurement limit

Excursions are taken from the high and low of the bars each trade spanned on InpTF . The path inside a bar is unknown. If the bars column shows 1 for many trades, run it on a smaller timeframe.

Shares TradeExcursion.mqh with the Trade Excursion indicator; the include goes in MQL5\Include .

Image for Trade Excursion Report: MFE and MAE of every closed trade, to CSV

Complement community code with advanced automation from RobotFX.

77050

Best MetaTrader Indicators + Profitable Expert Advisors