Risk & process

How to Backtest a Gold Strategy: One Real Test, Every Trade Shown

A backtest tells you whether a gold rule deserves real money, but only if the test is run straight. This is Level 2, lesson 16: one small test run start to finish on our hourly gold data, with the rule, the costs and every trade shown, the result as it came out, and then four ways the very same test could have fooled you.

Level 2 · IntermediateLesson 16 of 31Risk & process

Short answer: To backtest a gold strategy, write the rule so exactly that two people would take the same trades, run it candle by candle over past XAUUSD data, fill orders only at prices that existed after the signal, subtract realistic costs, and list every trade. Judge it by expectancy, profit factor, drawdown and the number of trades, and compare it with a yardstick such as random entries or holding gold. Keep a later stretch of data aside and test it only once. We ran one small test this way on our hourly data: 69 trades, a win rate exactly on its break-even line, and −0.27R after costs. Then the same data, tested carelessly, produced a 67% win rate and +17.86R. The careless version is the one people post.

Two results from the same candles

Here are two results. Both come from the same hourly gold candles, August to November 2026. Both test the same idea, a breakout of the last day’s range. Every trade in both really is on the chart.

Result A Result B
Trades 69 18
Win rate 33.3% 66.7%
Profit factor 0.97 3.84
Total after costs −0.27R +17.86R

Result A is the test run properly. Result B is the same test after two small decisions were made with the answer already in view. This lesson builds A step by step, lists every trade in it, and then shows exactly how B was made, because B is the kind of result that gets posted and A is the kind you usually get.

Two words first. Backtesting means running a fixed rule over past prices. Forward testing means running the same rule, unchanged, on new prices as they arrive, on a demo account or at the smallest real size. The backtest is cheap and fast. The forward test is slow, and much harder to cheat on.

A backtest does three jobs. It throws out bad ideas cheaply. It tells you what normal looks like for a rule: how often it loses, how long the losing runs are, how deep the drawdowns go. And it gives you a baseline, so that when live results come in you can tell “a normal bad month” from “this has stopped working”.

It does not prove that a rule will work. It shows how the rule behaved on one stretch of data under one set of assumptions. Every way that can go wrong is in this lesson, shown on the same test.

A rule a stranger could follow

A backtest can only test a rule. “Buy pullbacks to good support” cannot be tested, because two traders will disagree about which pullbacks and which supports. The first job is to write every decision down so exactly that a stranger, or a computer, would take the same trades as you.

Here is the rule we tested. The idea in one sentence: when gold closes beyond its range of the last day, go with it.

  1. Data: COMEX gold futures (GC=F) hourly candles from the site’s own file, times in UTC, with the flat one-price pause candles of the daily break left out. Signals from 3 August to 23 November 2026. One futures contract covers the whole stretch, so no contract switch distorts it.
  2. Signal: a candle closes above the highest high of the 24 candles before it (buy), or below their lowest low (sell).
  3. Entry: at the open of the next candle. Never at the signal candle’s close, because by the time you know the close, that price has gone.
  4. Stop: 1.5 times the average true range (ATR, 14 candles) of the signal candle, away from the entry.
  5. Target: twice the stop distance (2R).
  6. Exit: whichever of stop or target is touched first, checked candle by candle. If one candle touches both, it counts as a stop, because the candle cannot tell us which came first. If a candle opens beyond the stop (a gap), the fill is that open, not the stop price.
  7. One trade at a time: new signals are ignored while a trade is open. A trade still open at the end of the data is closed at the last close.
  8. Costs: $0.30 an ounce for each round trip, subtracted from every trade. That is an assumption, roughly a normal spread plus a little slippage; your own cost may be higher.
  9. Results: in R (1R = the stop distance) and in dollars per ounce, one ounce per trade.

Every one of those lines is a decision you would otherwise make by feel, and every one of them changes the result. Write them before you look at any results, and do not change them afterwards to fix a trade you do not like.

The test: 69 trades, August to November 2026

Here is what the rule did, exactly as the script produced it.

  • Trades: 69 (30 buys, 39 sells).
  • Winners: 23, all at the target. Losers: 45 at the stop, plus 1 still open on 23 November and closed at the last price (−0.56R).
  • Win rate: 33.3%. The break-even win rate for a 2R target is also 33.3%.
  • Net result: −0.27R, or −$40.73 an ounce, after costs. Expectancy about −0.004R a trade.
  • Profit factor (gross profit ÷ gross loss): 0.97.
  • Worst drawdown: 13.28R. Longest losing run: 9 trades.
  • Typical risk: stops from $17.44 to $43.41 an ounce, median $27.27.

Said plainly, the rule found nothing. Its win rate landed on the break-even line, and costs pushed it just below zero. This is Result A from the top of the lesson. Sixteen weeks that included gold’s August rally to 4,755.0 and its fall to 3,651.4 on 23 November did not give a 24-hour breakout an edge.

That is a perfectly good backtest result. It cost one script and an afternoon, and it says “do not risk money on this as it stands”. Sixty-nine trades in one sixteen-week window is a small sample, so it does not say the idea can never work. It says this test gives you no reason to think it does.

Two numbers deserve a second look. The test lost 9 times in a row at one point and fell 13.28R from its best: if you had traded it at 1% a trade, you would have been down about 12.5% in the middle of a method that, over the whole stretch, broke even. And the R total and the dollar total do not move together: the losses happened to fall more often on trades with wider stops, so the dollar result is worse than the R result. Judge in R; it is the fairer unit.

Two days of the test, candle by candle

A results list hides what the rule actually did, so step through a piece of it. These are the six trades it took on 18 and 19 November, when gold fell about $300. Each dot on the chart is one entry candle.

Real gold: six trades of the breakout test in two days, 18 and 19 November 20263,893.43,826.43,759.33,692.33,625.33,558.33,491.2+2R-1R same hour-1R-1R+2R-1R (Monday)REAL DATA · COMEX GOLD FUTURES (GC=F) · 1-HOUR CANDLES · TIMES UTC
Real gold: six trades of the breakout test in two days, 18 and 19 November 2026. COMEX gold futures (GC=F) 1-hour candles, 22:00 UTC on 17 Nov to 03:00 UTC on 20 Nov 2026. Each dot is the entry candle of one trade from the lesson's test (sell at the next open after a close below the lowest low of the previous 24 candles, stop 1.5 ATR, target 2R). Two reached their targets and four were stopped, one of them inside its own entry candle; the last one was stopped on the Monday after the weekend. Gold fell about $300 across these two days and the six trades together came to -0.06R.
  1. 18 November, 00:00 signal. The candle closed below the lowest low of the previous 24, so the rule sold the next open at 3,816.9. The target was reached at 08:00: +1.99R after costs.
  2. 18 November, 12:00 signal. Another close below the 24-hour low, at 3,745.4. The sell filled at the 13:00 open, 3,745.5, with the stop at 3,771.8. That 13:00 candle is the one lesson 14 used as a liquidity sweep: it shot up to 3,792.9 inside the hour. The trade was stopped in its own entry candle: −1.01R.
  3. 18 November, 19:00 signal. Sold 3,724.9; stopped just after midnight. −1.01R.
  4. 19 November, 02:00 signal. Sold 3,710.0; stopped two hours later. −1.01R.
  5. 19 November, 15:00 signal. Sold 3,674.3; target at 23:00. +1.99R.
  6. 20 November, 01:00 signal. Sold 3,560.9 with the stop at 3,599.5. Friday’s low was 3,502.9, not quite the target. Gold reopened on Sunday at 3,568.0, below the stop, and the 01:00 candle on Monday traded up to 3,629.6, through it. −1.01R.

Gold fell about $300 across these days. All six trades were sells, the right side, and together they came to −0.06R. Stay with that for a moment. A rule can be on the right side of a big move and still make nothing, because it keeps entering after the move has already run and keeps getting stopped by the bounces. You would never see that in a summary line. You see it by stepping through the trades.

Every trade, listed

The short version first, month by month.

Month of the signal Trades Winners Result after costs
August (from the 3rd) 17 8 +6.83R
September 17 3 −8.17R
October 18 6 −0.21R
November (to the 23rd) 17 6 +1.28R
Whole test 69 23 −0.27R

August made +6.83R and September took −8.17R back. A trader who had tested only August would think he had a strategy. One who had tested only September would have binned the idea in disgust. Neither would have learned anything. The four months together say: nothing here.

Below are all 69 trades, so that you can check any of them against your own chart. Times are UTC, prices are COMEX gold futures, and R is after the $0.30 cost. The table is wide: on a phone, slide it sideways inside its own frame.

# Signal candle Side Entry Stop Target Exit Exit price R
1 4 Aug 11:00 Buy 4,132.3 4,110.5 4,175.8 5 Aug 02:00, target 4,175.8 +1.99
2 5 Aug 05:00 Buy 4,222.3 4,195.4 4,276.2 5 Aug 14:00, target 4,276.2 +1.99
3 5 Aug 23:00 Buy 4,337.2 4,306.8 4,398.0 6 Aug 05:00, stop 4,306.8 −1.01
4 7 Aug 06:00 Buy 4,356.2 4,327.9 4,412.8 7 Aug 12:00, target 4,412.8 +1.99
5 10 Aug 18:00 Buy 4,438.4 4,411.6 4,492.1 11 Aug 01:00, target 4,492.1 +1.99
6 12 Aug 12:00 Buy 4,497.8 4,469.8 4,553.8 12 Aug 13:00, stop 4,469.8 −1.01
7 13 Aug 19:00 Sell 4,406.0 4,435.0 4,348.1 14 Aug 12:00, stop 4,435.0 −1.01
8 17 Aug 00:00 Buy 4,457.1 4,432.9 4,505.5 18 Aug 13:00, stop 4,432.9 −1.01
9 18 Aug 14:00 Sell 4,422.9 4,448.1 4,372.4 19 Aug 12:00, stop 4,448.1 −1.01
10 19 Aug 13:00 Buy 4,517.6 4,486.0 4,580.7 19 Aug 20:00, target 4,580.7 +1.99
11 21 Aug 05:00 Buy 4,609.8 4,581.1 4,667.2 21 Aug 15:00, target 4,667.2 +1.99
12 21 Aug 16:00 Buy 4,686.7 4,654.8 4,750.5 24 Aug 00:00, stop 4,654.8 −1.01
13 24 Aug 02:00 Buy 4,700.4 4,666.8 4,767.7 25 Aug 13:00, stop 4,666.8 −1.01
14 26 Aug 15:00 Sell 4,651.6 4,680.9 4,592.9 27 Aug 00:00, stop 4,680.9 −1.01
15 27 Aug 09:00 Sell 4,632.9 4,660.0 4,578.7 27 Aug 15:00, stop 4,660.0 −1.01
16 28 Aug 15:00 Sell 4,575.9 4,616.1 4,495.5 28 Aug 18:00, target 4,495.5 +1.99
17 31 Aug 02:00 Sell 4,472.7 4,516.1 4,385.9 1 Sep 13:00, target 4,385.9 +1.99
18 2 Sep 00:00 Sell 4,361.6 4,389.4 4,305.9 2 Sep 12:00, stop 4,389.4 −1.01
19 2 Sep 13:00 Buy 4,432.9 4,400.9 4,496.9 3 Sep 12:00, target 4,496.9 +1.99
20 4 Sep 12:00 Sell 4,440.9 4,473.3 4,376.1 4 Sep 13:00, stop 4,473.3 −1.01
21 8 Sep 20:00 Sell 4,399.0 4,430.5 4,336.0 9 Sep 05:00, stop 4,430.5 −1.01
22 10 Sep 11:00 Sell 4,416.8 4,444.1 4,362.3 10 Sep 19:00, target 4,362.3 +1.99
23 11 Sep 03:00 Sell 4,344.2 4,373.8 4,284.9 11 Sep 04:00, stop 4,373.8 −1.01
24 11 Sep 13:00 Buy 4,443.7 4,407.4 4,516.4 11 Sep 14:00, stop 4,407.4 −1.01
25 14 Sep 09:00 Sell 4,324.8 4,356.2 4,262.1 14 Sep 16:00, stop 4,356.2 −1.01
26 16 Sep 02:00 Buy 4,362.3 4,336.8 4,413.2 16 Sep 18:00, stop 4,336.8 −1.01
27 17 Sep 12:00 Buy 4,413.8 4,377.6 4,486.2 18 Sep 03:00, stop 4,377.6 −1.01
28 18 Sep 06:00 Buy 4,433.2 4,404.9 4,489.9 18 Sep 12:00, stop 4,404.9 −1.01
29 21 Sep 14:00 Sell 4,377.1 4,403.8 4,323.7 21 Sep 23:00, stop 4,403.8 −1.01
30 22 Sep 07:00 Sell 4,337.2 4,362.7 4,286.1 22 Sep 08:00, stop 4,362.7 −1.01
31 23 Sep 13:00 Sell 4,320.1 4,344.3 4,271.8 25 Sep 10:00, stop 4,344.3 −1.01
32 28 Sep 00:00 Sell 4,264.4 4,291.2 4,210.8 28 Sep 06:00, target 4,210.8 +1.99
33 28 Sep 07:00 Sell 4,187.4 4,213.8 4,134.6 29 Sep 20:00, stop 4,213.8 −1.01
34 30 Sep 06:00 Buy 4,222.6 4,200.9 4,265.9 30 Sep 14:00, stop 4,200.9 −1.01
35 1 Oct 00:00 Sell 4,175.5 4,196.4 4,133.7 1 Oct 03:00, stop 4,196.4 −1.01
36 2 Oct 12:00 Buy 4,248.4 4,220.6 4,304.1 2 Oct 13:00, stop 4,220.6 −1.01
37 2 Oct 15:00 Sell 4,156.2 4,190.9 4,086.7 5 Oct 02:00, stop 4,190.9 −1.01
38 6 Oct 11:00 Buy 4,201.7 4,178.8 4,247.5 6 Oct 14:00, stop 4,178.8 −1.01
39 7 Oct 08:00 Sell 4,149.7 4,168.2 4,112.7 7 Oct 12:00, target 4,112.7 +1.98
40 9 Oct 01:00 Buy 4,199.7 4,176.9 4,245.2 13 Oct 01:00, stop 4,176.9 −1.01
41 13 Oct 17:00 Sell 4,171.6 4,189.0 4,136.7 13 Oct 19:00, stop 4,189.0 −1.02
42 14 Oct 10:00 Sell 4,163.4 4,180.9 4,128.4 14 Oct 12:00, target 4,128.4 +1.98
43 15 Oct 19:00 Buy 4,195.9 4,171.7 4,244.2 16 Oct 01:00, stop 4,171.7 −1.01
44 16 Oct 03:00 Buy 4,205.0 4,181.7 4,251.6 16 Oct 13:00, stop 4,181.7 −1.01
45 19 Oct 15:00 Sell 4,161.1 4,182.6 4,118.1 22 Oct 03:00, target 4,118.1 +1.99
46 22 Oct 11:00 Sell 4,074.7 4,098.1 4,028.0 22 Oct 12:00, stop 4,098.1 −1.01
47 22 Oct 13:00 Sell 4,071.6 4,098.8 4,017.2 23 Oct 01:00, target 4,017.2 +1.99
48 27 Oct 14:00 Buy 4,066.5 4,044.5 4,110.4 28 Oct 05:00, stop 4,044.5 −1.01
49 28 Oct 19:00 Buy 4,089.1 4,065.5 4,136.3 28 Oct 22:00, stop 4,065.5 −1.01
50 29 Oct 05:00 Sell 4,036.1 4,062.2 3,984.0 30 Oct 07:00, target 3,984.0 +1.99
51 30 Oct 12:00 Sell 3,963.6 3,988.8 3,913.1 30 Oct 14:00, target 3,913.1 +1.99
52 30 Oct 17:00 Sell 3,893.0 3,921.7 3,835.6 2 Nov 01:00, stop 3,921.7 −1.01
53 2 Nov 16:00 Buy 3,977.9 3,951.1 4,031.5 2 Nov 19:00, stop 3,951.1 −1.01
54 4 Nov 05:00 Buy 4,008.5 3,977.2 4,071.1 4 Nov 16:00, target 4,071.1 +1.99
55 5 Nov 00:00 Buy 4,098.1 4,071.2 4,151.9 5 Nov 03:00, target 4,151.9 +1.99
56 6 Nov 01:00 Sell 4,068.2 4,103.3 3,998.0 9 Nov 00:00, stop 4,103.3 −1.01
57 9 Nov 01:00 Buy 4,132.7 4,101.5 4,195.1 9 Nov 07:00, stop 4,101.5 −1.01
58 9 Nov 19:00 Buy 4,145.4 4,115.4 4,205.3 10 Nov 09:00, stop 4,115.4 −1.01
59 10 Nov 13:00 Sell 4,059.7 4,086.6 4,006.0 11 Nov 16:00, target 4,006.0 +1.99
60 11 Nov 17:00 Sell 4,000.4 4,021.7 3,957.7 12 Nov 08:00, target 3,957.7 +1.99
61 12 Nov 13:00 Sell 3,894.7 3,923.8 3,836.4 13 Nov 03:00, stop 3,923.8 −1.01
62 16 Nov 05:00 Sell 3,840.0 3,868.7 3,782.7 16 Nov 09:00, stop 3,868.7 −1.01
63 18 Nov 00:00 Sell 3,816.9 3,842.2 3,766.2 18 Nov 08:00, target 3,766.2 +1.99
64 18 Nov 12:00 Sell 3,745.5 3,771.8 3,692.8 18 Nov 13:00, stop 3,771.8 −1.01
65 18 Nov 19:00 Sell 3,724.9 3,754.1 3,666.5 19 Nov 00:00, stop 3,754.1 −1.01
66 19 Nov 02:00 Sell 3,710.0 3,741.2 3,647.6 19 Nov 05:00, stop 3,741.2 −1.01
67 19 Nov 15:00 Sell 3,674.3 3,703.3 3,616.4 19 Nov 23:00, target 3,616.4 +1.99
68 20 Nov 01:00 Sell 3,560.9 3,599.5 3,483.7 23 Nov 01:00, stop 3,599.5 −1.01
69 23 Nov 13:00 Buy 3,655.2 3,617.5 3,730.5 23 Nov 21:00, still open, last close 3,634.4 −0.56

Four ways the same test can fool you

Result A is dull and true. Here is how the very same data, handled carelessly, turns into Result B and its cousins.

Leave the costs out

Run the same 69 trades with no costs and the total becomes +0.45R. A losing rule turns into a winning one on paper. Double the cost to $0.60 and it falls to −1.05R.

On this hourly test the cost is a small share of each trade, because the stops are around $27. On faster charts it decides everything. In the words of our strategies tested hub: “A $0.30 round trip is about 16% of the average 1-minute bar during London and New York hours, 6% of a 5-minute bar, 3.5% of a 15-minute bar and under 2% of an hourly bar.” A backtest without costs is not a cautious estimate; it is a different strategy that nobody can trade.

Put hindsight into the rule

We know, now, that gold fell from late August to late November. So suppose we “improve” the rule by only taking sells. Same data, same everything else: 41 trades, 14 winners, +0.55R. Better, but still nothing.

Now combine that with a little tuning. Among the settings we tried (next section), the best sell-only version used a 24-candle signal, a 3-ATR stop and a 2R target: 18 trades, 12 winners, a 66.7% win rate, a profit factor of 3.84, +17.86R, +$992.72 an ounce. That is Result B.

Nothing in that result is fake. Every trade really happened on the chart. It is still worthless, because the two most important decisions in it, “only sell” and “these exact settings”, were made by looking at the answer first. That is hindsight, and a rule built on it has been tested on nothing. The test against it is simple: could you have written the rule, word for word, before the data you tested it on?

Believe a small number of trades

That 66.7% win rate came from 18 trades. Put it through the margin formula from lesson 15, 2 × √(p × (1 − p) ÷ n), and 18 trades give about ±22 percentage points. The “true” win rate of that rule could be anything from about 45% to almost 90%, and that is before the hindsight problem. Even our 69-trade result carries a margin of about ±11 points around its 33.3%.

Sample size and win-rate uncertaintyFour horizontal bars showing the 95 percent range of observed win rate for a true 50 percent strategy at 20, 50, 100 and 300 trades.A coin-flip strategy (true win rate 50%): the range its backtest can show20%30%40%50%60%70%80%20 trades±22 pts50 trades±14 pts100 trades±10 pts300 trades±6 ptsAbout 95% of backtests of a no-edge, 50% strategy land inside each bar (binomial maths).
Why 20 trades prove nothing. Maths, not market data. With no edge at all, a 20-trade test can show anything from about 28% to 72% winners. At 100 trades the range is still ±10 points, and at 300 about ±6. That is why this lesson asks for 100 to 300 trades before you trust a win rate.

The trading math lesson showed the same thing from the other side: in a simulation of a method with a genuine edge, one run in four was still losing after twenty trades. A short test cannot tell skill from luck in either direction. By that lesson’s rough bands, Result B’s 18 trades are an anecdote, and even the 69 trades of the full test are only early evidence.

Tune the settings until the past looks good

The rule has three settings: the lookback (24 candles), the stop (1.5 ATR) and the target (2R). We tried every combination of five lookbacks (6, 12, 24, 48, 72), four stops (1, 1.5, 2, 3 ATR) and four targets (1, 1.5, 2, 3R): 80 settings. Each was tuned on August and September 2026 (in-sample) and then run on October to 23 November (out-of-sample).

  • 55 of the 80 settings made money in-sample. Our original setting was not one of them.
  • The best in-sample setting (12 candles, 1 ATR, 3R) made +17.07R on 54 trades. Out-of-sample it made +10.13R on 51 trades.
  • The second best (6 candles, 1 ATR, 3R) made +12.67R in-sample and −5.34R out-of-sample. The sixth best (12 candles, 3 ATR, 1.5R): +9.35R in, −4.14R out.
  • Of the 55 in-sample winners, 37 also made money out-of-sample.

So the best setting held up out-of-sample. That is how it came out, and we report it as it came out. It still proves little, for three reasons.

  • The second period was the same kind of market. In August and September gold ran from 4,074.0 up to 4,755.0 and most of the way back. From October to 23 November it fell from 4,259.0 to 3,502.9. Both periods were made of long one-way runs, which is what a breakout rule lives on. Sixteen weeks held no quiet stretch to test it against.
  • Its neighbours disagree. Over the whole window, 12 candles, 1 ATR and 3R made +27.2R. Change only the target to 2R and the same rule made +0.6R. Change only the stop to 1.5 ATR: +9.62R. Change only the lookback to 24 candles: +10.66R. A result that falls from +27R to under +1R when one setting moves one step is a peak, not a plateau.
  • It was the best of 80 tries. The next section shows how often luck alone produces a number like that.
Parameter sweep in-sample and out-of-samplePaired bars of profit factor for entry lookbacks from 10 to 100 days, in-sample 2005-2018 and out-of-sample 2019-2026, with trade counts.Same rule, ten settings: profit factor in-sample (blue) and out-of-sample (gold)01234561095/532052/323035/224026/145026/116022/11off7017/10off8014/9off9013/8off10011/7Entry lookback in days (exit = half). Second row = trades in-sample / out-of-sample.
Real test: why the 'best setting' is a trap. Real data, same rule with entry lookbacks of 10 to 100 days. In-sample (2005-2018) the best profit factor was 2.30 at 100 days, from only 11 trades; the worst was 1.11. Out-of-sample the slow settings look brilliant on 7 to 14 trades, simply because gold trended hard. Bars marked 'off' run above the scale. Small samples make any setting look like genius or failure.

The same trap appears on our long daily test further down, where the best lookback rested on only 11 trades.

A yardstick made of coin flips

How do you know whether +27.2R, or −0.27R, is good? Compare it with a rule that has no idea at all.

What follows is a simulation, not a record of trades anyone could have taken. Its rule: on each hourly candle from 3 August, a 6% chance of entering at the next open, direction chosen by a coin flip, then exactly the same stop, target, cost and one-trade-at-a-time rules as the test. 1,000 runs, Python’s random number generator with seeds 0 to 999.

  • With our base settings (1.5 ATR, 2R), the random runs finished with a median of −3.78R, and 90% of them fell between −22.05R and +13.72R. Our rule’s −0.27R beat 64% of them. It is well inside the band that pure chance produces.
  • With the tuned winner’s settings (1 ATR, 3R), random entries reached +27.2R or better in 20 of the 1,000 runs: 2%. That sounds rare, until you remember we tried 80 settings. One chance in fifty, tried 80 times, is expected to turn up once or twice. (Roughly: the 80 settings overlap, so they are not 80 separate tries.)

That is why a backtest result on its own means little. The question is never “did it make money?” but “did it do better than something with no idea, by more than luck explains?”

Our earlier random-entry baseline on a longer stretch of hourly data makes the same point about direction. From 11 June 2024 to 13 November 2026, entering at the open of every hourly candle with a fixed target and stop and $0.30 of costs:

Target / stop Side In-sample win rate In-sample net per trade Out-of-sample win rate Out-of-sample net per trade
$20 / $20 Long 52.0% +$0.51 49.0% −$0.71
$20 / $20 Short 47.7% −$1.21 49.0% −$0.71
$40 / $20 Long 39.0% +$3.12 35.4% +$0.93
$40 / $20 Short 29.8% −$2.44 32.5% −$0.82
$60 / $30 Long 42.2% +$7.65 37.0% +$3.01
$60 / $30 Short 22.9% −$9.65 32.1% −$1.38

Per ounce per trade, after $0.30 costs. In-sample 11 June 2024 to 31 July 2025, out-of-sample 1 August 2025 to 13 November 2026. About 6,400 to 6,560 trades per in-sample row and 7,360 to 7,380 per out-of-sample row, one per hourly candle, so trades overlap and are not independent. Carried from the earlier version of this lesson (added 16 November 2026), not re-run.

Random buys “made money” while gold was rising: +$3.12 an ounce a trade at 2:1 in-sample, with no skill at all. A long-only rule showing +$2 a trade over those months had shown that gold went up, not that it had an edge. Run your own rule on the same dates with the same stop, target and costs, and put your row next to the random row for the same side. Only the difference is yours.

The long version: 20-day breakouts on daily gold since 2005

The same method works on a long daily test, and it shows a fourth trap that the hourly test is too short to show: benchmark blindness.

The rule: after a daily close above the highest high of the previous 20 days, buy at the next day’s open. After a daily close below the lowest low of the previous 10 days, sell at the next open. Long only, one ounce, $0.30 a round trip. In-sample 2005 to 2018; out-of-sample 2019 to November 2026, run once with the rules frozen. Decisions on a finished close, fills at the next open, so no look-ahead.

Period Trades Win rate Profit factor Net per ounce Holding 1 oz instead
In-sample 2005-2018 52 44% 1.59 $447 $859
Out-of-sample 2019-Nov 2026 32 41% 1.82 $1,000 $2,771

We re-ran the rule on data to 23 November 2026 and got the same trades and totals. The holding figures are from the earlier run to early November; holding from the first open of 2019 to the 23 November close made about $2,365, still far more than the rule.

Real backtest: 20-day breakout versus simply holding goldProfit per ounce from 2005-01-07 to 2026-11-04 on COMEX gold futures daily data. The breakout rule ends at about $1,454; holding one ounce gained about $3,630.Profit per 1 oz, GC=F daily: breakout rule (gold) vs buy and hold (grey)out-of-sample$0$2,000$4,0002008201120142017202020232026
Real test: a profitable rule that still lost to holding. Real data: COMEX gold futures (GC=F) daily, 7 Jan 2005 to 4 Nov 2026. Rule: buy at the next open after a close above the prior 20-day high; sell at the next open after a close below the prior 10-day low; long only, $0.30 per ounce round trip, 1 ounce. It made money in both periods, yet holding one ounce made more each time. The rule's profit came mostly from gold's long uptrend, which is why every test needs a benchmark.

At first glance this is a success: profitable in both halves, with a better profit factor out-of-sample. Now read the last column. Simply holding one ounce made more in both periods. The rule made money mostly because gold went up, and it spent long stretches out of the market while gold kept rising.

Drawdown of the breakout ruleUnderwater curve of the breakout test; the deepest drawdown was about $666 per ounce, reached on 2026-02-02.Drawdown from the last equity peak, per 1 oz (US$)$-600$-400$-200$02008201120142017202020232026
Real test: the pain you have to sit through. Real data, same test. The curve shows how far the account sat below its previous best at each point. The deepest drawdown was about $666 per ounce, on 2 Feb 2026. Drawdowns grow with gold's price, which is one reason fixed-dollar rules age badly.

It also hurt on the way. The deepest drawdown was about $666 an ounce, on 2 February 2026, when gold’s swings had become very large. And across lookbacks from 10 to 100 days, the in-sample profit factor ranged from 1.11 to 2.30, with the “best” (100 days) resting on only 11 trades. A careful trader’s conclusion: the rule catches some of gold’s trends, does not beat holding gold, has small trade counts (52 and 32) and depends heavily on its setting. It fails at the benchmark gate. The next step is a new idea, not more tuning.

Limits of that test: the data is a continuous futures series from a public source, not your broker’s spot feed, and it was not adjusted for contract switches. Costs are a flat $0.30; swaps, which matter for multi-week holds on a spot or CFD account, are not included.

Data, fills and the spot-versus-futures gap

Gold puts eight specific obstacles in the way of a clean test.

  • There is no single spot price. Spot XAUUSD trades over the counter, and each broker and data vendor builds its own feed. Highs, lows and wicks differ between providers, most of all in fast moves. A stop “hit” on one feed may not be hit on another. Test on your own broker’s data where you can.
  • Futures have switches. Our tests use COMEX futures, which move to a new delivery month every couple of months. At each switch the series jumps by the price gap between the two months. This lesson’s hourly test sits inside one contract on purpose. Our older counts leave out every switch session and the day after it.
  • Charts show the bid. Most platforms draw the bid price. A buy fills at the ask, and a sell’s stop above the market is triggered on the ask, so add the spread to buy entries and to short exits.
  • Fixed spreads flatter testers. Spreads widen at the 5:00 pm New York daily break, in the Asian hours and around news. A tester set to one fixed spread understates costs exactly when fast strategies trade.
  • News candles and weekend gaps. US data at 8:30 New York time and Fed decisions at 2:00 pm produce moves where a real fill can be worse than the price a backtest assumes. Gold reopens on Sunday evening with a gap: trade 68 in our table was stopped on the Monday after one.
  • Time zones. A session filter breaks silently if you misread the server’s offset from UTC or New York.
  • Look-ahead. Using a candle’s close to decide something you then do at that candle’s open; marking a swing high that was only confirmed candles later; using a day’s high before the day finished. In code, refer only to finished candles. In replay, hide the future.
  • Regimes. Gold’s average daily range on COMEX futures went from about $34 in 2024 to about $64 in 2025 and around $123 in 2026 (figures from the earlier version of this lesson). A test on recent data alone covers one very volatile regime. A fixed-dollar stop does not travel between regimes: in the Level 1 risk management count, a $10 stop under a random hourly open was touched within four hours 23.0% of the time in 2024 and 69.8% in 2026. Sizing the stop in ATR, as this lesson’s rule does, lets it stretch with the market.

Running a test in TradingView replay and in the MT5 tester

Our test was coded. Most traders start by hand, which is slower and trains the eye. Allow an evening for your first one.

By hand, with TradingView bar replay

  1. Open a gold chart (TVC:GOLD or the feed closest to your broker) on the timeframe you trade.
  2. Write the rule in a note beside the chart: trigger, entry, stop, target, session, and what makes you skip a trade. If a line needs the word “feel”, rewrite it.
  3. Click Replay in the top toolbar, then click a starting date a few months back. Everything to the right is hidden.
  4. Step forward one candle at a time. Decide before you see the next candle.
  5. When the rule gives a trade, write it down before stepping on: date, time, direction, entry, stop, target.
  6. Step until the stop or target is hit; write the result in dollars an ounce and in R.
  7. Repeat until you have at least 30 trades, preferably 100, across quiet and busy weeks. Subtract your real spread from each.

Coded, with the MT5 Strategy Tester (you need the rule as an Expert Advisor)

  1. Open the tester: View, then Strategy Tester (Ctrl+R).
  2. Choose the EA, your broker’s exact gold symbol and the timeframe.
  3. Set a long date range and keep the last 25 to 30% aside.
  4. Choose “Every tick based on real ticks” where your broker has the history; “1 minute OHLC” is faster and rougher.
  5. Set deposit and leverage as you would really trade, and check the spread setting is your real spread, not zero.
  6. Run it with “Visualisation” on at least once to check the EA does what you meant.
  7. Read net profit, profit factor, maximum drawdown and number of trades, then look at the graph: a smooth curve that only works in one year is a warning.
  8. Run the hidden period once, with the same settings.

Many traders mix the two: they code the parts that can be coded, such as a session filter, and judge the rest by hand. Log test trades in the free XAUUSD trading journal spreadsheet, which works out R, expectancy, profit factor and drawdown, and keep your live journal in the same format so the two can be compared.

From backtest to forward test to small live size

Strategy testing pipelineSix boxes from idea to rules, in-sample test, out-of-sample test, forward test and small live, with a note to restart when a gate is failed.Testing pipeline: an idea must pass every gate before real money1 Ideaone clear sentence2 Rulestwo people take the same trades3 In-samplebuild and tune4 Out-of-sampletest once, frozen rules5 Forward testdemo, 50+ trades6 Small livecompare with the testFail a gate: go back to step 1 with a new idea.Never re-tune and re-test on the same out-of-sample data.
The testing pipeline. Schematic. Each gate is cheaper than the next. A failed out-of-sample test sends you back to a new idea, not to more tuning on the same data, because tuning until the out-of-sample period looks good turns it into in-sample data.

A test only earns its keep inside a process where each step is cheaper than the next and a failure sends you back to a new idea, not to more tuning.

  1. Write the rule with the fewest conditions that capture the idea.
  2. Set the costs before you start: spread by session, commission, a slippage allowance for news.
  3. Choose and split the data. Develop on the older part, often 60 to 70%; keep the newest part untouched.
  4. Run the in-sample test and log every trade.
  5. Make few changes, each with a reason that would make sense without seeing the results.
  6. Freeze the rule and run the out-of-sample part once. If it collapses, the in-sample result was probably fitted.
  7. Compare with a yardstick: random entries with the same exits, holding gold, or the rule without its key filter.
  8. Forward test the frozen rule on demo or at the smallest size (0.01 lot is 1 ounce) for at least 30 trades or two to three months. Log the spread and slippage you really got.
  9. Compare forward with backtest. Expect it to be somewhat worse. If it is much worse, find out why (missed trades, late entries, costs) before going further.
  10. Go live at reduced risk, and step up only while live results stay inside the range the tests suggested.
In-sample, out-of-sample and walk-forwardA bar split into in-sample and out-of-sample; below it four staggered walk-forward windows each with a tuning block and a test block.Two ways to split the dataSimple splitin-sample: build and tune (older ~65%)out-of-sample: test onceWalk-forwardBlue = tune, gold = test the frozen rules. Join the gold pieces to get the out-of-sample record.
In-sample, out-of-sample, walk-forward. Schematic. A simple split keeps the newest part of the data untouched until the rules are frozen. Walk-forward repeats the split in rolling windows, so the strategy is always judged on data it was not tuned on.

Our breakout rule stops at step 7: it does no better than random entries. The backtesting with free data lesson takes a London-open rule through more of the gates, and the position size calculator sizes the forward test.

Shortcuts that make a test worthless

  • Testing a vague rule. If two people would log different trades, you are testing your mood.
  • Stopping at 20 trades. The margin on a 20-trade win rate is about ±22 points.
  • Leaving costs out, or using zero spread in the tester. Our rule went from −0.27R to +0.45R that way.
  • Building hindsight into the rule. “Only sells” looks clever after a fall. Could you have written it before?
  • Tuning everything. 55 of 80 settings looked profitable on two months of data.
  • Picking the best setting and stopping there. Check its neighbours. A peak that collapses when one setting moves one step is luck.
  • Skipping the yardstick. If random entries with the same exits do as well, your entry adds nothing.
  • Peeking in replay. Hide the future; write the trade before stepping on.
  • Changing the rule during the forward test. Freeze it. Write new ideas down for version 2.
  • Going live at full size straight away. The first live month is a test of you, not of the rule.

The hub’s method sentence is a good standard to copy: “Exact rules, no look-ahead, fills at the next open or at the order price, the stop assumed first when a bar touches both levels, $0.30 per ounce per round trip, 1 ounce per trade.” And its warning about splitting the data, from the 5-minute scalp test: “Negative before costs, halves disagreed, and the same rules lost $744 on two years of hourly data.”

Walk-forward, neighbours and the many-tries problem

Eight further checks. Three were used on this lesson’s test (neighbours, counting tries, worse costs) and one in lesson 15 (shuffling the trades). The other four we have not run on it.

Walk-forward testing. Instead of one split, repeat it in rolling windows: tune on one block, test on the next, slide forward, repeat. The strategy is always judged on data it was not tuned on, and you see how its best setting drifts over time. A setting that keeps changing from window to window is not a setting; it is noise.

Neighbour checks. A sound idea gives similar results across nearby settings: if a 24-candle lookback works, 12 and 48 should not collapse. Map the results as a grid and look for plateaus, not peaks.

Count your tries. Every setting, filter and variation you test is another lottery ticket. With 80 tries, a result that pure chance beats only 2% of the time is expected to appear once or twice. Write down how many versions you tested, and judge the best one against that number, not against a single coin flip.

Shuffle the trades. Reordering your list of R results many times (a simple Monte Carlo) shows the range of drawdowns the same trades could have produced. The trading math lesson did this for a 225-trade record: its real worst drawdown was 11.7R, and one shuffle in twenty went beyond 20.3R.

Split by session, day and volatility. A rule can make its money in one session and hand it back in another. Splitting results by session, by day of week and by volatility (for example ATR above or below its 50-day average) is often more useful than any headline number, as long as each slice still has enough trades.

Test with news days in and out. Tag high-impact releases using the economic calendar for FOMC, CPI and NFP dates. A handful of release candles can hold a large share of a rule’s wins, or of its losses.

Run a “worse costs” version. Double the spread and add slippage. If the edge disappears, it was too thin to trade.

Version your rules. Name each rule set (v1.0, v1.1) so results from different versions never get mixed. The glossary has curve-fitting, walk-forward analysis, profit factor and sample size.

One change, written down before the test

Take the rule from this lesson and change exactly one thing that you can justify without looking at the results. For example: only take signals between 07:00 and 16:00 UTC, because those are the hours when London and New York are open and you would rather not trade the thin ones. Write the reason down first. Then test it by hand in replay over two weeks of gold you have not studied, log every trade in R with $0.30 of costs, and compare your total with the random band in this lesson. Whatever comes out, you will have done the one thing that separates a tested rule from a hopeful one: you decided before you looked.

From here Level 2 turns from what you trade to when. Lesson 17, the Sydney session for gold, starts where trade 68 in this lesson ended: the Monday open after a weekend gap, when gold reprices the weekend in thin, expensive hours.

Frequently asked questions

How do I backtest a gold strategy step by step?

Write the rule so exactly that a stranger would take the same trades. Choose the data and split off a later part you will not look at. Run the rule candle by candle, filling orders only at prices that existed after the signal, and log every trade with entry, stop, exit and result in R. Subtract realistic costs, then judge it by expectancy, profit factor, drawdown and number of trades, and compare it with a simple yardstick such as random entries or holding gold.

Can you show a real gold backtest?

Yes. This lesson runs a 24-hour breakout rule on COMEX gold futures hourly candles from 3 August to 23 November 2026, with a stop of 1.5 times the hourly ATR, a 2R target and $0.30 an ounce of costs. It made 69 trades, won 23 (33.3%, exactly the break-even rate for a 2R target) and finished at -0.27R, about break-even. Every trade is listed.

How many trades do I need to backtest a strategy?

There is no single number, but a few dozen is rarely enough. A win rate from 69 trades still carries a margin of about plus or minus 11 percentage points, and from 18 trades about 22. A common rule of thumb is 100 to 300 trades across quiet and busy markets before drawing conclusions.

What spread should I use when backtesting XAUUSD?

Use your own typical round-trip cost, then run the test again with a higher one. Our tests use $0.30 an ounce per round trip. Around news, the Sunday open and the daily break your real cost can be much higher. A result that only survives at the lowest cost you can imagine is not a result.

What is curve-fitting in backtesting?

Curve-fitting (overfitting) is tuning a rule’s settings until they match past data. In this lesson 55 of 80 settings of one simple rule made money on August and September 2026; the best of them was picked from 80 tries, which is why a good past result for a tuned setting proves very little.

Why should a backtest be compared with a benchmark?

Because the market’s own drift makes many rules look clever. Our long daily test of a 20-day breakout made money in both halves of 2005 to 2026, and simply holding one ounce made more in both. On the hourly test, random entries with the same stop and target finished between -22R and +14R in 90% of 1,000 simulated runs, so a result inside that band shows no skill.

Is manual backtesting as good as automated backtesting?

They test different things. Automated tests are fast and perfectly consistent but only work for rules that can be coded exactly. Manual bar-by-bar testing suits discretionary methods such as SMC or price action and trains your eye, but it is slower and easier to bias.

Why do my backtest results differ from live trading on gold?

Usually because of costs and slippage the test left out, a different data feed, look-ahead in the test, or skipped and late trades in live trading. Forward testing on demo or at the smallest size shows the gap before it costs real money.

Where can I get free historical gold data for backtesting?

Your platform’s own history (MT5 and TradingView), exports from your trading account, and COMEX gold futures data on public finance sites. Each has gaps: spot feeds differ between providers and futures data has contract switches. Our guide to backtesting gold with free data compares them.

What is forward testing?

Trading the frozen rules in real time, on demo or at the smallest live size, for at least 30 trades or two to three months. It checks whether you can follow the rules with real spreads, slippage and nerves.

Sources and further reading

External sites are independent of XAUUSD Global. Check dates and data yourself.

Back to the path: all Level 2 Intermediate lessons