The rules tested

The strategy buys gold when the price closes above the highest high of the previous 20 bars, and sells when it closes below their lowest low. Stop loss at 2 ATR, take profit at 4 ATR, 1% of the account at risk per trade, on 4-hour bars.

Instrument
Gold (XAU/USD)
Timeframe
4 hours (H4)
Entry
close above the highest high or below the lowest low of the previous 20 bars
Filters
none
Stop loss
2 times the 14-bar ATR
Take profit
4 times the 14-bar ATR
Other exits
none
Risk per trade
1% of the virtual account, position size set from the stop distance
Costs
spread actually recorded hour by hour, slippage of half a spread on every stop, no commission; swaps not included
Period tested
from August 1, 2022 to September 25, 2026

Edit this strategy in the lab

The button opens the lab with exactly these settings: change one, run it again and compare.

A result that looks solid

Every usual check comes out well. The rule makes money in the design period (+12.2%) and in the out-of-sample period (+19.3%), which played no part in tuning it. All nine range lengths tested, from 10 to 40 bars, are profitable, from +29.0% to +89.1%, and the 20-bar setting even sits at the lower end of that range: it was not picked after the fact. Costs barely register at 0.01 R per trade, because on four-hour gold bars the stop is very wide compared with the spread.

Cumulative result in % of the virtual account, trade after trade, with 1% risk per trade. Hypothetical. Shaded area: out-of-sample period.

The ride is anything but smooth, though: the maximum drawdown reaches 12.4% of the virtual account, and the worst run is 12 losing trades in a row. With 38.1% of trades in profit, the rule lives on a few wins twice the size of its losses.

But longs did all the work

Split the trades by direction. The 147 longs made 56.8%; the 92 shorts lost 14.6%. The rule is symmetrical, buying upside breakouts and selling downside ones. The market was not. Gold rose strongly over the test period, by 143.2% between August 1, 2022 and September 25, 2026, and a breakout rule mechanically profits from a long one-way trend while losing on the breakouts that go against it.

  • Shorts
  • Longs
Contribution of longs and of shorts to the result, in % of the virtual account, trade after trade: each line compounds the trades of one direction only. Hypothetical. Shaded area: out-of-sample period.

The same rule on currencies

Applied unchanged to the lab's three currency pairs, the same 20-bar breakout on H4 gives this:

InstrumentPrice changeTradesResultBefore costs
Gold (XAUUSD)+143.2%239+33.9%+34.4%
EUR/USD+11.6%238-15.6%-7.4%
GBP/USD+8.8%231-6.6%-4.2%
USD/JPY+17.9%246+0.2%+10.5%

No currency pair repeats gold's result, and none saw a comparable move over the period: the “Price change” column compares the open of the first bar with the close of the last. On USD/JPY it makes money until 2024, then loses in 2025 and 2026: the page on that case shows how the out-of-sample test gives it away. What paid here was a trend specific to gold over these four years, not a property of the rule.

The question this test leaves open

This backtest cannot tell you what the rule does once gold stops rising: the test period holds almost no example of it. That is the limit of any test on a history dominated by a single market regime. To dig further, open this strategy in the lab and run it long only, then short only, from the advanced options. The results will be close to the two lines above without matching them exactly: the lab holds one position at a time, so one direction no longer blocks the other.

Design period against out-of-sample

Design period: Aug 1, 2022 to Jun 27, 2025

Result
+12.2%
Trades
172
Maximum drawdown
12.4%
In R
+13.5 R

Out-of-sample: Jun 27, 2025 to Sep 25, 2026

Result
+19.3%
Trades
67
Maximum drawdown
6.3%
In R
+18.7 R

Tune the strategy while looking at the design period, then judge it on the out-of-sample period, which played no part in the tuning. A wide gap between the two often means the settings were fitted to the past.

Sensitivity of the main setting

Result over the period (in %) as the number of bars in the range changes, every other setting unchanged. Outlined bar: your setting. A result that only holds for one exact value is fragile.

Year by year

YearTradesResult (R)
202223-2.2 R
202351+8.9 R
202461+7.9 R
202560+14.9 R
202644+2.7 R

In R, the multiple of the risk taken on each trade: a yearly total cannot be read as a % of the account, since gains and losses compound from one year to the next.