Monte Carlo Equity Projection
A backtest or a live account produces exactly one equity curve, in exactly the order the trades happened to land. That order is one draw out of many possible ones. The same set of trades, sequenced differently, can look like a steady climb or a brutal early drawdown that would have stopped most people out - and a single curve cannot tell you which kind of luck you got. This script takes the net profit of every closed trade matching the filter and resamples it with replacement, thousands of times, to build a distribution of ending equity and maximum drawdown rather than a single number. It also reports how often, across all those runs, equity would have touched a ruin level you choose, expressed as a percentage of the starting balance. It is a trade-order bootstrap, not a price simulator. It cannot invent an edge the sample does not have, and it cannot simulate a trade that never happened. What it does show, honestly, is how much the sequencing of wins and losses alone can move the outcome around a fixed set of results - which is usually more than people expect, and is invisible from the one curve a terminal report shows. Notes and limitations - This resamples the trade P/L your account actually produced, at the lot sizes those trades were actually opened with. It is not a fixed-lot or fixed-risk simulation unless your historical trades were sized that way. - Bootstrapping assumes trades are reasonably independent. A history full of martingale or grid trades, where one trade's size depends on the previous one's outcome, breaks that assumption and the projection should be read with more caution in that case. - A small sample still produces a distribution - the script enforces a minimum trade count, but even at the minimum the result reflects a small amount of evidence, not certainty. - Probability of ruin is measured against a fixed percentage of the chosen starting balance, not against a broker's actual margin call level. - On MQL5, a position built from more than one entry fill or closed via more than one partial exit is folded into a single resampled trade, with its net P/L summed across every deal on that position. This matches the common single-fill case exactly but is an approximation for a scaled-in or partially-closed position - the MQL4 version has no partial-close concept at all, since MT4 orders are never partially closed in place.
Script · MT4 · v1.0 · Free
About Monte Carlo Equity Projection
Monte Carlo Equity Projection is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 11 settings, such as Symbol filter, Magic filter and From date. MQL source code included.
Files in the download: MonteCarloEquityProjection.ex4, MonteCarloEquityProjection.mq4, MonteCarloEquityProjection.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Symbol filter | Symbol filter ("" = every symbol) | |
| Magic filter | -1 | Magic number filter (-1 = every magic) |
| From date | 0 | Earliest close time (0 = all loaded history) |
| To date | 0 | Latest close time (0 = up to now) |
| Min trades | 20 | Minimum closed trades required before reporting |
| Starting balance | 0.0 | Starting balance for the projection (0 = current balance) |
| Simulations | 2000 | Number of bootstrap runs |
| Trades per run | 0 | Trades per run (0 = same as the historical sample size) |
| Ruin level percent | 50.0 | Equity level counted as "ruin", % of starting balance |
| Export csv | false | Also write every run's outcome to a CSV file |
| Csv delimiter | , | CSV delimiter (first character is used) |
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 Script · MQL4 Source Code