How to Backtest an EA in MT5
Run an Expert Advisor through MetaTrader 5's Strategy Tester: choosing the modelling mode, costs and period, reading the report, and the mistakes that make a backtest lie.
By the AURAX teamPublished 5 min read
On this page (6)
To backtest an EA in MT5, open the Strategy Tester (Ctrl+R), pick the EA, symbol, timeframe and date range, choose a modelling mode — "Every tick based on real ticks" is the most realistic — set the deposit and leverage, and press Start. The hard part is not running the test; it is making sure the result means something. A backtest with unrealistic costs, a short or calm period, or parameters tuned to that period will look far better than live trading ever will.
Part of the MT5 Expert Advisor guide.
Setting up a test
Open the Strategy Tester
View → Strategy Tester, or Ctrl+R. Choose Single test on the Overview if it asks.
Choose the EA, symbol and timeframe
Use the broker's exact gold symbol. Many EAs have their own internal timing, but indicators still use the timeframe you set.
Set the date range
Long enough to include different conditions — calm ranges, strong trends, news shocks. A few quiet months tell you almost nothing.
Pick the modelling mode
Covered below. For anything that trades intrabar or manages positions tick by tick, use real ticks.
Deposit, leverage and delays
Match what you will trade live. The Delays option can add execution latency, which is more honest than the default ideal execution.
Inputs
On the Inputs tab, load the settings (a
.setfile) you intend to use live, then Start.
Modelling modes
The modelling mode decides what prices the EA sees during the test. MetaQuotes' own help describes them roughly as follows:
| Mode | What the EA sees | Use it for |
|---|---|---|
| Every tick based on real ticks | The broker's recorded tick history, with its real spreads | Final testing — the closest to live conditions |
| Every tick | Ticks generated from minute bars | Most EAs when real ticks are unavailable |
| 1 minute OHLC | Four prices per minute bar | Quick checks of logic that works on bar closes |
| Open prices only | One price per bar of the test timeframe | EAs that only act on a new bar — fast optimisation |
| Math calculations | No prices at all | Pure calculations, not trading tests |
Getting the costs right
In MT5 the spread comes from the historical data the test uses: real tick data carries the spread the broker actually quoted; generated ticks use the spread stored with the minute bars. Also check:
- Commission — on raw-spread accounts it is charged separately and must be part of the test (the symbol settings of the tester account determine it).
- Swap — charged on positions held overnight. Strategies that hold baskets for days pay it every night.
- Slippage — enable delays; a fill at the exact requested price on every news spike is not realistic.
Why it matters is covered in XAUUSD spread explained: the more often a strategy trades and the smaller its targets, the larger the share of profit the costs take.
Reading the report
| Figure | What it measures | Watch for |
|---|---|---|
| Total net profit | End balance minus deposit | Meaningless on its own — compare with the drawdown it took |
| Equity drawdown maximal / relative | Largest fall of equity from a peak, in money and % | The number that decides whether an account survives. See trading drawdown |
| Profit factor | Gross profit ÷ gross loss | Very high values often mean the losses are still ahead |
| Recovery factor | Net profit ÷ maximal drawdown | How much the strategy earned per unit of pain |
| Expected payoff | Average result per trade | Compare with the spread per trade |
| Largest loss trade | Worst single close | For grids, look at basket closes, not single positions |
How backtests lie
- Overfitting. Optimise enough parameters over one period and some combination will look excellent by chance. Use the Forward option to hold back part of the period and test the chosen settings on data the optimiser never saw.
- Cherry-picked periods. A test that starts after the last crash has no crash in it.
- Survivorship. Showing the one setting that worked out of hundreds tried.
- Ideal execution. No delays, no slippage, and fills during the minutes the spread was widest.
- Ignoring the tail. A strategy that wins 99 times and loses the account once has a great win rate and a terrible outcome.
After the tester, run the EA on a demo account in real time for weeks, and compare the fills, spreads and results with what the test predicted. Differences there are cheap lessons.
From backtest to live
A good backtest earns a strategy the right to a forward test, not the right to real money. The order that protects capital: tester with realistic costs → demo in real time → small live allocation → size up only if live matches expectations.
Sources
- Strategy Tester — MetaQuotes — MetaTrader 5 Help
Educational content, not financial advice. Trading gold and other leveraged products carries a high level of risk, including the possible loss of some or all of your capital. Automated strategies do not guarantee profit, and past or simulated performance is not indicative of future results. Risk disclosure.