Loading…

Trading Cost Attribution Monitor

A single net profit figure hides four very different things: what you paid to cross the spread at entry, what price actually did afterwards, the broker's commission, and the swap accrued while the position sat open. Two trades can show the same net result for completely different reasons, and a trader who never separates them ends up crediting good outcomes to a skill that was really just a favourable spread or a quiet swap-free symbol. This monitor scans open positions on a timer, records the money cost of the spread the instant it first sees each one, and when that position later appears in history it strips the recorded spread cost back out of the position's own realised profit to recover the price-only component. It then reports a running total across the session broken into price movement, spread cost, commission and swap. Neither platform stores the spread a position paid at open anywhere in account history, so this is the only way to recover it - and only for positions this EA was already watching. A position opened and closed before the EA attached, or while it was detached, still shows up in the total but with its full result counted as price movement, and the Print log marks it as unattributed rather than silently guessing. Notes and limitations - Only positions opened, or already open, while this EA is attached get an accurate spread split. Earlier closed history is not retroactively attributed - there is no API on either platform to recover a historical position's spread at entry. - The spread snapshot is taken at first detection, which is a close approximation of the true entry spread for positions already open when the EA starts, and exact for positions opened afterwards. - Read-only. It never sends, modifies or closes a position - only Alert, Print and Comment are used to surface what it finds. - Assumes no partial closes: a position with more than one exit deal is still summed correctly for commission/swap, but each exit deal is attributed as its own closed trade in the log and totals.

Expert advisor · MT5 · v1.0 · Free

About Trading Cost Attribution Monitor

Trading Cost Attribution Monitor is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 2 settings, such as Scan interval secs and Max tracked tickets. MQL source code included.

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

Settings

SettingDefaultWhat it does
Scan interval secs15How often to check for newly opened and newly closed positions
Max tracked tickets300Maximum simultaneously open positions whose entry spread is remembered

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: Alerts · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria