Strategies

How to Backtest a Strategy Before Trading for Real

A backtest is the process of testing a trading strategy using historical data, before risking real capital on it. The idea is simple: apply the same entry and exit rules you would use live to a past period of the chart, and record what would have happened on every signal generated. It's a step that separates a strategy with evidence of working from an idea that only looks good when looking back at the chart in hindsight.

Step 1: write down the entry and exit rule

Before looking at any historical data, write the exact rule you're going to test — for example: "buy when the price breaks above the high of the last 20 candles with volume 30% above average; exit at a 2% profit or a 1% stop loss". Vague rules like "buy when it looks like a good opportunity" can't be tested consistently, because they depend on subjective judgment on every signal.

Step 2: go through the history signal by signal

With the rule defined, go through the historical chart identifying every time the entry condition would have been met, and record the result the exit rule would have produced — profit or loss, in points or percentage. It's important to stay disciplined about applying the rule exactly as written, without "adjusting" the result after seeing what happened, at the risk of biasing the test in the strategy's favor.

Step 3: calculate the win rate and average payoff

After gathering a reasonable sample — 30 signals at minimum, ideally more — calculate two numbers: the win rate (percentage of winning trades) and the average payoff (the average gain on winning trades divided by the average loss on losing trades). Suppose a backtest with 40 signals, 18 winners and 22 losers, an average gain of R$ 60.00 on winners and an average loss of R$ 35.00 on losers. The win rate is 45% (18/40) and the payoff is 1.71 (60/35).

Step 4: calculate the expected value

Expected value measures the average expected result per trade, and is calculated like this: (win rate × average gain) − (loss rate × average loss). Using the numbers from the example: (0.45 × R$ 60.00) − (0.55 × R$ 35.00) = R$ 27.00 − R$ 19.25 = R$ 7.75 positive per trade, on average. A positive expected value indicates that, keeping the same win rate and payoff over time, the strategy tends to generate a positive result — which doesn't guarantee every individual trade will be profitable, but indicates a statistical edge in the tested sample.

What a backtest doesn't guarantee

A positive historical result doesn't guarantee the same performance going forward — market conditions change, and a small sample may have been favorable by chance. On top of that, manual backtests are subject to hindsight bias: it's easy to unintentionally adjust the interpretation of a signal knowing what happened afterward. Because of that, many traders follow the backtest with a testing period on a simulated account, applying the same rule in real time before trading with meaningful capital.

Putting the process into practice

  • Write down the entry and exit rule before looking at any historical data.
  • Gather a minimum sample of 30 signals so the numbers carry some statistical weight.
  • Calculate win rate, average payoff, and expected value before considering the strategy validated.
  • Test on a simulated account for a period before applying real capital, even with a positive backtest.

A backtest is a filtering tool, not a guarantee: it helps rule out strategies with no apparent statistical edge, and helps you better understand the expected behavior of the ones that remain — but no expected value calculated over the past is a promise of future results.

An extra precaution: sample size matters more than it seems

A positive expected value calculated over just 10 or 15 signals has little statistical value — it can be the result of luck in the sample, not a real edge in the strategy. The larger the number of signals tested, the more confidence the result carries, although no sample, no matter how large, completely eliminates uncertainty about the future. It's also worth testing the strategy across different market periods — uptrends, downtrends, and sideways markets — since a rule can work well in one regime and poorly in another, and a backtest done only over a strong uptrend period tends to overestimate the expected result.

Practice before you risk. Open your Astron account and test your ideas on the demo account with R$ 10,000 in virtual funds.

Create free account