Part 1: What a backtest is · Chapter 1 of 14 · 9 min

What a backtest is

A backtest applies written rules to past data and records the result of each trade in R. In this book we use 4,865 hourly gold candles (15 December 2025 - 6 October 2026) and a family of 480 breakout rules. The example rule (20-candle high, 1 ATR stop, 1 R target) gives 307 trades at −0.02 ± 0.11 R: the backtest tells you what would have happened with those rules and that data, not what will happen.

What a backtest does

A backtest takes a set of written rules (when to enter, where to put the stop, when to exit) and applies them to past data, candle after candle, as if you had followed them then. For each trade it records the result in R (chapter 1 of book 11): 1 R is the distance between entry and stop. At the end you have a list of results, from which you compute mean, error, losing streaks and drawdown with the tools of the previous books.

The backtest is the only way to try a rule without risking money, and it is also the easiest way to fool yourself. A backtest does not measure what will happen: it measures what would have happened with those rules, on that data, with those execution assumptions. Each of the three parts can be wrong. This book is a list of the ways in which it is, with real numbers.

The ingredients

Every backtest in this book has five ingredients, all declared:

IngredientWhat we used
Data4,865 market-open H1 gold candles (XAUUSDT perpetual future), from 15 December 2025 to 6 October 2026: a single instrument, under ten months
SignalBreakout: close beyond the high (or below the low) of the previous N candles
ExitStop at k times the ATR (14-candle mean), target at t times the stop, time exit after a maximum number of candles
Cost0.3 $ per ounce per trade, already inside the R
ExecutionEntry at the close of the signal candle, one trade at a time; if a candle touches both stop and target the stop counts (prudent rule)

The signal is simple on purpose: a breakout rule is described in one line and computed without interpretation. This is the first requirement of a backtest: the rule must be applicable by a computer, without judgment. "I buy when the price looks strong" cannot be tested; "I buy when the close exceeds the high of the last 20 candles" can.

A complete example

Take the most natural rule: high (or low) of the last 20 candles, stop at 1 ATR, target at 1 R, time exit after 24 candles. The figure shows a real trade.

Figure 1. A trade of the example rule (31 March - 1 April 2026, UTC hours): the 19:00 close rises above the high of the previous 20 candles (4,670.00 $), long entry at 4,680.51 $, stop at 4,652.05 $ (28.5 $ = 1 ATR, that is 1 R), target at 4,708.97 $ reached at one in the morning: +0.99 R (the difference from +1 is the 0.3 $ cost).Data: gold, XAUUSDT perpetual future (real candles) · 1 hour (H1) · from 31 Mar 2026 05:00 UTC to 1 Apr 2026 10:00 UTC.
Read the chart in words

Hourly gold chart of 31 March - 1 April 2026 with the 20-candle high level, the entry, the stop and the target of a long trade.

WhenWhatPrice
31 Mar 2026 19:00 UTCentry4,680.51
31 Mar 2026 19:00 UTCstop: −1 R (28.5 $)4,652.05
31 Mar 2026 19:00 UTCtarget: +1 R4,708.97
31 Mar 2026 11:00 UTC20-candle high4,670.00

Times in UTC.

Applied to all the candles, the rule gives 307 trades, which win 50% of the time. Mean R is −0.02 with an error of ±0.11 (chapter 2 of book 11), the deviation 1.00 R, the sum −4.6 R. The sign is not determined: the error is five times the value. The same rule reversed (fade: you sell the breakout and buy the breakdown) gives −0.05 ± 0.11.

Figure 2. Cumulative R of the example rule over the 307 trades (December 2025 - October 2026): peak +8.2 R, low −7.4 R, at the end −4.6 R.Data: gold, XAUUSDT perpetual future (real candles) · daily (D1) · from 15 Dec 2025 to 5 Oct 2026.
Read the chart in words

Daily gold chart with, below, the cumulative R curve of the example rule.

The curve rises and falls inside a narrow band and ends near zero. It is what you expect from a rule with no edge and 307 trades, and it is the reference for the whole book: a curve like this is a normal result, not a failure.

The family of 480 rules

It is rare that a single rule is the one you use. In practice you try variants: another length, another stop. Here we use a fixed family:

ParameterValuesNumber
Breakout length N (candles)10, 20, 30, 50, 805
Stop k (times the ATR)0.5, 1, 1.5, 24
Target t (times the stop)1, 1.5, 2, 34
Maximum duration (candles)12, 24, 483
Directionbreakout (follow) or fade (go against)2

Five times four times four times three times two make 480 rules. Applied to all the candles they give 108,309 trades in total, from 72 to 499 per rule (median 210). The rest of the book uses this grid to show how a good-looking result is born and how it is checked.

The four questions

Every backtest, before being believed, must answer four questions. They are the index of the book.

  1. How many rules did you try? A result chosen among 480 is worth less than one obtained with a single rule written beforehand (chapters 2, 3 and 9).
  2. Did you try the rule on data you did not use to choose it? An in-sample result overstates what will come (chapters 4, 5 and 6).
  3. Does the test use only information that existed at the time of the decision? A timing error inflates the numbers without your noticing (chapter 7), and costs and execution matter too (chapter 8).
  4. Does the result beat chance, and does it hold if you change the rules and the period a little? You need a comparison with random series, the neighbours check and a reading by period (chapters 10, 11 and 12).

Chapter 13 puts them together in a process, and 14 gives the summary with the mistakes and the final test.

What to do with it

  1. Write the rule so that a computer can apply it: signal, entry, stop, target, time exit, cost.
  2. Declare data and period: instrument, interval, how many candles. Ten months on a single instrument is a small sample.
  3. Record every result in R, with the cost, and look at mean and error, not just the sum.
  4. Keep a log of everything you try, discarded rules too: the number of trials counts (chapter 3).
  5. Do not trust a backtest you cannot explain in one line.

Procedure in four steps

  1. Write signal, stop, target, time exit and cost so that a computer can apply them.
  2. Declare the data (instrument, period, number of candles) and the limits.
  3. Compute the number of trades, mean R ± error, winning share, curve and drawdown.
  4. Write down how many rules you tried and which data you have already looked at.

Exercises

Chapter exercises

1. On the chart the lines are the entry (5,140.05 $), the stop (5,161.26 $) and the target (5,118.84 $) of a short trade of 11-12 March 2026 (UTC hours); the line at the upper left is the 20-candle low (5,146.27 $). Which letter is the candle in which the stop is hit?

Chart exercise. Data: gold, XAUUSDT perpetual future (real candles) · 1 hour (H1) · from 11 Mar 2026 08:00 UTC to 12 Mar 2026 11:00 UTC.
Read the chart in words
WhenWhatPrice
11 Mar 2026 22:00 UTCentry5,140.05
11 Mar 2026 22:00 UTCstop: −1 R (21.2 $)5,161.26
11 Mar 2026 22:00 UTCtarget: +1 R5,118.84
11 Mar 2026 14:00 UTC20-candle low5,146.27
11 Mar 2026 18:00 UTCPoint A5,177.15
11 Mar 2026 22:00 UTCPoint B5,181.46
12 Mar 2026 00:00 UTCPoint C5,159.43
12 Mar 2026 01:00 UTCPoint D5,170.89

Times in UTC.

2. The example rule gives 307 trades at −0.02 ± 0.11 R. What can be said?

3. You add one value to each parameter of the grid: 6 lengths, 5 stops, 5 targets, 4 durations and two directions. How many rules do you have?

4. Which of these is a rule that can be tested with a backtest?

Have a question or want to share your exercise?

Post in the community, or join the free signals room on Telegram.

Educational content, not financial advice. Trading involves risk.