MT5 Strategy Tester: How to Backtest an EA, Step by Step

How to backtest an EA in the MT5 Strategy Tester: the settings, a tick-mode table, how to read the report, forward and walk-forward tests, and tester vs live.

๐Ÿ“– 15 min read

๐Ÿ“ 2,827 words

๐Ÿท๏ธ MQL5 and Expert Advisors

Share this article:

MT5 Strategy Tester: How to Backtest an EA in MetaTrader 5

Short answer: open the Strategy Tester with Ctrl+R, pick your Expert Advisor, the symbol, the timeframe and the dates, choose a tick mode, set the deposit, leverage and an execution delay, and click Start. For an EA with tight stops or one that acts inside a bar, test on "Every tick based on real ticks"; "1 minute OHLC" is for fast passes and "Open prices only" only for EAs that act once per new bar. Then read the report in this order: history quality and trade count, equity drawdown and losing streaks, and only then profit factor and expected payoff. A backtest is a first filter, not a verdict: check a forward period and run the EA on a demo account before any live money.

This guide shows each setting, a table of the tick modes, how to read the report, forward and walk-forward tests, why tester and live results differ, and two tester limits we measured ourselves.

Part of the MQL5 and Expert Advisors academy.


How to Backtest an EA in MT5, Step by Step

The MetaTrader 5 Strategy Tester [1] replays history and lets the EA trade it with virtual orders. The settings below are on its Settings tab; the Strategy Testing (opens in a new tab) help page [2] describes each one.

  1. Open the tester. View โ†’ Strategy Tester, or Ctrl+R. It opens at the bottom of the terminal.
  2. Pick the Expert Advisor. From the Expert dropdown, or right-click the EA in the Navigator (Ctrl+N) โ†’ Test. It must be compiled (F7 in MetaEditor).
  3. Pick the symbol and timeframe. The symbol must be in Market Watch (Ctrl+U to add it), with the exact suffix your broker uses (EURUSD and EURUSD.a are different symbols).
  4. Set the dates. A long enough stretch for the EA to trade many times, in more than one kind of market. The tester loads extra history before the start date for the indicators.
  5. Choose the tick mode. See the table in the next section.
  6. Set deposit, leverage and delay. Use your real account's deposit currency and leverage. Set Delays to a fixed delay close to your ping (the tester can measure it) or to a random delay, not "zero latency": no live account fills at zero delay.
  7. Set Forward if you will optimize (next sections), then click Start. Progress shows at the bottom; the report opens when it ends.
MetaTrader 5 Strategy Tester panel โ€” โ‘  Strategy Tester tabs โ‘ก Test type icons (Single, Visualize, Genetic) โ‘ข Previous test results list
MetaTrader 5 Strategy Tester panel โ€” โ‘  Strategy Tester tabs โ‘ก Test type icons (Single, Visualize, Genetic) โ‘ข Previous test results list
MT5 Strategy Tester settings โ€” Expert Advisor selection in Navigator, Symbol (EURUSD), Timeframe (H1), and EA parameters on chart
MT5 Strategy Tester settings โ€” Expert Advisor selection in Navigator, Symbol (EURUSD), Timeframe (H1), and EA parameters on chart

To watch the EA trade bar by bar, tick Visual mode before Start: a chart opens with its trades and a speed control. It needs local agents and does not work during optimization.


Which Tick Mode Should You Use?

The tick mode decides how the tester moves the price inside each bar. MetaTrader 5 can use real or generated ticks (opens in a new tab) [3]; the choice changes results most for EAs with tight stops and targets.

ModeWhat it doesUse it whenWhat it can miss
Every tick based on real ticksReplays the ticks your broker recorded, with their spreadFinal checks; scalpers; tight stops; trailing stops; anything that acts inside a barOnly as good as the broker's tick history; the first run is slow while it downloads
Every tickBuilds ticks from one-minute bars with the tester's algorithmReal ticks are missing for your symbol or datesThe real order of highs and lows and the real spread changes inside each minute
1 minute OHLCUses only the open, high, low and close of each one-minute barFast passes and first optimizations of EAs that act on closed barsMoves inside each minute; a stop and a target in the same minute
Open prices onlyRuns the EA at the open of each bar of the test timeframeEAs that check their rules once per new bar, and quick rough checksEverything inside the bar: stops, targets and trailing are guessed
Math calculationsLoads no market data; only OnInit, OnTester and OnDeinit runPure calculations and optimizing math, not tradingPrices, orders and margin: there are none

A simple rule: optimize on "1 minute OHLC" to save time, then re-run the chosen inputs on real ticks. If the result changes a lot between the two, the EA depends on what happens inside the bar, and only the real-tick run counts.


How to Read the Strategy Tester Report

When the run ends, the Backtest tab (called Results in the help) shows the statistics and the Graph tab the balance and equity curves. The help page on the testing report (opens in a new tab) [4] defines every field. Read it in this order:

ReadFieldWhat it tells youWhat to check
1History qualityThe share of correct one-minute data in the testWell below 100 % means gaps or bad bars: the result is unreliable
2Total tradesHow many trades closedA few dozen trades prove little; more trades, in different markets, say more
3Equity drawdown maximal / relativeThe deepest fall of equity, open trades includedCould you live with it, in money and in %? It is the number to size risk on
4Balance vs equity drawdownBalance counts closed trades onlyEquity drawdown far above balance drawdown: trades sat deep in loss before closing
5Maximum consecutive lossesThe longest losing streak and what it costMultiply by your risk per trade: that is the streak you must survive
6Profit factorGross profit รท gross lossClose to 1 means costs decide the result; check it again after realistic costs
7Expected payoffThe average result per tradeCompare it with your spread and commission per trade
8Recovery factor, Sharpe ratioResult against drawdown; result against its own variationUse them to compare runs of the same EA, not as a target

On the Graph tab, look for a curve that rises in steps across the whole test, not one that depends on a single period. The Journal tab lists every error the EA met; a clean report with a Journal full of errors is not clean.

MT5 Strategy Tester Backtest tab โ€” Total Net Profit, Profit Factor, Drawdown, Total Trades, and entry distribution charts
MT5 Strategy Tester Backtest tab โ€” Total Net Profit, Profit Factor, Drawdown, Total Trades, and entry distribution charts
MT5 Strategy Tester Graph tab โ€” Balance (blue) and Equity (green) curves over time for EA backtest results
MT5 Strategy Tester Graph tab โ€” Balance (blue) and Equity (green) curves over time for EA backtest results

Optimization, Forward Testing and Walk-Forward

Optimization. Tick an input's box on the Inputs tab, set Start, Step and Stop, pick a criterion and an optimization type (slow complete or fast genetic), and Start. The Optimization tab lists every pass. The best pass on past data is often the one that fits its noise best.

Forward. The Forward (opens in a new tab) setting [5] splits the date range: No, 1/2, 1/3, 1/4 or Custom (you set the forward start date). The EA is optimized on the first part and the chosen inputs are checked on the most recent part; those results appear on a separate Forward tab, with a line at the forward start on the chart. Inputs that hold up only in the first part were fitted to it.

Walk-forward. MetaTrader 5 has no built-in walk-forward analysis, but you can do it by hand with the Forward setting:

WindowOptimize onThen check on
1Months 1-12Months 13-15
2Months 4-15Months 16-18
3Months 7-18Months 19-21

Each window is one tester run with a custom forward date. Keep an EA only if most forward windows hold up with similar inputs; if each window needs very different inputs, the rules are fitting noise. Warning signs at any stage: a strong backtest with a weak forward part, most trades packed into one period, and extreme inputs (a period of 3, a stop of 2 points).


Strategy Tester vs Live: Why Results Differ

The tester replays history under assumptions about ticks, spread and fills. A live account adds spread widening, slippage, delays and the broker's rules. If an EA looks good in the tester and fails on a real account, the gap is usually in the settings or the execution, not bad luck: fix those before you change the strategy.

FactorStrategy TesterLive / demo account
SpreadFrom the history, or the value you setWidens at news, at the daily rollover and in thin hours
FillsAt the tested prices, unless you set a delaySlippage, requotes, partial fills
DelayWhat you set under DelaysInternet, VPS and broker execution
Stop levelApplied to the prices the tester modelsEnforced: 10016 invalid stops
SymbolThe one you pickedSuffixes and contract specs differ per broker
YouAbsentSwitching the EA off, changing inputs mid-run
  • Spread and slippage. Scalping and gold EAs are the most sensitive: see Scalping EA for MT5 and Gold EA (XAUUSD). Test with a realistic spread and add a spread filter to the EA.
  • Lot and margin. Read volume limits and tick value from the broker, never assume them: EA risk management.
  • Prop accounts. The standard tester does not model daily-loss or news rules: prop firm EA rules.

An EA made without code has the same gap: it comes from market modelling and execution, not from how the MQL5 was written.


Two Tester Limits We Measured

We run the MQL5 code that AlfaTactix generates in the MetaTrader 5 tester to check it against our own backtest. Two tester behaviours from those runs matter for anyone testing an EA:

1. Higher-timeframe history starts on 1 January of the year before the test. The tester gave our Expert Advisor higher-timeframe history only from 1 January of the year before the test start. An EA on H4 that read a daily EMA 200 asked for 1,000 daily bars and got 303. The help page says the tester loads extra history before the start; it does not load as much as a long higher-timeframe indicator may want. What to do: if the EA reads a slow indicator on a higher timeframe, start the test later in the year, or judge only the trades after the indicator has had its bars.

2. A custom symbol is charged no commission and no slippage. On a custom symbol (one you create in MetaTrader 5 and fill with imported prices), the tester charges no commission, no slippage and no limit-order fill offset. A report on a custom symbol leaves those costs out, so subtract them yourself before you judge it.

Limits of what we measured: because of point 2, our trade comparisons with MetaTrader 5 do not prove commission and slippage there. Our runs used one symbol, one broker's feed and the "1 minute OHLC" mode; real-tick mode and live or forward trading were not run.


Or Backtest on the Site, Without MT5

If you build the strategy in the AlfaTactix Strategy Builder, you can test the same rules before you open MetaTrader 5. The backtest runs on the site: you don't need MetaTrader 5 or TradingView to backtest. Backtests run on data you upload, on any timeframe down to one minute; how many days one run covers depends on your plan (Pricing). The backtest is open to every signed-in user, on every plan, Free included.

Then download the generated EA and confirm it in the Strategy Tester with the steps above. How the engine compares with the MetaTrader 5 tester, and its limits: Backtest engine. Start here: No-code backtest.

A backtest is not a forecast; past results do not predict future results.


Troubleshooting

SymptomLikely causeFix
EA not in the dropdownNot compiled, or not in MQL5/ExpertsCompile in MetaEditor (F7) and refresh the Navigator
No tradesSymbol not in Market Watch, filters never pass, lot below the minimumRead the Journal; check volume limits and filters on the test dates
"Not enough money"Lot too large for the deposit and leverageSize from risk and check margin: EA risk management
Invalid stops in the JournalStops inside the stop levelRead SYMBOL_TRADE_STOPS_LEVEL: Error 10016
Results change a lot between modesThe EA depends on moves inside the barTrust the real-tick run
Very slow runReal ticks over a long period, or a huge optimizationOptimize on 1 minute OHLC, use the genetic algorithm, then re-check on real ticks

Checklist Before Going Live

StepAction
1Re-run the chosen inputs on Every tick based on real ticks
2Use a realistic spread and a non-zero delay
3Check a Forward period, or walk-forward windows
4Read the report in order: quality, trades, equity drawdown, streaks, then the rest
5Run the EA on demo across several sessions and compare its fills with the tester
6Journal clean: no repeated 10016 / 10019 errors (common errors)
7A VPS if the EA must run around the clock: VPS for an EA
8Start live with the minimum lot and the risk caps you tested

Design and test on desktop; the MT5 mobile app is for watching demo or live trades, not for tick-mode tests.


Next Steps

After the checklist, move the EA to demo first. Size every trade from your risk with EA Risk Management. To build the rules without code and test them on the site first, see Build an EA without coding.

Frequently Asked Questions

Press Ctrl+R (View โ†’ Strategy Tester), pick the Expert Advisor, the symbol, the timeframe and the dates, choose the tick mode, set the deposit, leverage and delay, then click Start. Read the Backtest tab and the Graph tab when it ends. Before you trust a result, check a forward period and run the EA on a demo account.

Every tick based on real ticks when your broker has tick history and the EA has tight stops or acts inside a bar. 1 minute OHLC for fast passes and first optimizations of EAs that act on closed bars. Open prices only only for EAs that check their rules once per new bar. Every tick (generated ticks) when real ticks are missing.

"Every tick" builds ticks from one-minute bars with the tester's own algorithm. "Every tick based on real ticks" replays the ticks your broker recorded, so the spread changes and the order of highs and lows are the ones that happened. The first run with real ticks can be slow while the history downloads.

Start with History quality and Total trades (is the test valid and large enough?), then Equity drawdown maximal and Maximum consecutive losses (how bad did it get?), then Profit factor, Expected payoff and Recovery factor. Compare equity drawdown with balance drawdown: a large gap means trades sat deep in loss before they closed.

The Forward setting (1/2, 1/3, 1/4 or a custom date) splits the period: the EA is optimized on the first part, and the chosen inputs are checked on the most recent part, shown on a separate Forward tab. MT5 has no built-in walk-forward analysis: you repeat optimize-then-forward on windows you shift forward by hand and keep only inputs that hold in most forward windows.

Check the Journal tab first. Common causes: the symbol is missing from Market Watch, the history is too short for the indicators, a lot below the symbol's minimum volume, stops closer than the stop level, or a time or spread filter that never passes on the test dates.

Usually settings or execution, not the signal: a coarse tick mode, a test spread tighter than live, no delay, over-optimized inputs, or the broker's stop level refusing orders live (Error 10016). Re-test on real ticks with a realistic spread and a delay, check a forward period, then run the EA on demo.

In our checks the MetaTrader 5 tester gave an Expert Advisor higher-timeframe history only from 1 January of the year before the test start: an EA on H4 that wanted 1,000 daily bars for a daily EMA 200 got 303. A long indicator may not be warmed up when the test begins, so start the test later or judge only the trades after the warm-up.

The MT5 Strategy Tester needs MetaTrader 5. In AlfaTactix, the backtest runs on the site: you don't need MetaTrader 5 or TradingView to backtest. Backtests run on data you upload, on any timeframe down to one minute; how many days one run covers depends on your plan. Then confirm the generated EA in the Strategy Tester. See No-code backtest.

References

  1. MetaQuotes. MetaTrader 5 Built-in Trading Strategy Tester. https://www.metatrader5.com/en/automated-trading/strategy-tester
  2. MetaQuotes, MetaTrader 5 Help. Strategy Testing. https://www.metatrader5.com/en/terminal/help/algotrading/testing
  3. MetaQuotes, MetaTrader 5 Help. Real and Generated Ticks. https://www.metatrader5.com/en/terminal/help/algotrading/tick_generation
  4. MetaQuotes, MetaTrader 5 Help. Testing Report. https://www.metatrader5.com/en/terminal/help/algotrading/testing_report
  5. MetaQuotes, MetaTrader 5 Help. Strategy Testing โ€” Forward testing. https://www.metatrader5.com/en/terminal/help/algotrading/testing#forward