barehands

barehands › Guides · Đọc bằng tiếng Việt

How to backtest gold (XAUUSD) after trading costs

Updated 24 Nov 2026 · numbers measured by us, method in the article

Short answer: Subtract three things or the result is fiction: the cost per trade (spread + commission), slippage, and overnight swap for positions still open at 17:00 New York time. Measure the result as average R per trade after costs (R = multiples of the risk), over hundreds of trades and several years of data, then re-check it on data you did not use to choose the parameters.

Example: Donchian breakout on gold H4

Rules: go long when the close breaks above the 20-candle high, short when it breaks below the 20-candle low; only trade in the direction of EMA200. Exit at a 1 × ATR14 stop loss, a 2R take profit, or when the close breaks the opposite 10-candle channel. Data: MetaTrader 5 (Exness), H4, from 16 Nov 2022 to 05 Dec 2026, re-run by the server at 07:19, 05 Dec 2026 (Vietnam time).

CostsTradesWin rateAvg per tradeTotal
No costs28741%+0.24R+68.0R
Real Exness costs28741%+0.23R+65.2R
Costs + overnight swap28741%+0.21R+60.2R

Measured cost of gold on Exness: about 0.0053% of price per round trip, roughly $0.20 for 0.01 lot at $3,794.61. Swap: long −0.0124%, short +0.0000% of price per night (negative means you pay), triple swap on Wednesday. Split into halves: first half +0.00R per trade, second half +0.38R. Maximum drawdown 15.3R. 95% confidence interval of the average: +0.04R to +0.38R.

20/10 is a common default, but gold H4 was chosen as the example after seeing gold's strong 2024–2026 trend. Over the full history since 2017, almost all of the profit comes from the recent period. If gold goes sideways, this edge can disappear.

How to backtest gold properly

  1. Enough data. Several years, with up, down and sideways markets. Watch out: Exness MT5 "H1" data before about December 2020 is really daily candles labelled H1; using it breaks the backtest without any error.
  2. Clear entry and exit rules, no look-ahead. Use closed candles only. If one candle touches both the stop and the target, count the stop first (the pessimistic assumption), because you cannot know which was hit first.
  3. Subtract real costs, in R. Costs are a percentage of price; divide by the stop distance to get R. The tighter the stop, the more R the same cost eats (see scalping after fees).
  4. Subtract swap. Gold H4 trades are often held for days, and gold's long swap is usually negative. In the example above, swap alone took 5.0R over 287 trades, while trading costs took 2.8R.
  5. Read the right numbers. Average R per trade after costs and its confidence interval matter more than the win rate (see win rate vs risk:reward). Also check the maximum drawdown and the longest losing streak.
  6. Don't fool yourself. Split the data in two and check both halves have the same sign; optimise on the first 70% and test on the last 30%; compare against random entries with the same number of trades; shuffle the trade order (Monte Carlo) to see how bad the drawdown can get.

Run it now, no account needed

🎬 Practice on past candles📊 Open the backtest tool

Frequently asked questions

How are trading costs for gold included in a backtest?

Take the spread plus the round-trip commission, express it as a percentage of price and subtract it from every trade. Divide it by the stop distance to see how many R each trade loses to costs. Add slippage if you enter during fast markets.

How does swap affect a gold backtest?

Every night a position is still open at 17:00 New York time, a percentage of price is charged (or paid); one weekday counts three nights. For strategies that hold gold for days, swap can take several R per hundred trades.

How many trades does a backtest need?

As many as possible. With a 2R target each trade ends near +2R or −1R, so the standard deviation is about 1.4–1.5R; 100 trades give a confidence interval about ±0.3R wide around the average. Telling +0.1R apart from zero takes several hundred to a thousand trades.

Does a good backtest mean the strategy will make money?

No. Parameters chosen after looking at the data always look better than reality. Test out of sample, compare with random entries, and forward-test on a demo account first.

Read more

For analysis and learning only, not investment advice. Past results do not guarantee future results. Numbers are measured by barehands on MetaTrader 5 (Exness) and Binance data; the method is in each article and on the About & methodology page.