Loading…

Cancelled Pending Autopsy

A pending order that gets deleted or left to expire disappears from the record with no answer to the obvious question: would it have worked? This script answers it directly. For every cancelled or expired pending order in history it walks forward bar by bar from the moment of cancellation on a chosen timeframe, checking whether price would have touched the order's trigger price. If it would have, that is treated as the hypothetical fill, and the replay continues from there looking for whichever of the order's own stop loss or take profit would have been hit first - or, if the order carried neither, the replay simply reports the floating result at the end of a fixed lookahead window rather than assuming an unbounded hold. A pending order that filled is not part of this audit at all - a filled order shows up in terminal history under a market order type, not a pending one, so this script's own type filter naturally separates "this order actually got taken" from "this order was cancelled or expired without ever filling", which is the only case worth an autopsy. Hypothetical profit is computed from tick value and tick size read live from the broker, never a hardcoded contract size, so it is priced correctly across ordinary forex pairs, JPY crosses, gold and index CFDs alike. Notes and limitations - The replay checks only bar high/low against the trigger and stop/target prices - it does not model spread, slippage or partial fills, so the hypothetical result is an approximation of what a real fill would have looked like, not a guarantee. - If price gaps straight through the trigger and the stop/target within the same bar, the fill is still assumed to happen exactly at the trigger price; a genuinely gapped market could have filled worse. - Bars older than what MetaTrader has already downloaded for that symbol/timeframe simply end the replay early (treated as "ran out of history"), which understates the lookahead on a symbol whose local history is thin. - Only pending order types (buy/sell limit and stop) are considered; market orders never appear as "cancelled pending" candidates.

Script · MT5 · v1.0 · Free

About Cancelled Pending Autopsy

Cancelled Pending Autopsy is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as Symbol filter, From date and To date. MQL source code included.

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

Settings

SettingDefaultWhat it does
Symbol filterSymbol to audit ("" = every symbol in history)
From date0Only orders cancelled on/after this date (1970.01.01 = no lower bound)
To date0Only orders cancelled on/before this date (1970.01.01 = up to now)
Replay timeframePERIOD_H1Timeframe used to replay price after cancellation
Lookahead bars200Bars to replay forward after cancellation
Write report filetrueWrite a CSV of every autopsied order

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: Pending Orders · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria