How to Backtest a Gold Strategy Honestly (XAUUSD, Real Test)
How do you backtest a gold (XAUUSD) strategy honestly? This advanced lesson explains, in simple words and on real data, what a backtest and a forward test are and why most backtests are wrong; how to write rules a computer could follow (entry, stop, target, filters, time); the limits of free data (futures vs spot, short intraday history, contract rolls, missing candles); costs (spread, commission, slippage, swap) and why they flip thin results; the numbers that matter, measured in R (number of trades, expectancy, profit factor, max drawdown, longest losing streak); the traps (look-ahead bias, overfitting, small samples, cherry-picking); the in-sample / out-of-sample split; forward testing on demo for a set number of trades; manual chart replay and a journal template. It runs one real backtest in code, with costs, shows its equity curve and drawdown, and an overfit version that looked great in-sample and failed on new data.
Chapters
- 0:00An overfit strategy fails on new data
- 0:44What a backtest is, and why most are wrong
- 1:23Write rules a computer could follow
- 2:24Free data and its limits (futures, rolls, missing candles)
- 3:39Costs: spread, commission, slippage, swap
- 4:44The numbers that matter (R, expectancy, profit factor, drawdown)
- 5:42A real equity curve and drawdown
- 6:41The traps: look-ahead, overfitting, small samples, cherry-picking
- 7:55In-sample, out-of-sample and forward testing
- 8:56Manual chart replay and a journal template
- 9:42Is your strategy ready? (flowchart)
- 10:16Recap
Key points
Write rules a computer could follow: entry, stop, target, filters and time; anything vague cannot be tested.
Free data has limits (futures vs spot, contract rolls, missing candles, short intraday history); find and drop bad data openly.
Always include costs (spread, commission, slippage); thin results can turn negative after costs.
Measure in R: number of trades, expectancy, profit factor, max drawdown and longest losing streak; small samples prove little.
Overfitting is the big trap: the best of 47,970 versions looked great on old data and lost on new data. Check new data, then forward test on demo; a good backtest does not guarantee future results.
Chart data: COMEX gold futures OHLC from Yahoo Finance (GC=F), times in UTC. Education only, not a signal.
Read more: How to Backtest and Forward-Test a Gold (XAUUSD) Trading Strategy · Trading Math for Gold Traders: R-Multiples, Expectancy, Drawdowns and Position Sizing · Backtest · Forward test · Curve fitting · Expectancy · Equity curve
Transcript
This line is a gold strategy we built by testing 47,970 versions of one rule, and keeping the best. Over 16 months it made 20.3R. It looked like a winner. Then we ran it on the next ten months, data it had never seen. It lost 7.2R. Only 2 of its 15 trades reached the target. The simple rule it came from, with no tuning at all, kept making money in those same months. This is the lesson on backtesting. You'll learn how to write rules a computer could follow, the limits of free data, costs, the numbers that matter, the traps, in-sample and out-of-sample, forward testing, and a real test, start to finish.
Chapter one. What a backtest is, and why most are wrong. A backtest means running fixed rules over past prices, trade by trade, to see what would have happened. A forward test runs the same rules on new prices, on demo, without changing them. The goal is not to find a money machine. It's to throw out bad ideas cheaply, and to learn how a good idea feels: how often it loses, and how deep the losing runs get. Most backtests are wrong for the same few reasons. Vague rules. Bad data. No costs. Too few trades. And testing until it works. We'll go through each one.
Chapter two. Write rules a computer could follow. "Buy at good structure" can't be tested. Two people would take different trades. So every part needs a number: the entry, the stop, the target, the filters, and the time. Here's the rule we'll test, from the market structure lesson. Swings use the 5-candle rule, and a swing only counts once two more candles have closed. When a one hour candle closes beyond structure, a BOS or a change of character, place a limit order at the broken level. It waits 12 candles, then it's cancelled. The stop goes 3 points beyond the strong high or low. The target is 2R. One trade at a time, and if one candle touches both the stop and the target, we count the stop. Here's one real trade from the test. 24 July 2025. A BOS down, a sell limit at the broken low, and the next day, the 2R target. A computer would take exactly this trade, every time.
Chapter three. Free data, and its limits. We use free data: COMEX gold futures from Yahoo. Futures trade a little above spot gold, and your platform's feed will differ too, so wicks and stops won't match exactly. Free intraday history is short. One hour candles only go back to June 2024 here. Five minute candles: just the last 66 days. That's very little history. Futures also switch contracts. On 25 November 2025, this file mixed two contracts. The price jumped about 37 points back and forth, 6 times in one day. None of those moves were real. And candles go missing. On 30 January 2026, in the middle of a crash, 26 trading hours are simply gone. The daily low was 4,423.2, more than 230 points below anything this one hour file shows. A stop there would never be hit in the test. So check your data before you trust any result. We dropped every trade that touched a bad jump: 32 trades. With them kept, the test looked better: 30.9R instead of 22.6. Bad data made fake winners.
Chapter four. Costs, and why they flip results. Every trade pays the spread and often a commission. Fast markets add slippage: you get filled worse than your price. And holding past the daily close on a CFD account costs swap. We charge 0.50 per ounce on every trade: 0.30 for spread and commission, plus 0.20 for slippage. We didn't model swap, but 104 of our trades were held overnight, so a real account would pay more. On the one hour test, stops averaged 50 points, so costs took only 2.4R in total. Costs would need to be about 11 times higher to wipe the result out. Small stops are different. With a 3-point scalping stop, 0.50 is already 0.17R on every trade. A small edge of plus 0.1R before costs becomes minus 0.07R after. The cost was bigger than the edge. The same rule on five minute candles lost 7R before costs, and 10.6R after. A rule that's thin before costs dies after them.
Chapter five. The numbers that matter. Measure every trade in R: the result divided by the risk. Risk 20 dollars and make 40, that's plus 2R. Then you can compare any trade, at any price. Here's our test, after costs. 146 trades. 57 reached 2R, 89 were stopped. The total: 22.6R. Average R per trade, called expectancy: plus 0.15R. That's the core number. It says what one trade was worth, on average. Profit factor: total won divided by total lost. 1.25. Above 1 means it made money in this sample. Max drawdown: the deepest drop from a high point, 9.3R. And the longest losing streak: 8 in a row. Ask yourself honestly: could you keep following the rules through that?
Chapter six. The equity curve and the drawdown. Here's the test as a picture. Gold on top. Under it, the equity curve: the running total in R, after every trade. It doesn't go straight up. It climbs, stalls for months, and drops. Under it, the drawdown: how far it sat below its last high. The deepest point came in August 2026. Now be honest about what this shows. Most of the R came from buys, 17.6R, while gold rose from about 2,523 to 3,886. Sells made only 5.1R. So part of this result is simply gold's big rise. And look at the settings around it. With a 1R target, the same rule lost 0.7R. With 1.5R, it lost 3R. With 2.5R, it made only 1.8R. A strong idea should still work when a setting moves a little. This one swings a lot.
Chapter seven. The traps. Trap one: look-ahead. Using something the market didn't know yet. A swing high is only known two candles later. Mark it on the candle itself, and your test trades on the future. Trap two: overfitting. Too many rules, or testing until it works. We tried 47,970 versions: targets, stops, hours, weekdays and direction. The best one: a 3R target, a 1-point buffer, three hour blocks, only Wednesday to Friday. In-sample: 31 trades and 20.3R. Out-of-sample: 15 trades and minus 7.2R. It didn't find an edge. It found the noise of 16 months: which hours and days happened to win. That noise never repeats. Trap three: small samples. Under 30 trades is a story, not proof. Aim for 100 to 300, across quiet and wild markets. Trap four: cherry-picking. Testing only the months you know worked, or logging only the clean trades you remember. Pick the period first, and log every trade the rules take.
Chapter eight. In-sample, out-of-sample, and the forward test. Before you test, split the data. The older part, in-sample, is where you build the rule. The newest part, out-of-sample, stays locked. We split our data at 1 January 2026: 96 trades and 13.1R before, 50 trades and 9.5R after. We checked 1 September and 1 November 2025 too. Both halves stayed positive every time. The overfit version didn't. If the out-of-sample test fails, don't tune and run it again. Then it's in-sample too. Go back to a new idea. Then forward test. Run the frozen rules on a demo account for a set number of trades, say 50. Same rules, no changes, every trade logged. Expect it to be a bit worse than the backtest. And remember: a good backtest does not guarantee future results. It only shows the rules worked on that data, with those costs.
Chapter nine. Manual replay, and your journal. Can't code? Use chart replay. Pick a start date at random, hide the future candles, and move forward one candle at a time. Log each trade before you move on. Never peek ahead, and never skip an ugly setup that fits the rules. Your journal needs the same columns for backtest, forward test and live: date and time, direction, entry, stop, target, exit, result in R, costs, a screenshot, and one question. Did I follow the rules? Then add up the same numbers: trades, expectancy, profit factor, drawdown and the longest losing streak. Now your live trading can be compared with your test.
Chapter ten. Is your strategy ready for real money? Are the rules written so a computer could follow them? If not, write them first. Are costs included, and does the data have no holes or jumps? If not, test again. At least 100 trades, and do nearby settings still work? If not, keep testing. Did the out-of-sample test hold up? If not, start with a new idea. If yes, forward test 50 trades on demo. Close to the backtest? Then start live with small size.
Let's recap. Write rules a computer could follow, and check your data for rolls, holes and gaps. Include costs. Judge the test by trades, expectancy, profit factor, drawdown and losing streaks, measured in R. Avoid look-ahead, overfitting, small samples and cherry-picking. Lock an out-of-sample period, then forward test on demo before any real money. The full written guide is on xauusdglobal.com. Subscribe for the next lesson, and come trade with us in the XAUUSD Global community. It's free during early access.
Other short videos

Trading Maths for Gold: Why a 70% Win Rate Can Still Lose

Dollar and Yields: What Really Moves Gold (DXY, Real Yields, XAUUSD)

Elliott Wave on Gold: 3 Rules, Fibonacci Targets, Real XAUUSD Trades
