Monte Carlo Trade Shuffler
A single backtest report gives one drawdown figure, and that figure depends on the order the wins and losses happened to arrive in as much as it depends on the strategy's real edge. Run the same set of trades in a different order and the drawdown can be substantially worse - or better - purely by chance. A trader who only ever sees the one ordering their backtest produced has no way to know how lucky that ordering was. This tool answers that directly. It loads a closed trade log, then reshuffles the sequence of trade profit-and-loss figures thousands of times, walking a simulated equity curve for each reordering and recording its maximum drawdown and whether equity ever fell to a configurable ruin threshold. The result is a distribution, not a single number: the median drawdown across reshuffles, the worst case seen, and what percentage of reshuffles were actually worse than the trader's own real-history ordering. MQL4 cannot run a second, arbitrary strategy's tick logic inside this EA - only one program executes per chart - so rather than pretending to simulate an unknown strategy live, this reads an already-closed trade log in the same six-column format PropRuleBacktestAuditor accepts and DetailedTradeHistoryExporter produces. That keeps the tool honest about what a standalone MQL4 file can actually analyse: real trades, reordered and re-measured, not an invented backtest. Notes and limitations - The reshuffle only reorders trades; it does not change their sizes, correlate them with market conditions, or account for the fact that a real strategy's trade order is not actually random - it is a stress test of ordering risk, not a forecast. - MathRand() covers only 0 to 32767. A trade log longer than that introduces a small bias into the shuffle; this is noted here rather than hidden, and is not a practical concern for the trade counts a single backtest normally produces. - The whole analysis runs once, synchronously, at attach time. A very large trade log combined with a very high InpShuffleCount will take correspondingly longer before the chart responds. - Read-only. It never sends, modifies or closes an order - only file reads, file writes and MathRand-driven reshuffling are used.
Expert advisor · MT4 · v1.0 · Free
About Monte Carlo Trade Shuffler
Monte Carlo Trade Shuffler 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 Trade log filename, Starting balance and Shuffle count. MQL source code included.
Files in the download: MonteCarloTradeShuffler.ex4, MonteCarloTradeShuffler.mq4, MonteCarloTradeShuffler.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Trade log filename | MonteCarloTradeShuffler_TradeLog.csv | File in MQL4\Files, columns: OpenTime,CloseTime,Type,Lots,Symbol,Profit |
| Starting balance | 10000.0 | Starting balance the simulated equity curve begins from |
| Shuffle count | 2000 | Number of random reorderings to test |
| Ruin threshold percent | 50.0 | A path counts as "ruined" if equity ever falls to this percent of the starting balance |
| Random seed | 0 | 0 = seed from the clock (different every run); non-zero = reproducible runs |
| Report file | MonteCarloTradeShuffler_Report.csv | Per-shuffle raw results, written once analysis completes |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Alerts · MT4 Expert Advisor · MQL4 Source Code