Loading…

Portfolio Backtest Aggregator

The Strategy Tester reports one symbol at a time. The obvious way to estimate a multi-symbol portfolio's risk is to test the strategy on each symbol separately and add up the max drawdowns from each report. That number is not the portfolio's real drawdown, and it is wrong in a way that can go either direction: five symbols rarely hit their own worst day on the same calendar day, so the sum usually overstates the true combined worst case, but if the symbols actually move together the real combined drawdown can just as easily be worse than the naive sum ever suggested, because losses that would have offset on paper instead stack. The only correct combined drawdown comes from one equity curve built by replaying every trade from every symbol in true chronological order, not from combining each symbol's own independently-computed statistic. This tool takes several CSV trade exports - one per symbol, in a simple Symbol/OpenTime/CloseTime/Lots/Profit shape - merges every trade into one timeline by close time, and walks that single timeline to compute the real combined equity curve, peak, and max drawdown. It reports that next to the naive sum so the size and direction of the gap is visible, then adds two supporting statistics per symbol pair: how many of the merged trades on each pair had genuinely overlapping open windows, and the Pearson correlation of the two symbols' recent price history - the two concrete reasons the naive sum was never going to be reliable. Notes and limitations - Requires each symbol's price history to already be cached locally for the correlation calculation; open a chart on each symbol first if InpCorrelationLookback bars are not yet available and the report shows "n/a (insufficient history)" for a pair. - The time-overlap count is a simple pairwise interval intersection test, not a continuous exposure-weighted figure - it tells you how often positions coexisted, not for how long or at what combined size. - Correlation is computed from live/cached price history at the moment this EA runs, not from history as it stood during the original backtests - for a strategy tested over a long historical period this is an approximation of the relationship, not an exact historical figure. - This tool never trades. It only reads the files you give it and writes the merged report.

Expert advisor · MT4 · v1.0 · Free

About Portfolio Backtest Aggregator

Portfolio Backtest Aggregator is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as File list, Starting balance and High correlation level. MQL source code included.

Files in the download: PortfolioBacktestAggregator.ex4, PortfolioBacktestAggregator.mq4, PortfolioBacktestAggregator.txt.

Settings

SettingDefaultWhat it does
File listSymbol1_trades.csv,Symbol2_trades.csvComma-separated trade export filenames, in MQL4\Files
Starting balance10000.0Starting balance the combined curve is built from
High correlation level0.70Pearson correlation above this is flagged as high
Correlation lookback100Bars used to compute price correlation between each symbol pair
Correlation timeframePERIOD_D1Timeframe the correlation is computed on
Output csv file namePortfolioBacktestAggregator_Merged.csvCombined curve export, in MQL4\Files

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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: Multi-Currency · Alerts · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria