Core Idea
Execution & Slippage Forensics is a standalone diagnostic script for MetaTrader 5 (no external #include dependencies) that audits your real account trading history by pairing every executed trade deal back to its parent historical order via HistoryOrderSelect(). By comparing ORDER_PRICE_OPEN (requested price) against DEAL_PRICE (actual fill price), it quantifies execution quality in both points and account currency without fabricating numbers when market orders omit requested prices (Req=0.0).
How to Interpret the Output
1. Sign Convention:
- Positive (+) values in points or currency represent favorable price improvement (filled better than requested).
- Negative (-) values represent adverse slippage (filled worse than requested).
2. Four Execution Buckets:
- ALL_MEASURED: Aggregate portfolio fill statistics.
- ENTRIES (IN / INOUT): Entry execution quality under normal liquidity.
- SL_EXITS (DEAL_REASON_SL): Stop-Loss execution slippage, isolating stop-hunting or liquidity gaps.
- OTHER_EXITS: Take-Profit, manual, and automated closes.
Each category reports Count, Mean (pts), Median (pts, resistant to outliers), Adverse %, Positive %, and Net Slippage ($).
3. 24-Hour Server Profile & Hidden Execution Drag:
- Identifies exact Broker Server hours (00:00 - 23:00) where rollover or low liquidity widens adverse slippage.
- Computes Hidden Execution Drag = Commissions + Fees + Swaps + Adverse Slippage expressed as a percentage of Gross Winning Profit.
4. Exports:
- Prints the full report and worst adverse deals in the Experts tab, displays a concise summary on the chart, and exports ExecutionForensics_Deals.csv and ExecutionForensics_Hourly.csv to MQL5\Files\.
External Input Parameters
- InpLookbackDays (default 90): Number of past days to audit. Set 0 to audit the entire loaded account history.
- InpSymbolFilter (default ""): Empty string audits all symbols; "CURRENT" audits only the active chart symbol; or specify an exact symbol name.
- InpMagicFilter (default -1): -1 includes all EAs and manual trades; set a positive MagicNumber to isolate a single Expert Advisor.
- InpExportCSV (default true): Enables CSV export of deal-level records and the 24-hour execution table into MQL5\Files\.
- InpShowChartComment (default true): Displays a compact summary overlay on the active chart.
- InpTopWorstDeals (default 5): Number of worst adverse-slippage fills to list in the Experts log (0 disables).
Recommended Usage
Attach the script to any chart after ensuring the desired date range is loaded in your MT5 Account History tab. Works on all Forex, Metals, Indices, and CFD symbols in both Hedging and Netting accounts.