Blog · Guides · 9 min read

How to Backtest an MT5 EA on Gold (XAUUSD) Properly

How to Backtest an MT5 EA on Gold (XAUUSD) Properly

To backtest an MT5 EA on gold, load your broker's exact XAUUSD symbol, run the Strategy Tester on "Every tick based on real ticks", charge realistic spread and slippage, and test at least a few years including a period you did not build the rules on. Then read equity drawdown and cost per trade before you look at profit. Gold punishes lazy tests because its contract size, spread and speed are all larger than on most forex pairs.

This guide covers the gold-specific parts. If you want the click-by-click tester walkthrough, we cover it in How to Backtest an EA in MT5 Strategy Tester. Here the focus is on what makes a gold backtest honest or misleading.

Check the symbol and the data first

Most bad backtests fail before the EA runs. The data or the symbol settings are wrong, and the report looks great anyway.

Open the symbol specification in MT5 (right-click XAUUSD in Market Watch, then Specification) and write down four things:

  • Contract size, usually 100 oz per lot
  • Digits, usually 2, so a price like 3,880.45
  • Tick size and tick value
  • Minimum lot, lot step and stops level

Why this matters: on a 100 oz contract, a $1 move is $100 per lot. If your broker's symbol is named XAUUSD.m or GOLD, with a different contract size, the same EA will size and lose money differently. Test on the symbol you will actually trade.

Next, data quality. MT5 downloads history from your broker's server, and gold history can have gaps, especially further back. After a run, check the history quality figure in the report. If it is low, or the chart shows flat bars and holes, the result tells you very little. Test on a different broker's data too if you can. A strategy that only works on one feed is usually working on that feed's quirks.

Set up the tester for gold

Here is the setup we use as a baseline.

Setting Use on gold Why
Symbol Exact broker symbol Contract size and tick value differ
Model Every tick based on real ticks Real spread and real price path
Execution Random delay, not zero latency Gold moves fast, fills are not instant
Deposit Your real account size Lot rounding changes results on small accounts
Leverage Same as your live account Margin can block trades
Period 3 to 4 years minimum One gold regime is not a test
Forward test Hold back the last part Checks rules on data they never saw

"1 minute OHLC" is fine for a quick screen of an idea. It is not fine for a final verdict, because it assumes a fixed or modelled spread and hides what happens inside each bar. On gold, one M1 bar can contain the entire move that decides whether your stop or your target is hit first.

Also check the account type. If the EA adds positions in the same direction or hedges, you need a hedging account in the tester. A netting account will merge those positions and give you a different result.

Charge the real costs

Gold's cost per trade is easy to underestimate. Spread is one piece. Slippage on stops, and commission if your account has it, are the others. Swap matters too if trades run overnight. We go deeper on spread in XAUUSD Spread Explained for Beginners, so here is just the effect on a backtest.

Take a spread of $0.30 and an assumed slippage of $0.20 on entry. That is $0.50 of friction per trade, quoted in price.

  • With a $12 stop, $0.50 is about 0.04R per trade.
  • With a $4 stop, the same $0.50 is 0.125R per trade.

Over 100 trades, the first costs roughly 4R and the second roughly 12.5R. Same market, same spread, very different result. This is why tight-stop scalping EAs often look brilliant on low-spread test data and then die live. If your EA has a small average stop, your cost assumption can decide the whole verdict.

A simple rule: run the test twice, once with your normal costs and once with costs about 50% worse. If the strategy only survives the first run, it has no margin for the days spreads widen, like around the 13:30 GMT US data releases or the 19:00 GMT FOMC minutes we saw this week.

A worked XAUUSD example

Let's walk through one trade the way the tester handles it. Account $10,000, risk 1% per trade, so $100 risked.

  1. The EA sells at 3,880.00.
  2. The stop is at 3,892.00, so the stop distance is $12.
  3. Lot size: $100 divided by ($12 x 100 oz) is 0.083 lots. The EA rounds down to 0.08 lots, which is 8 oz.
  4. Actual risk: $12 x 8 oz is $96, or 0.96% of the account. Call that 1R = $96.
  5. Price falls to 3,844.00, where the target sits. That is a $36 move, or 3R gross. Gross profit: $36 x 8 oz is $288.
  6. Costs: $0.50 x 8 oz is $4. Net profit is $284, which is 2.96R.

Two lessons. First, lot rounding means your real R is not exactly 1% of the account, so compare R-multiples rather than dollar profit when you assess the edge. Second, the cost was small on this trade only because the stop was wide. If you want the sizing maths for your own account, the gold lot size calculator does it without the arithmetic.

Read the report in the right order

Most people look at net profit first. Look at it last.

Go in this order:

  1. Number of trades. Under about 100 trades, the profit factor is shaky. Say so in your own notes.
  2. Equity drawdown vs balance drawdown. Balance drawdown only counts closed trades. Equity drawdown includes the open-trade swings, and it is the one a prop firm or your nerves will feel.
  3. Cost per trade in R. As above.
  4. Profit factor and average trade. Useful only after the first three look sane.
  5. Results by year and by month. One great year carrying three flat ones is a warning.

Here is real data from our own model, which is hypothetical backtest output, not live performance. Our R-based test covers July 2022 to September 2026: 146 trades on M15 data with spread and slippage charged on each trade, net +91R, profit factor 2.71, max drawdown 6.3R, longest losing streak 7. The full list is on the performance page.

We also ran the EA in the MT5 Strategy Tester over January to September 2026 on a $10,000 account at 2% risk. Result: +$5,046, profit factor 3.47, max balance drawdown 6.51% and max equity drawdown 9.23%. Notice the gap between the last two. Balance drawdown looked comfortable. Equity drawdown was close to a 10% prop-firm limit. That is exactly the number that gets accounts closed, and it is why that same test at 1% risk is the setting we point prop traders to.

Also notice that nine months is a short window, and its profit factor is higher than the four-year figure. A short window flatters. Do not quote it alone.

Test on data the rules never saw

Optimising an EA on 2022 to 2026 and then admiring the result on 2022 to 2026 proves nothing. The parameters have simply memorised that path.

A cleaner method:

  • Build and tune the rules on an early block. For our model that was 2022 to 2024.
  • Freeze everything.
  • Run the later block, 2025 to 2026, once, and accept what it says.

Then ask whether the result holds in both halves. Gold has had very different phases, from quiet grinding to violent news-driven swings, so a rule set that works in only one phase is fragile. Our methodology page explains how we split the data and what we froze before testing.

One more check that costs nothing: nudge each key input by 20% either way. If profit collapses when a moving-average length goes from 20 to 24, you found a fitted number, not an edge. A real edge degrades gently.

Mistakes that ruin gold backtests

  • Fixed, tiny spread. A flat 10-point spread in the tester when your broker averages much more.
  • Zero latency. Stops fill at exactly the stop price, every time. Live, they do not.
  • Testing only one trending stretch. Gold in a strong run makes almost any buy-the-dip EA look smart.
  • Ignoring news spikes. Check what the EA did around releases such as the 13:30 GMT retail sales print. If it was flat during those minutes in testing but trades them live, your results differ.
  • Judging on dollars, not R. Compounding and lot rounding hide whether the edge is stable.
  • Optimising until the curve is smooth. A very smooth curve from an optimiser is a red flag, not a prize.
  • Skipping a forward test on demo. The tester cannot model your broker's real execution. A few weeks live on a small size or demo shows the gap.

Questions traders ask

Which tick model is best for backtesting gold in MT5?

"Every tick based on real ticks" is the best available, because it replays the broker's actual price path and spread. Use "1 minute OHLC" only for quick screening. If real ticks are not available for your whole period, shorten the test rather than switch to a less accurate model without saying so.

How many years of data do I need?

Aim for three to four years at least, and make sure it includes both calm and volatile stretches. The trade count matters as much as the years: a few dozen trades is too few to trust, however long the period. Our own sample is 146 trades over four years, which is useful but still modest.

Why does my backtest not match live results?

Usually it comes down to spread, slippage and execution speed, which the tester only approximates. Live fills around news can be worse than any test. Run the same EA on a demo or small live account for a few weeks and compare trade by trade. You can see how our own live record compares to the tests on the live results page.

Can I trust a profit factor from a short test?

Treat it with caution. A nine-month test can show a profit factor well above the long-run figure just because the period was friendly. Look at the by-year results and the drawdown, and weight the longer sample more.

Where to go next

If you want to see how a rule-based gold EA is built and tested end to end, the XAUUSD EA for MT5 page shows the settings and the numbers without hiding the losing months.

Trading gold on margin carries a high risk of loss. This article is education, not financial advice.

Tradedge Pulse

Trade the tested model

Live XAUUSD signals, an MT5 indicator and a fully automated MT5 EA, all from one tested rule set.

Trading involves substantial risk. This is educational content, not financial advice. See the risk disclosure.

Fuzail Naqash
Written by Tradedge Pulse

Published by Tradedge Pulse, a gold trading research site founded by Fuzail Naqash. We test trading ideas on years of XAUUSD data before we write about them.

About Fuzail Naqash →

Next steps

Keep reading