Watch how to download trading robots for free
Find us on Telegram!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Scripts

MAE and MFE of closed trades - script for MetaTrader 5

Views:
40
Rating:
(1)
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

This script writes the MAE (maximum adverse excursion) and MFE (maximum favourable excursion) of every closed position in your account history to a CSV file: in price, in account money and in R when the first entry had a stop loss. MAE is how far the price went against the position before it closed; MFE is how far it went in its favour. Set next to the result and the initial stop loss, they show how much room each trade needed and how much of the move it kept. The script only reads the history: no trade functions, no DLL imports, no network.

MAE and MFE of a closed long trade

MAE and MFE of a closed long trade: a drawing of the method, not account data.

How it works

  • Positions are built from the deals of the history by position id. Partial closes stay in one position; the entry price is the volume-weighted average of all entries.
  • The path between entry and exit comes from M1 bars, from the minute of entry to the minute of exit. M1 bars hold bid prices; for short trades the ask is estimated as the bid plus the bar spread.
  • The first and the last bar also hold prices from before the entry and after the exit. Where the trade shows where it was, those parts are cut: the minute of entry at the stop loss and take profit set with the order; the minute of exit at the fill for a stop loss or take profit exit, else at the stop loss and take profit in place at the exit. The last exit price is always on the path.
  • For a long trade, MAE = entry minus the lowest price and MFE = the highest price minus entry; for a short trade the other way round.
  • Money values come from OrderCalcProfit with the total entry volume. R = net result / 1R, where 1R is the loss at the initial stop loss of the first entry.

How to read the results

  • A winning trade with an MAE near 1R came close to its stop loss before it turned.
  • An MFE in R well above the result in R means the trade gave back much of what it had offered.
  • A losing trade with an MFE near zero went against the position from the start.

Use

Drag the script from Navigator > Scripts onto any chart, set the days of history and press OK. The Experts log says how many positions were written. The file is MQL5\Files\MAE_MFE_ClosedTrades.csv (File > Open Data Folder), one row per closed position: position, symbol, direction, entry and exit time, entry and exit price, exit reason, net result, initial stop loss, MAE and MFE in price and money, 1R in money, R, MAE and MFE in R, and the number of M1 bars used.

Input

  • Days of history to read (InpDaysBack, default 90; 0 = all).

Limitations

  • Inside the edge minutes the values stay approximate when the trade had no stop loss or take profit.
  • Trades older than the terminal's M1 history (Tools > Options > Charts > Max bars in chart) are skipped; the log says how many.
  • Netting reversals (in/out deals) are not split into two positions.
  • Money values use current conversion rates for symbols not quoted in the account currency.
Server-Midnight Daily Floating Drawdown and Spread Spike HUD Server-Midnight Daily Floating Drawdown and Spread Spike HUD

Read-only chart HUD tracking server-midnight daily floating drawdown (Max Balance/Equity anchor), remaining daily buffer, per-Magic P&L attribution, and 23:00-00:15 rollover spread spikes.

Execution Quality Recorder Execution Quality Recorder

Records every fill on the account and shows how it was executed: slippage against the requested price on entries and on stop-loss and take-profit exits, the spread at the fill and the execution delay. Per-symbol panel, hour-by-hour heatmap, CSV log and a side-by-side broker comparison. It does not trade.

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.