Backtesting in MT4 and MT5 — a practical guide for 2026
Chris finished his first Expert Advisor in January 2024. He clicked Strategy Tester with default settings and watched the equity curve climb from 10,000 to 47,000 euros in three years, with a 78 percent win rate. Five months later his live account stood at 7,200 euros. The gap between backtest and reality came from three workshop mistakes: poor data, unrealistic parameters and a single optimisation pass instead of walk-forward.
MT4 versus MT5 Strategy Tester — what really differs
Strategy Tester runs an Expert Advisor against history in both platforms, but mechanics decide whether the result is trustworthy. MT4 is single-threaded: a five-year backtest on M15 takes two to ten minutes, and optimising across hundreds of combinations can stretch over two days. MT5 spreads the work across cores and handles multi-currency tests natively — a portfolio on three majors runs serially in MT4, concurrently in MT5. The second difference is data: MT4 pulls history from History Center (usually two or three years back), MT5 downloads broker tick data. For M30 or higher this is not dramatic; for an M5 scalper it is a chasm. Background in MT4 basics and why MT5 wins.
Modelling modes and historical data quality
Strategy Tester offers three candle modelling levels. Open prices only uses the opening price alone — quick, but useless intraday. Control points reconstructs High and Low by interpolating from a smaller timeframe, capped at 90 percent modelling quality in MT4. Every tick in MT4 builds the path inside each candle from the OHLC envelope; MT5's “Every tick based on real ticks” mode reads broker tick history — the only mode that delivers a credible result below H1.
Dukascopy Bank in Geneva makes tick history freely available from 2003 onwards for most major pairs, indices and commodities. You retrieve it via the JForex Historical Data Downloader and convert to MT4's HST with the free FX Blue Quant Data Manager or paid Tickstory (30 to 50 USD). Modelling quality then jumps to 99 percent. In MT5 you select “Every tick based on real ticks”; without broker tick data MT5 falls back to a synthetic mode and the backtest is as suspect as MT4 on defaults.
Simulation parameters — spread, commission, swap, slippage
By default Strategy Tester assumes the current spread and zero commission, which for scalping is the difference between an apparent surplus and a real deficit. Set the spread to match your live account (0.8 to 1.5 pips on EUR/USD at an ECN broker, pessimistic times 1.5). ECN commission is typically 7 USD per lot; without it a strategy earning five pips shows a 1.6 profit factor in the backtest and 0.9 in real life. Swap on positions held two to seven days can erase 20 to 30 percent of annual profit. Slippage is not simulated, yet five to twenty pips during NFP is routine; the realistic correction adds 1.5 pips per loss and subtracts 1 pip per win.
Three pitfalls that wreck a backtest
Look-ahead bias is the unintentional use of information unavailable at decision time — in MQL4/MQL5 it most often appears when referring to the current candle with index zero. That candle is still forming, so the backtest knows its final High and Low while the live trader does not. Rule: every read uses index 1 or higher. The coding side is in our intro to Expert Advisors.
Overfitting is the consequence of excessive optimisation — the trader runs Strategy Tester across a thousand combinations, picks the best and admires a curve that looks impossibly smooth, really a fit to noise. Warning signs: drawdown below 5 percent, profit factor above 3.5, win rate above 75 percent across 200 trades, an equity curve without corrections longer than two weeks. Together, an alarm. Survivorship bias means testing only pairs that survived to today; a portfolio of exotics tested only on those “still quoted by the broker” can flatter the result by 30 to 50 percent (USD/TRY after 2018 and EUR/CHF after January 2015 are instructive examples).
Reading the report and walk-forward as the antidote to curve-fit
Both platforms generate reports of eight to ten metrics, and most traders look at three: net profit, win rate, drawdown. Not enough. Profit factor above 1.5 is decent, above 2 excellent, above 3.5 suspicious. Sharpe near 1.0 acceptable, 1.5 to 2.5 very good, above 3 check for curve-fit. Maximum drawdown intraday should stay under 25 percent. Trade count at least 100, ideally 500. Modelling quality 99 percent.
Walk-forward is the methodology Robert Pardo set out in his 2008 classic and remains the standard at systematic funds today. Split history into in-sample (four years) and out-of-sample (one year), optimise parameters only on in-sample, run the strategy with frozen parameters against out-of-sample, roll the window forward by a year and repeat. The aggregated OOS result best approximates a live account. WFE (OOS return divided by IS return) above 0.5 signals a robust strategy, 0.3 to 0.5 moderate curve-fitting, below 0.3 a flattering reflection of the trader's ego. Mechanics step by step are in walk-forward analysis.
“The whole purpose of walk-forward analysis is to reveal the real-time, real-money performance of a trading strategy without actually trading it with real money in real time.” — Robert Pardo, The Evaluation and Optimization of Trading Strategies, Wiley, 2008
Limits of MT4/MT5 and when to reach for other tools
Strategy Tester carries built-in limits: a simplified execution model, an MT4 optimiser that struggles beyond a few hundred combinations, reports without stability-of-parameters analysis or Monte Carlo. For discretionary price-action strategies Strategy Tester can be useless, because such rules cannot be expressed fully as code. When MT4/MT5 falls short, you reach for Forex Tester 5 (about 300 USD) or Python with backtrader. Platform-independent methodology lives in our piece on how to backtest a strategy correctly; wider context sits in the trader's workshop on ForexMechanics.
What to do tomorrow
- Download tick data from Dukascopy for EUR/USD across the last five years and import it into MT4 via FX Blue Quant Data Manager or Tickstory; in MT5 select “Every tick based on real ticks” and confirm that the broker exposes tick history — without that step any further intraday backtest is statistical fiction.
- Open your EA in Strategy Tester, enter the spread that matches your live account (typically 1.2 pips on EUR/USD at an ECN broker), add a 7 USD per lot commission and a slippage penalty of 1.5 pips per loss and 1 pip per win, then run a single backtest across five years and compare with the previous result.
- Split the five years into four years in-sample plus one year out-of-sample, optimise parameters only on the in-sample window, freeze the best set and run a single backtest on out-of-sample; if WFE falls below 0.5, the strategy is curve-fitted and demands simpler logic rather than another optimisation round.
- Read the EA source for every iCustom, iHigh, iLow, CopyClose or CopyRates call with index zero, replace it with index 1 and run the backtest again; any divergence greater than 30 percent means the strategy lived on look-ahead bias and the entry logic needs rewriting.
Sources & bibliography
-
MetaQuotes MetaTrader 5 — Testing Trading Strategies · oficjalna pomoc MT5: tryby modelowania, parametry symulacji, optymalizacja www.metatrader5.com ↗
-
MetaQuotes MQL5 Reference — Testing Trading Strategies · dokumentacja MQL5: tryby ticków, ograniczenia funkcji testera www.mql5.com ↗
-
MetaQuotes MetaTrader 4 — Strategy Testing · oficjalna pomoc MT4: modeling quality, raporty Strategy Tester www.metatrader4.com ↗
-
Dukascopy Bank SA Historical Data Export · darmowe dane tickowe od 2003 r. dla 99 procent modeling quality www.dukascopy.com ↗
Frequently asked
How does 99 percent modelling quality differ from 90 percent in MT4?
Modelling quality is the percentage shown in the top-right corner of the MT4 Strategy Tester report, indicating how faithfully the simulator reconstructed price movement inside each candle. 90 percent is the maximum achievable on the default data downloaded from the broker via History Center — MT4 interpolates the candle interior from four points (Open-High-Low-Close), so a backtest on M15 assumes a path inside the candle that it never verifies. 99 percent requires genuine tick data imported from an external source — typically the free Dukascopy API or paid Tickstory. The practical difference is dramatic: a scalping strategy targeting five pips might show a 70 percent win rate and 30 percent annual return on 90 percent data, yet on the same period at 99 percent quality the win rate collapses to 52 percent and the curve flatlines. The reason is simple — the absence of tick movement inside each candle hides the moment when a stop loss would have been triggered before price could rotate back to the target. Rule of thumb: if your strategy lives on M30 or higher with take-profits beyond 30 pips, the 90-versus-99 gap is not critical. If you scalp or trade below M15, anything less than 99 percent is fiction. MT5 sidesteps this entirely with its "Every tick based on real ticks" mode, provided the broker exposes tick history — most reputable ECN brokers do.
How do I configure the MT5 Strategy Tester step by step?
This is the sequence to follow every time so that you never miss a setting silently. Step one: open Strategy Tester with Ctrl+R or via View → Strategy Tester. Step two: in the Expert field, pick the EA compiled to a .ex5 file. Step three: select the symbol from the list — ideally the same one you trade on the demo or live account. Step four: set the timeframe identical to the one the strategy uses in production. Step five: define the date range. Five years minimum, ten preferred — long enough to include at least one bull leg, one correction and one crisis event (March 2020, February 2022, October 2023 are useful waypoints). Step six: choose the simulation model — "Every tick based on real ticks" for a credible result, "Every tick" for faster iteration, "1 minute OHLC" only for the first parameter sweep. Step seven: starting deposit and currency that match your real account. Step eight: leverage — crucially the same as your live setup (1:30 for an EU retail trader, 1:500 if you carry experienced-client status). Step nine: in the Settings tab set Optimisation to Disabled for a single run, Slow complete algorithm for the first walk-forward iteration, Fast genetic for larger parameter spaces. Step ten: click Start and watch. When MT5 downloads history for the first time it can take two to twenty minutes depending on period length and number of instruments. Once finished, you have access to the Backtest tab (equity curve), Trades tab (order list) and Graph tab (balance evolution). Export the report to HTML through right-click → Save as Report and archive it inside the strategy project folder.
What is look-ahead bias and how do I avoid it in MQL5?
Look-ahead bias is the unintentional use, in strategy code, of information that would not have been available at decision time — peeking into the future. In MQL5 it tends to surface in three places. First: referring to the current, unclosed candle with index 0 instead of 1 in iCustom and similar calls. Index 0 is still forming — its High, Low and Close mutate tick by tick, so an entry condition based on that reading uses the candle's final values in the backtest while a live trader would not see them for another fifteen or thirty minutes. Second: using iHigh(symbol, period, 0) or iLow(symbol, period, 0) when computing a stop loss — the backtest knows the full candle's extreme, the live trader does not. Third: synchronising data from multiple timeframes without verifying that the H4 candle closed before the M15 candle on which the strategy enters. Detection: if your equity curve is suspiciously smooth (drawdown below 5 percent, profit factor above 3.5, win rate over 75 percent on 200 trades), put the same EA on a demo account for a month. A 50 percent performance gap almost always indicates look-ahead bias somewhere in the code. Fix: always read indicators and price history at index 1 or higher (closed candle), verify exit conditions through CopyClose or CopyRates with explicit close-time arguments, and check timeframe synchronisation with SymbolInfoInteger(symbol, SYMBOL_TIME).
Manual versus automated backtesting — which one makes sense?
Both have a role, but at different stages of the workflow. Manual backtesting (stepping bar by bar in a replay tool such as TradingView Bar Replay or MT5's step function) is the right tool for discretionary traders who operate on price action and either cannot or will not formalise their rules into code. It builds a feel for volatility, market rhythm and the moment when a setup begins to look attractive. The drawbacks are subjectivity, zero replication (a second pass through the same period produces a different result) and long hours — two hundred trades on M15 takes thirty to fifty hours of careful work. Automated backtesting through Strategy Tester demands that the strategy live as an Expert Advisor — every entry, exit and risk-management rule must be expressed mathematically, with no room for "feel". The payoff is replication (identical results every time on identical data), statistical significance (5,000 trades in a single evening) and objective metrics. The drawback is that it cannot capture discretionary chart-pattern judgement, so intuition-driven price-action strategies slip through this net. The golden path is to start with a manual backtest of one hundred trades to understand the market and your own approach. If the result is encouraging, formalise the rules into an EA and run it through automated Strategy Tester with walk-forward — that step separates real intuition from curve-fitted memories. Pure intuition loses to a mechanical system about ninety percent of the time across a twelve-month live sample.