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:
| Ingredient | What we used |
|---|---|
| Data | 4,865 market-open H1 gold candles (XAUUSDT perpetual future), from 15 December 2025 to 6 October 2026: a single instrument, under ten months |
| Signal | Breakout: close beyond the high (or below the low) of the previous N candles |
| Exit | Stop at k times the ATR (14-candle mean), target at t times the stop, time exit after a maximum number of candles |
| Cost | 0.3 $ per ounce per trade, already inside the R |
| Execution | Entry 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.
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.
| When | What | Price |
|---|---|---|
| 31 Mar 2026 19:00 UTC | entry | 4,680.51 |
| 31 Mar 2026 19:00 UTC | stop: −1 R (28.5 $) | 4,652.05 |
| 31 Mar 2026 19:00 UTC | target: +1 R | 4,708.97 |
| 31 Mar 2026 11:00 UTC | 20-candle high | 4,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.
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:
| Parameter | Values | Number |
|---|---|---|
| Breakout length N (candles) | 10, 20, 30, 50, 80 | 5 |
| Stop k (times the ATR) | 0.5, 1, 1.5, 2 | 4 |
| Target t (times the stop) | 1, 1.5, 2, 3 | 4 |
| Maximum duration (candles) | 12, 24, 48 | 3 |
| Direction | breakout (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.
- 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).
- 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).
- 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).
- 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
- Write the rule so that a computer can apply it: signal, entry, stop, target, time exit, cost.
- Declare data and period: instrument, interval, how many candles. Ten months on a single instrument is a small sample.
- Record every result in R, with the cost, and look at mean and error, not just the sum.
- Keep a log of everything you try, discarded rules too: the number of trials counts (chapter 3).
- Do not trust a backtest you cannot explain in one line.
Procedure in four steps
- Write signal, stop, target, time exit and cost so that a computer can apply them.
- Declare the data (instrument, period, number of candles) and the limits.
- Compute the number of trades, mean R ± error, winning share, curve and drawdown.
- 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?
Read the chart in words
| When | What | Price |
|---|---|---|
| 11 Mar 2026 22:00 UTC | entry | 5,140.05 |
| 11 Mar 2026 22:00 UTC | stop: −1 R (21.2 $) | 5,161.26 |
| 11 Mar 2026 22:00 UTC | target: +1 R | 5,118.84 |
| 11 Mar 2026 14:00 UTC | 20-candle low | 5,146.27 |
| 11 Mar 2026 18:00 UTC | Point A | 5,177.15 |
| 11 Mar 2026 22:00 UTC | Point B | 5,181.46 |
| 12 Mar 2026 00:00 UTC | Point C | 5,159.43 |
| 12 Mar 2026 01:00 UTC | Point D | 5,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.