Home › Learn › Backtesting in MT5 Without Fooling Yourself
Backtesting in MT5 Without Fooling Yourself
The MT5 Strategy Tester will happily show you a rising equity curve for a strategy that would have lost money every month it was live. It is not lying — it is answering exactly the question you asked. The skill is in asking a harder one.
Modelling: what the tester is actually simulating
MetaTrader 5 offers several modelling modes, and the difference between them is not cosmetic.
| Mode | What it does | Use it for |
|---|---|---|
| Open prices only | One price per bar | Fast parameter sweeps on bar-close strategies only. Never for final results |
| 1 minute OHLC | Generates ticks from minute bars | Rough shape. Intrabar path is fabricated |
| Every tick | Generates ticks from minute data by an algorithm | Better, still synthetic |
| Every tick based on real ticks | Uses the broker's actual recorded tick history | The only mode whose result means much for anything intrabar |
If your strategy touches price inside a bar — a stop, a take-profit, a trailing stop, a breakout level, any grid — then a synthetic tick mode is guessing the order in which the high and the low were reached. That order determines whether you were stopped out before your target was hit, which determines the entire result. On a strategy with a stop and a target both inside one bar's range, synthetic modelling can turn a loser into a winner by assumption alone.
Use real ticks for anything you intend to trade. And be aware of what real ticks actually are: your broker's recorded history, which is often incomplete going back more than a year or two, and which differs from another broker's history for the same instrument.
Spread is where most backtests quietly cheat
This is the largest single source of fake profit in retail backtesting, and it is worst on gold.
Set the spread to “current” and MT5 will test a whole year at whatever the spread happens to be right now. If you press Start on a quiet Tuesday afternoon, you have just simulated a year in which the spread never widened — not for the New York open, not for a payrolls release, not for the Sunday reopen, not once.
Real gold spread is not a constant. It is tight in liquid hours and multiples of that at the session handover and around data. A scalping strategy tested at a fixed tight spread and traded at a real variable one is a completely different strategy with a completely different expectancy.
What to do:
- Test with a fixed spread set to the worse end of what you actually see, not the average, and certainly not the best.
- Run the test again at double that. If the edge disappears, it was never an edge — it was a spread assumption.
- Enter commission and swap in the symbol settings. Leaving them at zero on a raw-spread account overstates every result.
- Remember the tester models no slippage at all. Every fill is perfect. Live fills are not, and the gap is biggest exactly where your strategy is most active if it trades news or breakouts.
Look-ahead: the bug that makes a strategy look psychic
If a result looks extraordinary, assume look-ahead bias before you assume genius. The usual sources:
- Reading the current bar's close before the bar closes. Using index 0 where you meant index 1 is the classic. In live trading, index 0 is unfinished; in some test modes it behaves as though it is not.
- Repainting indicators. Anything that draws a signal on a bar that has already passed — ZigZag, many fractal- and pivot-based tools, most “never loses” arrow indicators — will produce a flawless backtest and no live edge whatsoever. The test of a repainter is simple: run it on a chart, let new bars form, and see whether historical signals move. If they move, the backtest is fiction.
- Higher-timeframe values on incomplete candles. Pulling a daily value mid-day and treating it as settled.
- Data that did not exist yet — using a revised economic figure at its original release timestamp, for instance.
A quick sanity check: if the strategy's win rate is above about 85% on a directional method with a stop, something is either repainting, averaging losses (see grid strategies), or reading the future.
Curve fitting, and how to tell whether you have done it
Optimisation finds the parameter set that performed best on the data you gave it. That is its job. The problem is that on any finite history, some parameter set will look excellent by luck alone, and MT5 will find it for you with great efficiency.
The more parameters you optimise, the more certain this becomes. Five parameters over a thousand combinations each is not a search for an edge, it is a search for a coincidence — and it will succeed.
Three defences, in increasing order of usefulness:
Look at the neighbourhood, not the peak
Open the optimisation results as a surface. If your best result sits on a lonely spike surrounded by losses, it is noise: a small change in market behaviour moves you off the spike. If it sits on a broad plateau where everything nearby is also decent, you may have something real. Always prefer a robust plateau to a superior peak.
Hold data back
Optimise on one period, test on a period the optimiser never saw. MT5 has this built in through the forward-testing setting, which splits your range automatically. If in-sample is brilliant and out-of-sample is flat, you fitted noise. This is the single most informative test available and it costs one checkbox.
Walk forward
Repeatedly optimise on a window, test on the next window, roll forward, and string the out-of-sample pieces together. It is slower and much more honest, because it simulates what you would actually have done — periodically re-tuning on recent data — rather than assuming you picked the right parameters once, years ago, by magic.
Test across regimes, not across time
“Five years of data” sounds thorough and often is not. What matters is whether those years contained conditions that are genuinely different from each other: a strong trend, a long range, a volatility shock, a rate-hiking cycle and a cutting one.
Break the result down by year and by quarter rather than reading one aggregate figure. A strategy that made everything in one six-month stretch and went sideways for the other four years is one regime's strategy, not a system. You want to see whether it merely survived the periods it was not designed for, which is a realistic hope, rather than whether it profited in all of them, which usually is not.
Where the platform allows it, run the same test on a second broker's data for the same instrument. Differences in feed, spread and tick history will move your result. If it moves a lot, your edge was inside those differences.
The numbers worth reading
The tester reports a great many statistics. Most are noise. These are not:
- Maximum equity drawdown, in percent. Equity, not balance — balance drawdown ignores everything held open. This is the number that decides whether you could have actually stayed with the strategy.
- Number of trades. Thirty trades tells you nothing at all. A few hundred starts to be informative. Any conclusion drawn from a handful of trades is a story, not a statistic.
- Expectancy per trade, compared against your spread. If average profit per trade is small relative to the cost of trading, the strategy is one spread widening away from nothing.
- Longest losing streak, in trades and in days. Ask yourself honestly whether you would have kept it running through that, because if not, the backtest describes a strategy you would never have traded.
- Profit factor stability over sub-periods, rather than the headline number.
Then shuffle. Reorder the trade sequence randomly a few hundred times and look at the distribution of outcomes. The historical order of your wins and losses was luck; seeing the range of drawdowns that the same set of trades could have produced in a different order is far more honest than the single path you happened to get.
Then forward test anyway
Everything above is still a simulation. Before real money:
- Run on demo, on the same broker and server you will trade, for long enough to include conditions the strategy dislikes — weeks at minimum, not days.
- Compare demo results against the backtest over the identical period. They will differ. The size of the gap is your estimate of how much the simulation was flattering you.
- Go live at the smallest size the platform permits, and compare again. Live fills differ from demo fills, particularly on gold around news.
- Only then scale, and scale slowly.
The purpose of a backtest is not to prove a strategy works. It is to find the reasons it will not, cheaply, before the market charges you to find them. A test that fails to kill a strategy has done its job; a test that was designed to approve one has not been a test at all.