Loading…

Rolling Performance Attribution

"Which strategy is actually paying for this account" is a question most traders only answer by exporting history to a spreadsheet after the fact. A live version of that question needs a breakdown that stays current as trades close, without rescanning the whole trade history on every request - which is what this library is for. Feed each closed trade's strategy tag, symbol, session label and net profit into RegisterTrade() once. Three independent keyed tables - by strategy, by symbol, by session - are updated at the same time, each tracking trade count, net profit, win rate, profit factor and share of total net profit per key. Looking up any key's current numbers is a linear scan over that dimension's distinct keys (typically a handful to a few dozen strategies/symbols/sessions), never a rescan of the trade history itself. The three dimensions are kept genuinely independent (a strategy table, a symbol table, a session table) rather than one combined strategy+symbol+session key, because most callers want one axis at a time and a combined key space grows combinatorially for no benefit most users need. The demo proves consistency directly: it sums net profit across every key in each of the three dimensions independently and shows all three sums reconcile exactly to the same grand total that was fed in - proof no trade is silently dropped or double-counted by any one dimension's bucket set. Notes and limitations - The session label is entirely caller-supplied - this library makes no attempt to derive a session from a trade's close time itself, since session boundaries are a broker/timezone decision the caller is better placed to make than a generic library. - Key lookup inside each dimension's table is a linear scan over that dimension's distinct keys. This is intentionally simple and stays cheap at realistic cardinalities (tens of strategies/symbols/sessions, not thousands); it is not built for a dimension with an unbounded number of distinct keys. - ShareOfTotalNetProfit() divides by the sum of absolute net profits across all keys in that dimension, not the raw net total - this keeps the share meaningful (and correctly signed) even when the dimension's overall net total is small or negative because winning and losing keys are cancelling each other out. - There is no persistence: RegisterTrade() history lives only in memory for the lifetime of the object. A caller wanting the breakdown to survive a terminal restart must re-feed historical trades on init or add its own file-based persistence.

Script · MT5 · v1.0 · Free

About Rolling Performance Attribution

Rolling Performance Attribution is a script for MetaTrader 5. It shows several symbols in one panel and is set up for gold (XAUUSD). It has 1 setting, such as Trade count. MQL source code included.

Files in the download: RollingPerformanceAttribution.mq5.mqh, RollingPerformanceAttribution.txt, RollingPerformanceAttributionDemo.ex5, RollingPerformanceAttributionDemo.mq5.

Settings

SettingDefaultWhat it does
Trade count250Total synthetic trades fed through the engine

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: Trading Sessions · Dashboards & Scanners · Gold (XAUUSD) · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria