Trading forex and CFDs on leverage is high risk. Most retail accounts lose money. Read the risk warning

How to Backtest an EA in MT5 (and Get Results You Can Actually Trust)

To backtest an EA in MT5, open the Strategy Tester (Ctrl+R), choose the expert advisor, symbol, timeframe and date range, set the modelling to "Every tick based on real ticks", enter a realistic deposit, leverage and execution delay, then press Start and read the Backtest and Graph tabs. The mechanics take five minutes. Getting a result that means something takes longer, because the defaults flatter most strategies and a backtest only describes the past under the assumptions you gave it.

Key takeaways

  • Use "Every tick based on real ticks" for anything that trades intrabar; "Open prices only" is for quick screening of bar-close logic.
  • Set a non-zero execution delay and check that your broker's real-tick history covers the whole test period.
  • Judge the report on drawdown, profit factor, trade count and the shape of the equity curve, not net profit alone.
  • Reserve part of your data for forward testing so optimisation cannot see it.
  • A good backtest is a filter for bad ideas, not evidence of future profit.

Before you start: what you need

You need MetaTrader 5 installed and logged in to an account with the broker whose conditions you want to simulate, ideally a demo with the same account type you would trade live (raw spread plus commission, or standard spread). The tester downloads that broker's price history, so results from Broker A will not exactly match Broker B. You also need the EA itself, either as a compiled .ex5 file or as .mq5 source, placed in the MQL5\Experts folder. If you have not done that yet, follow our guide on how to install an expert advisor on MT5 first.

Finally, decide what question the backtest should answer. "Is this profitable?" is too vague. "Does this EA's edge survive realistic costs on EUR/USD and GBP/USD from 2020 to 2024, with a maximum drawdown under 20%?" is testable.

Step 1: Open the Strategy Tester and set the basics

Pick the EA

Press Ctrl+R or go to View, then Strategy Tester. MT5 opens a panel at the bottom of the terminal, and recent builds show an overview page with test types. Choose single test (not optimisation yet). On the Settings tab, use the Expert drop-down to select your EA. If it does not appear, it is either in the wrong folder or failed to compile; refresh the Navigator, or open the source in MetaEditor and press F7 to see compile errors.

Set symbol, timeframe and dates

Pick the symbol exactly as your broker names it, including suffixes such as EURUSD.raw. The timeframe you choose is the chart the EA "sits on"; an EA can still request data from other timeframes internally. For the date range, choose a period long enough to include different conditions: a trending year, a ranging year, and at least one stressful event. For most intraday systems, three to five years is a sensible minimum, and you want several hundred trades at least. Thirty trades tells you very little.

Step 2: Choose the modelling mode

This is the single most important setting. MT5 offers five modes:

Modelling modeWhat it simulatesSpeedUse it for
Every tick based on real ticksThe broker's recorded tick history, with real variable spreads where availableSlowestFinal validation, scalpers, anything with tight stops or trailing logic
Every tickTicks generated synthetically from M1 barsSlowWhen real tick history is missing for part of the period
1 minute OHLCOnly open, high, low and close of each M1 barFastRough checks of strategies with wide stops
Open prices onlyOnly the opening price of each bar on the test timeframeVery fastScreening EAs that act strictly at bar open; optimisation first passes
Math calculationsNo price data at allInstantTesting calculations, not trading

The trap is "Open prices only" on an EA that checks conditions on every tick. The tester will not know whether a stop-loss or take-profit inside a bar was hit first, and results can be wildly optimistic. If an EA's profit changes drastically between "Open prices only" and "Every tick based on real ticks", trust the latter and ask why the gap exists.

After a real-tick test, the Journal tab and the report show the history quality. If the broker's tick data has gaps, MT5 fills them with generated ticks and the quality percentage drops. Low quality in the period where most trades happened is a reason to distrust the result.

Step 3: Deposit, leverage and execution delay

Enter the deposit you would really trade with, in your account currency. Set leverage to what your account would have, not the maximum the drop-down offers. A UK, EU or Australian retail client is capped at 30:1 on major pairs; a US client at 50:1. Testing at 500:1 hides margin problems you would hit in reality. Our leverage explainer walks through the margin maths.

Next to modelling there is a delay setting. The default "Zero latency, ideal execution" fills every order instantly at the requested price, which no live account achieves. Choose a fixed delay (for example 50 to 200 milliseconds, depending on where your terminal or VPS runs relative to the broker's server) or the random delay option. Scalping EAs that look brilliant at zero latency often fall apart with a realistic delay, and that is exactly what you want to discover now.

Step 4: Inputs, costs and commission

Open the Inputs tab and set the EA's parameters. Check the risk settings carefully: lot size, risk per trade, maximum open trades, and whether any "recovery" or multiplier option is enabled. If the EA risks a fixed lot, think about whether that matches your plan; many traders work to a 1% risk rule instead.

Commission is the next issue. In real-tick mode MT5 uses the recorded spread, but commission on raw-spread accounts depends on how the broker configured the symbol in the tester. Check the Deals in the report to confirm commission is being charged. If it is not, you can usually adjust it via a custom symbol, or at minimum subtract the expected commission manually. On a raw account charging, for illustration, $7 per round-turn standard lot, 1,000 trades of one lot costs $7,000 that a careless test omits.

Step 5: Run the test and read the report

Press Start. Watch the Journal tab for errors such as "not enough money", "invalid stops" or "market closed", which reveal logic bugs. When the test ends, open the Backtest tab. These are the numbers worth reading first:

  • Total trades. Fewer than about 100 makes every other statistic unreliable.
  • Profit factor (gross profit divided by gross loss). Values just above 1 are fragile once real costs vary; very high values on a short test often signal curve fitting.
  • Expected payoff. Average profit per trade in account currency. Compare it to your cost per trade; if it is only slightly larger, small changes in spread will erase it.
  • Maximum drawdown, balance and equity. Equity drawdown includes open losses and is the one that matters. A big gap between the two suggests the EA holds losing trades for a long time, a pattern typical of grid systems.
  • Recovery factor and Sharpe ratio. Useful for comparing variants of the same EA.
  • Consecutive losses. Ask whether you would keep running the EA after that many losses in a row.

Then open the Graph tab. A steadily rising balance line with an equity line that dips deeply below it is the visual signature of averaging down. A curve that does all its work in one six-month window and goes sideways or down otherwise is a strategy that fitted one regime.

A worked example

Say an EA traded EUR/USD from January 2021 to December 2024 on a $10,000 account and produced 620 trades, net profit $4,340, profit factor 1.28 and maximum equity drawdown $2,150 (about 18%). Expected payoff is $4,340 ÷ 620 = $7.00 per trade. If the average position was 0.5 lots, a pip was worth $5, so the average trade made 1.4 pips net. Now suppose live spreads average 0.3 pips wider than the test assumed: that is 0.3 × $5 × 620 = $930 of extra cost, cutting net profit by more than a fifth. Add slippage and the strategy is plausibly break-even. That calculation, done before risking money, is the whole point of backtesting.

Step 6: Optimise carefully, then forward test

Optimisation lets MT5 try many parameter combinations. Choose Optimization on the Settings tab, tick the parameters to vary on the Inputs tab with start, step and stop values, and select either the slow complete algorithm or the fast genetic algorithm. Pick an optimisation criterion such as balance, profit factor, recovery factor or a custom criterion coded in the EA.

The critical setting is Forward. Set it to 1/3 or 1/4, and MT5 will reserve the final part of your date range: it optimises on the earlier data, then runs each of the best parameter sets on the unseen later data. Results that look good in-sample but collapse forward are overfitted. Look for parameter regions where many neighbouring settings are profitable, not a single sharp peak. A more rigorous version of this process is walk-forward testing, which repeats the optimise-then-test cycle across rolling windows.

You can also run the EA across several symbols by selecting "All symbols selected in Market Watch" in the symbol optimisation option. A robust idea usually works, at least weakly, on related pairs. One that works on a single pair and nowhere else deserves suspicion.

The main risk: a backtest is a simulation under your assumptions, not a forecast. The more parameters you optimise and the more variants you try, the more likely your best result is luck. Most retail CFD and forex accounts lose money, and automated systems that test well routinely fail live because of overfitting, changed market conditions, wider spreads, slippage or broker rules. Always follow a backtest with weeks on a demo account and then very small live size before trusting an EA with meaningful capital.

Common backtesting mistakes in MT5

MistakeWhat it does to resultsFix
Using "Open prices only" on tick-based logicInflates profit, ignores intrabar stop hitsValidate in real-tick mode
Zero latencyPerfect fills that never happen liveSet a realistic fixed or random delay
No commission on raw accountsOverstates expected payoffCheck deals; add commission via custom symbol or manually
Excessive leverageHides margin callsUse your real regulatory cap
Short test periodToo few trades, one regime onlySeveral years, hundreds of trades
Optimising on all the dataCurve-fit parametersUse Forward and walk-forward tests
Ignoring swapOverstates long-holding strategiesConfirm swap is applied in the report

After the backtest: from tester to live

A clean, realistic backtest earns an EA the right to a demo trial, nothing more. Run it on a demo account under the same conditions you would use live, ideally on a VPS near your broker's server; our comparison of forex VPS hosting explains why location matters. Compare the demo trades to what the tester would have done over the same weeks: the same entries, similar fills, similar costs. If the live behaviour diverges, find out why before going further. Then move to a live account at the smallest size available and scale only when the live statistics resemble the backtest over a meaningful number of trades.

It also helps to stress the result. Re-run the test with a higher delay and wider spread to see how much margin of safety there is, and run the trade list through a Monte Carlo simulation to see how bad drawdowns could plausibly get with the same trades in a different order.

Frequently asked questions

What is the most accurate backtest mode in MT5?

"Every tick based on real ticks" is the most realistic because it replays the broker's recorded tick history, including variable spreads. Its accuracy still depends on the quality of that broker's history, so check the history quality figure in the report. Where real ticks are missing, MT5 fills the gaps with generated ticks, which reduces realism for scalping and tight-stop strategies.

Why are my MT5 backtest results different from live trading?

Common causes are zero-latency testing, missing commission, spreads that were tighter in the test than in your live session, slippage on news, swap charges, and differences between your broker's data and the data the EA was developed on. Overfitting is the other big reason: parameters tuned to the past rarely perform as well on new data. Test with realistic delays and costs to narrow the gap.

How many years should I backtest an EA?

There is no fixed rule, but most intraday strategies should be tested over at least three to five years and several hundred trades, covering both trending and ranging conditions. Longer is better if the broker's history is reliable for the whole period. Fewer than about 100 trades gives statistics that can change dramatically with a handful of results.

What does the Forward option in the MT5 tester do?

It splits your date range so that optimisation runs on the earlier portion and the best parameter sets are then tested on the later portion that the optimiser never saw. If performance holds up forward, the parameters are less likely to be curve-fitted. If it collapses, the optimisation probably found noise rather than an edge.

Can I backtest an EA on multiple currency pairs at once in MT5?

Yes. MT5's tester is multi-currency, so an EA coded to trade several symbols can be tested in one run. You can also use the symbol optimisation option to run the same EA separately across all symbols selected in Market Watch, which is a quick way to see whether an idea generalises or only works on one pair.

Is a profitable backtest enough to go live?

No. A profitable backtest is only the first filter. You should forward test on a demo account for several weeks, compare the trades to what the tester predicts, and then trade very small live size. Leverage magnifies losses, most retail forex accounts lose money, and many EAs that backtest well fail live because of changing conditions and execution costs.

This article is general information, not personal financial advice. Figures such as spreads, fees, leverage and rules change; confirm them with the provider and check the provider is authorised for your country of residence.