A backtest runs an Expert Advisor on past price data so you can see how its rules behaved before you risk money. MetaTrader 5 has a built-in Strategy Tester that does this well, but the settings you pick decide whether the report means anything. This guide shows how to set up a gold (XAUUSD) backtest, which modelling mode to use, how trading costs change the result, and how to read the numbers in the report.
Open the Strategy Tester
In the MT5 desktop terminal press Ctrl+R or choose View → Strategy Tester. The tester opens at the bottom of the window. Pick Single test (or simply open the Settings tab) and you will see the fields covered below. The EA must already be in the Navigator; if it is not, follow how to install an EA in MT5 first.
The settings that matter
- Expert: choose the EA.
- Symbol and timeframe: use your broker's exact gold symbol (for example XAUUSD, XAUUSDm or XAUUSD.r) and the timeframe stated in the EA's manual.
- Date range: use enough history to include different market conditions, such as a strong trend, a long range and a few high-volatility news periods. For an H1 system, two years or more is a reasonable minimum.
- Delays: "Zero latency, ideal execution" is the most optimistic. "Random delay" adds slippage-like timing and is closer to live trading.
- Modelling: see the next section.
- Deposit and leverage: match the account you plan to trade.
- Inputs tab: set the same risk, lot mode and filters you would use live. and save them as a .set file for the live chart.
Which modelling mode to choose
| Mode | What it does | Use it for |
|---|---|---|
| Every tick based on real ticks | Replays the broker's recorded ticks, including the real bid/ask spread at each tick | Final checks, scalping and short-stop systems on gold |
| Every tick | Generates ticks from M1 bars; spread comes from the bar history | General testing when real tick history is short or missing |
| 1 minute OHLC | Uses only open, high, low and close of each M1 bar | Fast first pass and optimization of slower systems |
| Open prices only | Runs only at the start of each bar | Only EAs that are written to act once per bar |
On XAUUSD, prefer Every tick based on real ticks for the run you actually trust. Gold can move several dollars inside one minute, so a stop and a target can both sit inside a single M1 bar. Coarser modes have to guess which was hit first, and that guess can turn a losing trade into a winning one on paper. If the report's history quality is well below 100%, part of the period had missing ticks and the result is weaker evidence.
Costs: spread and commission on gold
In MT5 you do not type a spread for a broker symbol. The tester takes it from the history: real recorded spreads in real-tick mode, or the spread stored with each bar in the other modes. That is a good reason to test on the broker you will trade with. Commission is applied only as the tester knows it for that account; if your account pays commission and the report's deals show none, subtract it yourself.
Costs matter more than most traders expect. On a 3-digit gold quote, 1 point is 0.01 dollars. On a standard 100-ounce contract, every 0.01 dollar of price is worth 1 USD per 1.00 lot.
The shorter the EA's average trade, the bigger this effect. A system that targets 1 dollar per trade loses a fifth of it to a 0.20 dollar cost difference; a system that targets 15 dollars hardly notices. See best timeframe for gold trading.
How to read the backtest report
Open the Backtest tab after the run. These are the numbers to read first, with an example report of 240 trades on a 10,000 USD deposit:
| Metric | Example value | What it tells you |
|---|---|---|
| Gross profit / gross loss | 4,200 / −3,000 USD | Total of winning trades and total of losing trades |
| Total net profit | 1,200 USD | Gross profit minus gross loss |
| Profit factor | 1.40 | 4,200 ÷ 3,000. Above 1 means winners outweighed losers in this sample |
| Expected payoff | 5.00 USD | 1,200 ÷ 240, the average result per trade. Compare it with your cost per trade |
| Equity drawdown maximal | 800 USD (7.3%) | Largest fall from a peak, including open trades |
| Recovery factor | 1.50 | 1,200 ÷ 800. How much the EA earned relative to its worst drawdown |
| Total trades | 240 | Sample size. Under about 100 trades, every other number is fragile |
Read them together, not alone. In the example, expected payoff is 5.00 USD per trade at 0.10 lot, while the spread gap from the cost section is 2 USD per trade. Almost half the edge depends on getting the same spread as the test.
Look at equity drawdown, not only balance drawdown. An EA that holds losing trades open can show a smooth balance line while equity dips deeply. On the graph, many small steps are more believable than one or two huge trades.
Turn the drawdown into position size
A backtest drawdown is not the worst case; live trading can and usually will exceed it at some point. A practical habit is to assume the future drawdown may be 1.5 to 2 times the tested one and size the EA so that figure is still acceptable. If the 800 USD drawdown above came from 1% risk per trade and you could only accept about 800 USD in total, halving the risk to 0.5% gives some room. The gold lot size calculator shows what lot a given risk and stop distance produce, the margin calculator checks that the account can carry it, and the 1% risk rule explains loss-streak math in more detail.
Avoid the over-optimization trap
The optimizer can try thousands of input combinations and will always find one that looked great in the past. That setting is often fitted to noise. A few habits reduce the risk:
- Set Forward to 1/3 or 1/4 so the optimizer never sees the last part of the history. If results collapse there, the edge was probably curve-fitted.
- Prefer a broad plateau of good settings over one sharp peak. If changing a period from 20 to 22 ruins the result, the setting is fragile.
- After the backtest, run the same settings on a demo account for several weeks and compare trade by trade.
Rule-based systems with a fixed stop on every trade are the easiest to test honestly, because each trade's maximum loss is known. The London Breakout EA trades a defined session range, and the Supertrend Rider EA follows trends with an ATR-based stop; both are good candidates to practise the steps above in the tester. Other styles are in the XAUUSD EA list.
Key takeaways
- Open the tester with Ctrl+R and test on your own broker's gold symbol, timeframe, deposit and leverage.
- For XAUUSD, trust "Every tick based on real ticks" over the faster modes.
- Spread comes from history; a 20-point gap costs 2 USD per trade at 0.10 lot, which can remove a large part of a small edge.
- Read profit factor, expected payoff, equity drawdown and trade count together, then size for a larger drawdown than the test showed.
FAQ
Which modelling mode is most accurate in MT5?
"Every tick based on real ticks" is the most realistic because it replays the broker's recorded ticks and their real spreads. It is also the slowest, so many traders use 1 minute OHLC for a first pass and real ticks for the final check.
Can I set a fixed spread in the MT5 Strategy Tester?
Not for a normal broker symbol. MT5 takes the spread from the price history. To test a higher cost, compare results on your broker's real ticks or adjust the expected result manually by the extra cost per trade.
How many trades does a backtest need?
There is no exact number, but under about 100 trades the results can change a lot from just a few outcomes. More trades across different market conditions make the statistics more stable.
What is a good profit factor for a gold EA?
A profit factor above 1 means winners outweighed losers in the test. Very high values on a small sample are often a sign of over-optimization. What matters more is whether it stays above 1 in a forward period and on demo after costs.
Can I backtest a Market EA before buying it?
Yes. MQL5 Market products have a free demo version that runs only in the Strategy Tester, so you can test it on your broker's data first.
For education only, not investment advice. Trading gold and CFDs is high risk and you can lose your capital.