# Backtesting Your Strategy

> Proving an edge on historical data.

Module: Building a Trading Plan & System — Finotaur Academy (free lesson)
Source: https://www.finotaur.com/academy/trading-plan-system/backtesting-your-strategy

## You'll be able to

Run an honest backtest of a written setup — with costs, an out-of-sample check and the right statistics — and recognise the biases that make backtests lie.

## In plain words

Backtesting means applying your exact rules to historical price data to see how the strategy would have performed. Done honestly, it gives you a large sample of trades in days instead of months, and shows you the losing streaks and drawdowns to expect before you live through them. Done carelessly, it produces beautiful results that vanish the moment real money is involved — so how you test matters as much as what the results say.

```takeaways
- A backtest tests **rules**, so the rules must be written precisely before you start — no adjusting as you go.
- Always include **costs** and keep part of your data **out-of-sample** to check the result was not fitted to the past.
- Judge a strategy on **expectancy, profit factor, max drawdown and sample size** — never on total profit alone.
```

## Quick demo

**A pullback strategy, tested two ways (hypothetical numbers).** You test your setup on two years of data. You use the first 18 months to study it (**in-sample**) and lock the last 6 months away until the end (**out-of-sample**).

In-sample: **120 trades**, 48 winners averaging 1.9R, 72 losers at 1.0R.

- Gross profit = 48 × 1.9R = 91.2R. Gross loss = 72 × 1.0R = 72R.
- **Profit factor** = 91.2 ÷ 72 ≈ **1.27**
- **Expectancy** = (91.2 − 72) ÷ 120 = **+0.16R** per trade
- After costs of about 0.05R per trade: **+0.11R**

Out-of-sample, untouched until now: **60 trades**, 24 winners at 1.8R, 36 losers at 1.0R.

- Net = 43.2R − 36R = 7.2R → **+0.12R** gross, **+0.07R** after costs

The edge held up on unseen data, but smaller. That shrinkage is normal and expected — and it is the number you should plan around, not the in-sample one.

## Full explanation

### Step by step

1. **Freeze the rules.** Write the context filter, trigger, stop, target and time exit before you look at a single trade. If you change a rule, you restart the test.
2. **Choose the data.** Use enough history to include different conditions — trending, ranging, high and low volatility. Split it: something like the first 70% in-sample, the last 30% out-of-sample.
3. **Record every trade.** Date, time, entry, stop, exit, result in R, and a screenshot or note. Include the ones you "would have skipped" — if the rules said take it, you take it.
4. **Apply costs.** Commissions, exchange fees and a realistic slippage estimate on every trade, especially stops and market orders.
5. **Calculate the statistics** on the in-sample set. Only then run the out-of-sample set, once.
6. **Compare.** If out-of-sample collapses, the in-sample result was probably fitted to noise.

### The statistics that matter

```stats
Expectancy | Average R per trade | The core number — must be positive after costs
Profit factor | Gross profit ÷ gross loss | Above 1 is profitable; many traders want 1.3+ after costs
Max drawdown | Worst peak-to-trough, in R | Sets your real risk tolerance
```

Add three more: **win rate** and **average win / average loss** (to understand *how* the strategy makes money), and the **longest losing streak** (so you know what normal pain looks like).

Total profit is the least useful number. It depends on how many trades you took and your position size, and it hides how bumpy the path was.

```chart
{
  "type": "bar",
  "title": "Expectancy per trade, in R — in-sample vs out-of-sample (illustrative)",
  "unit": "R",
  "unitPosition": "suffix",
  "data": [["In-sample, gross", 0.16], ["In-sample, net", 0.11], ["Out-of-sample, gross", 0.12], ["Out-of-sample, net", 0.07]],
  "highlight": ["Out-of-sample, net"],
  "caption": "Illustrative numbers from the hypothetical test above. Costs and unseen data both shrink the edge; the out-of-sample, after-cost figure is the one to plan with."
}
```

### The biases that make backtests lie

**Overfitting (curve-fitting).** Every extra parameter — a moving-average length, an RSI level, a time filter — lets the strategy bend to fit the past. Test enough combinations and one will look great by pure chance. Warning signs: results that collapse when a parameter changes slightly (a 20-period average works, 19 and 21 do not), or many rules with few trades. Prefer few rules and settings that work across a range of values.

**Look-ahead bias.** Using information that was not available at the time — for example entering at the open based on that day's close, or using a daily high that had not formed yet. In manual testing, hide the future bars as you go.

**Survivorship bias.** Testing stocks only from today's index list ignores the companies that were dropped or went bankrupt. Results look better than reality.

**Unrealistic fills.** A limit order that price only *touched* may not have filled in reality — you were in a queue. Conservative testers count a limit fill only if price traded through the level. Stops in fast markets fill worse than the stop price.

**Ignoring costs.** As the edge chapter showed, a few dollars per trade can turn a short-term strategy from profitable to losing.

```warning
If you tweak the rules after looking at the out-of-sample results and then re-run it, it is no longer out-of-sample. You have only one honest look at that data. Use it at the end.
```

### Manual versus automated testing

**Automated** backtests (code in a testing platform) can run thousands of trades and many variations quickly — which also makes overfitting easier. **Manual** testing (bar-by-bar replay, recording each trade by hand) is slower but trains your eye, and forces you to deal with the same ambiguity you will face live. For discretionary setups, a manual test of 100+ trades is often more realistic than a perfect-looking automated one.

### How many trades?

More is better, but quality matters. Aim for at least **100 trades** in-sample if the setup is frequent enough, and remember from the edge chapter that even 100 trades leaves roughly ±10 percentage points of uncertainty on the win rate. A strategy that produces 30 trades in five years may be real, but you will never be very sure.

### Common mistakes

- **Testing until it works.** Trying 50 variations and keeping the best is data mining, not discovery.
- **Skipping trades in the test** that "didn't feel right". If you cannot code or write that feeling as a rule, it does not exist in the backtest.
- **Testing one market regime.** Two years of a bull market tells you little about how a long strategy behaves in a decline.
- **Trusting total profit** instead of expectancy and drawdown.

```checklist
title: Backtest protocol
- Write and freeze the rules before opening any chart.
- Split the data: about 70% in-sample, 30% out-of-sample.
- Record every rule-valid trade, including the ones you dislike.
- Hide future bars to avoid look-ahead bias.
- Apply commissions, fees and slippage to every trade.
- Count limit fills only when price trades through the level.
- Calculate expectancy, profit factor, win rate, avg win/loss, max drawdown and longest losing streak.
- Run the out-of-sample set once, at the end.
- Check that results hold when key settings move slightly.
- Plan with the out-of-sample, after-cost numbers.
```

```quiz
[
  {
    "q": "A backtest shows gross profit of 90R and gross loss of 60R over 100 trades. What are the profit factor and expectancy?",
    "options": ["PF 1.5, expectancy +0.30R", "PF 0.67, expectancy −0.30R", "PF 1.5, expectancy +0.90R", "PF 3.0, expectancy +0.30R"],
    "answer": 0,
    "why": "PF = 90 ÷ 60 = 1.5. Expectancy = (90 − 60) ÷ 100 = +0.30R per trade."
  },
  {
    "q": "A strategy works with a 20-period moving average but fails with 18 and 22. What does that suggest?",
    "options": ["20 is a magic number", "The result is probably overfitted to noise", "The strategy is robust"],
    "answer": 1,
    "why": "Real edges usually survive small parameter changes. A sharp peak at one setting is a classic overfitting sign."
  },
  {
    "q": "Why keep part of the data out-of-sample?",
    "options": ["To save time", "To check the rules on data they were not developed on", "Because older data is less accurate"],
    "answer": 1,
    "why": "Out-of-sample data gives one honest test of whether the in-sample result was real or fitted to the past."
  },
  {
    "q": "In a conservative backtest, when should a limit order count as filled?",
    "options": ["When price touches the limit price", "When price trades through the limit price", "Always at the limit price"],
    "answer": 1,
    "why": "A touch does not guarantee a fill because other orders were ahead of you in the queue. Requiring a trade-through avoids overstating results."
  }
]
```
