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
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).
| Costs | Trades | Win rate | Avg per trade | Total |
|---|---|---|---|---|
| No costs | 287 | 41% | +0.24R | +68.0R |
| Real Exness costs | 287 | 41% | +0.23R | +65.2R |
| Costs + overnight swap | 287 | 41% | +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
- 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.
- 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.
- 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).
- 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.
- 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.
- 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
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
- Can a $200 account trade gold within a 2% risk rule?
- Is scalping on M15 profitable after fees?
- What win rate do you need to be profitable?
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.