Par William Harris · Dernière révision
How to Backtest an Expert Advisor in MetaTrader 5 (Strategy Tester deep dive)
Ce dont vous avez besoin
- • MT5 with the EA installed and configured
- • Tick data from the broker (auto-downloads on first run)
- • At least 2 GB free RAM for multi-year M1 backtests
Instructions étape par étape
Étape 1 : Open the Strategy Tester
View → Strategy Tester (Ctrl+R). The tester panel appears at the bottom of MT5 with tabs Settings, Inputs, and Results.
The Strategy Tester is a separate engine from the live terminal — it has its own copy of the EA's compiled code, its own historical tick stream, and runs in a sandbox with no network access. This is by design: a backtest must be deterministic and reproducible.
First-time use requires MT5 to download historical data for the symbol + timeframe combination you pick. The first backtest of any pair triggers a download of M1 ticks for the entire requested date range, which can take 5–20 minutes depending on the broker and date range. Subsequent runs reuse the cached data and start instantly.
Étape 2 : Configure the Settings tab
On the Settings tab, fill in: Expert (pick your EA from the dropdown), Symbol (pick from your broker's symbols), Period (the timeframe; usually match the live attach timeframe), Modelling (see next step), Date (From/To), Forward (split for walk-forward testing), Deposit (the initial balance), Leverage (the broker's actual leverage on your account type), Currency (account currency), Optimization (off for a single backtest).
Date range matters a lot. For a credible backtest, use a minimum 5-year window that includes both trending and ranging regimes — typically 2018-01-01 to today covers the 2020 COVID volatility spike, the 2022 inflation regime change, and the 2024+ rate-cut cycle. Anything shorter risks fitting to one regime.
Deposit should match your live account — 0.1 lot trades produce very different psychological pressure on $1000 vs $100,000 even when the absolute P&L is the same; lot-percent risk models will scale accordingly.
Étape 3 : Pick the right Modelling mode
Modelling determines how MT5 reconstructs each price tick during the backtest. There are four modes:
'Every tick' — uses M1 OHLC to interpolate every tick. Fast, but ticks are synthetic. Profit factor on scalping EAs is often 1.5–2× too high. Avoid for scalping.
'Every tick based on real ticks' — uses the broker's actual recorded tick history. Slow (10× longer than synthetic) but produces backtests that closely match live performance. Use for any EA on M1/M5 timeframe or any scalping strategy.
'OHLC 1 minute' — uses only the open, high, low, close of each M1 bar. Very fast but the order of high vs low within the bar is undefined, which breaks any EA that uses intra-bar logic. Useful only for daily-timeframe EAs.
'Open prices only' — fastest but unrealistic. Use only for sanity-checking initialisation logic, never for performance evaluation.
Default to 'Every tick based on real ticks' unless you are time-constrained or running a daily-timeframe EA.
Étape 4 : Load the vendor preset on the Inputs tab
Switch to the Inputs tab. Click Load and pick your vendor .set file from MQL5/Presets/. Verify the loaded values are appropriate for the backtest scenario.
For a fair backtest you want the EA configured exactly as it would run live. That means: same lot size, same risk percent, same time filters, same magic number. The only setting you should override for the backtest is the trading-window date if the EA hard-codes 'do not trade before 2024' or similar.
If the EA has a 'Backtest Mode' or 'Optimization Mode' input that disables certain checks, leave it off. Those modes exist for fitting and produce unrealistically good backtest results.
Étape 5 : Set realistic spread and commission
Strategy Tester defaults to 'Current spread' which uses the live tick spread at the moment you start the backtest. This is unrealistic — spreads widen during news, during low-liquidity hours (Sydney open), and during fast moves.
For a pessimistic backtest, override the spread to a fixed point value 50–100% above the typical spread. For EURUSD on ECN, typical is 0.3 pips so use 0.6 pips (6 points). For XAUUSD, typical is 20 points so use 40 points. The resulting backtest is conservatively pessimistic.
Commission is set via Tools → Options → Charts → 'Commission, $ per 1.0 lot per side' — but this only affects the live terminal display. For Strategy Tester commission, the broker's tick data file usually includes commission metadata. If you need to override, edit the symbol specification in `Symbols → Properties → Trade → Commission`.
Étape 6 : Run the backtest
Click Start. The Strategy Tester begins streaming historical ticks through the EA. Progress is shown as a bar at the bottom; the Equity curve updates in real-time on the Graph tab.
A 5-year EURUSD M5 backtest with Every-Real-Ticks takes about 15 minutes on a modern PC. XAUUSD M1 backtests are slower because the tick density is 5–10× higher than EURUSD. If your machine is single-core (e.g. Mac via Wine), expect 3–5× longer durations.
Watch the Journal tab during the run for errors. Common runtime errors are 'Cannot load history' (data still downloading; pause the backtest, wait, restart) and 'Symbol not found' (symbol name mismatch). Successful runs complete with 'Tester result: ...' in the log.
Étape 7 : Interpret the Results tab
When the backtest completes, the Results tab shows summary metrics. The key fields to read, in order of importance:
Profit Factor = gross_profit / gross_loss. 1.5+ is acceptable, 2.0+ is good, 3.0+ is suspicious (probably overfit). Below 1.3, the EA loses money after spreads and commissions.
Maximum Drawdown — the biggest peak-to-trough equity drop. Should not exceed 30% for any retail EA; 50%+ means the EA blows up an average account during a typical bad year.
Sharpe Ratio (visible in MT5 build 4000+) — risk-adjusted return. Above 1.0 is acceptable; 2.0+ is good. The MT5 calculation uses daily returns; backtests under 1 year may give misleading values.
Recovery Factor = net_profit / max_drawdown. Above 5 is good — means the EA recovers from its worst drawdown 5× over. Below 2 is fragile.
Total Trades — backtest credibility scales with trade count. Below 100 trades, the metrics are noisy. Aim for 500+ trades over a 5-year window.
Étape 8 : Save the backtest report
Right-click anywhere in the Results tab → 'Save as Report...'. MT5 generates an HTML report with the full equity curve, monthly returns, drawdown profile, trade list, and all summary metrics. Save the report somewhere persistent — these are the documents you compare future backtests against.
For systematic tuning, also save the .set file via the Inputs tab → Save button, named with the backtest date and key metric, e.g. `MyEA-Aggressive-PF1.82-DD18-2026-05-17.set`. This way you have a paper trail of which preset produced which backtest.
Before acting on a backtest, run the same EA in walk-forward mode (Settings → Forward, split 50/50). Walk-forward results meaningfully diverging from in-sample results are the single most important indicator that the in-sample numbers are overfit.
Erreurs courantes à éviter
- ✗ Using 'Every tick' (synthetic) modelling for scalping EAsSolution: Always use 'Every tick based on real ticks' for sub-H1 timeframes. Synthetic ticks miss the spread widening that kills scalpers in live.
- ✗ Backtesting on 1 year of data and treating the result as predictiveSolution: 5 years minimum. Single-year backtests have too few regime changes to be statistically meaningful.
- ✗ Leaving spread at 'Current' instead of a pessimistic fixed valueSolution: Pad spread 50–100% above typical. Backtests with tight spreads look great but live execution loses 0.5+ pips per round trip.
- ✗ Ignoring commission entirelySolution: ECN accounts charge $3–7 per round-turn lot. For scalpers this is 30–50% of net profit; not modelling it is the biggest single source of optimistic backtest bias.
- ✗ Optimizing on the same period you backtest on (in-sample fitting)Solution: Use walk-forward: optimize on 70% of the period, validate on the remaining 30%. Discard any preset that doesn't survive the out-of-sample test.
- ✗ Backtesting only on a single symbol when the EA trades a basketSolution: MT5 backtests one symbol per run. For basket EAs, backtest each symbol separately and aggregate the results in a spreadsheet.
- ✗ Trusting Net Profit as the primary metricSolution: Net Profit can be inflated by an outsized lot size on a fluke trade. Use Profit Factor and Recovery Factor as primary; Net Profit as sanity check.
Questions fréquemment posées
Why does my backtest show 80% win rate but live trading shows 50%?
Backtest-to-live divergence is the most common complaint about EAs. A useful diagnostic is to backtest the same EA with the same .set on the most recent 30 days only, then compare the backtest's hypothetical trades against the EA's actual live trades over the same 30 days. If trade timestamps match but P&L differs, it's execution/slippage. If trade timestamps don't match, it's a code-environment issue (different data feeds, time-zone bugs).
Where does MT5 get the tick data for backtesting?
If your broker's history is too short for your backtest period, you have three options: (1) use a different broker terminal that has longer history, (2) import tick data from a third party like TickStory or Dukascopy via MT5's 'Import' button in the Symbols panel, or (3) accept the shorter backtest window. For paid serious EA development, many traders maintain a separate Tickmill or Dukascopy demo account purely for high-quality long-history tick data.
Can MT5 backtest a multi-symbol EA in one run?
The 'every symbol uses its own tick stream' mode requires the EA to explicitly enable it via `TestSetTickStreamMode(TESTER_TICK_STREAM_ALL_SYMBOLS)` in OnInit, or it falls back to synthetic ticks for non-master symbols. Most basket EAs published in 2024+ already handle this; older EAs may not. Check the vendor docs.
Can I run MT5 backtests in the cloud to speed them up?
The Cloud Network only accelerates Optimization mode (running many .set variants), not single backtests. For a single backtest, local CPU is your only option. To use cloud optimization, you need an MQL5 Community account with billing enabled, and the EA must compile without local DLL dependencies (cloud agents are sandboxed).
My backtest is taking 4+ hours — how can I make it faster?
Backtest speed depends on tick count × EA complexity. M1 EURUSD across 10 years is ~100 million ticks; with a complex EA evaluating 10 indicators per tick, this is genuinely 4+ hours on a single CPU core. The right speedup depends on what you're testing — for parameter tuning, faster modes are fine; for final go/no-go evaluation, run the slow Every-Real-Ticks mode and walk away from the machine.
Should I run a Monte Carlo analysis on my backtest results?
Standard MT5 backtest results show ONE possible historical equity curve — the actual chronological order. Monte Carlo asks: 'What if the same trades had arrived in a different order?'. For a trend-following EA, the answer is usually 'much worse drawdown', because the chronological order benefits from the actual sequence of trends. Run Monte Carlo before sizing live positions: pick the worst 1% drawdown from the Monte Carlo distribution as your risk budget, not the backtest's actual max drawdown.
Backtest looks promising — what's next?
Run an optimization sweep to tune the inputs against your live account size and broker, then walk-forward validate. Five-minute setup guide here.
Continue to: How to optimize an EA in MT5 →Guides connexes

William Harris
Fondateur et développeur principal de FxRobotEasy
Chicago, USA · Depuis 2021
- 12+ ans de trading en direct
- 10+ ans MQL5 / MQL4
- 3 Expert Advisors vérifiés en direct
- Fondé en 2021
“Je développe avec du code depuis le collège. Je trade depuis l'université. L'intersection de ces deux mondes — algorithmes, marchés et la technologie qui les relie — c'est là que j'ai passé les quinze dernières années. FxRobotEasy est ce qui se produit lorsqu'on refuse d'abandonner jusqu'à ce que l'idée imaginée fonctionne réellement sur un compte de courtier en direct.”