← Back to the blog
Tools & comparisons

How to backtest a trading strategy (the complete method)

The method for backtesting a strategy seriously: sample size, unambiguous rules, biases to avoid, and moving on to replay.

L’équipe Altiora··5 min read

To backtest a trading strategy, write rules precise enough that anyone would take the same trades, then run them in order on historical data, charging every trade its real costs. Judge the result on expectancy and drawdown over a large sample, check it on data you didn't use to build the rules, and confirm it in bar-by-bar replay before you risk real money.

What is backtesting?

Backtesting is testing a strategy's rules on past market data to see whether it has a statistical edge before you risk real money. Done badly, it breeds false confidence. Done well, it saves you months of losses.

Three terms come up all the time:

  • Edge: a positive expectancy that holds over many trades, not over a few lucky ones.
  • Expectancy: the average result per trade. Expectancy = (win rate × average win) − (loss rate × average loss). Positive means the strategy earns on average.
  • Replay: the market played back bar by bar with future bars hidden, so you make each decision without knowing what comes next.

Step 1: write rules that leave no room for interpretation

A backtestable strategy says exactly:

  • which market and which timeframe
  • the entry condition
  • where the stop goes
  • the exit (target, time limit or signal)
  • the position size, usually a fixed risk per trade

The test is simple: if two people read your rules on the same chart, they take the same trades. If they don't, the strategy isn't testable yet. Your trading plan is the right place to write these rules down.

Step 2: pick your data and split it in two

Choose a period that covers different conditions: trend, range, high volatility. An edge that only works in one market regime is not reliable.

Then split that history:

  • In-sample: the part where you build and adjust the rules.
  • Out-of-sample: a later part you don't look at until the rules are frozen.

If the strategy only works on the data you used to tune it, you have measured the past, not an edge.

Step 3: run the trades in order, using only what you knew at the time

Go through the history chronologically and take every signal, including the ones you don't like. The most common cheat is look-ahead bias: using information you wouldn't have had at decision time. A signal that appears on a candle's close can only be filled after that close, not at a nicer price inside the candle.

There are three ways to run the test:

  • Manually on a chart, logging each trade. Slow, but you learn how the setup really behaves.
  • In replay, with future bars hidden. Closer to live decision-making.
  • In code, for hundreds of trades or many markets. This only works if the rules are fully mechanical.

Step 4: charge every trade its real costs

A backtest without costs measures an idea, not a strategy. Subtract commissions, spread and slippage from every trade. The shorter your trades and the tighter your stops, the bigger the share of the result that costs eat. That's why this step matters most for scalping.

Step 5: build a big enough sample

Ten trades prove nothing. Aim for at least 100 trades before drawing a conclusion, spread across several market conditions. With a small sample, a few lucky trades are enough to make a bad strategy look good.

Step 6: read the right numbers

Total profit is the least useful number in a backtest. Look at these instead:

  • Expectancy in R (multiples of your risk per trade): is it positive, and by how much?
  • Win rate and average win vs average loss: together, they explain the expectancy.
  • Maximum drawdown: the deepest drop from a peak. Could you live with it? Does it fit your prop firm's limits?
  • Longest losing streak: this is what will test your discipline live.

Our guide to trading journal statistics explains how to read each one.

Step 7: avoid the classic biases

  • Selection bias: testing only the periods or setups that suit you.
  • Survivorship bias: testing only on markets or stocks that still exist today, which ignores the ones that disappeared and flatters the result.
  • Overfitting: a strategy tuned perfectly to the past usually fails in the future. Fewer parameters means a sturdier strategy.
  • Hindsight bias: on a chart you already know, the "obvious" trades only look obvious afterwards. Replay hides the future to fix this.

Step 8: confirm in replay, then trade small

A historical backtest tells you whether the strategy has an edge. Replay tells you whether you can actually execute it. Walk the market bar by bar, decide without seeing the next candle, and log each decision as if it were real. Then go live with a small size before you scale up.

Preparing a prop firm challenge? Backtest on windows the length of an evaluation, and check your worst day against the daily loss limit. See prop firm drawdown management and the prop firm consistency rule.

Start my 7-day trial

Journal your backtests like real trades

Log every backtest trade with its setup, entry, stop, exit and result, then compare setups with the same statistics you use for live trading. The logic is the same as in the trading journal guide. Keep backtests apart from live trades so they don't distort your real stats.

Backtesting in Altiora

Altiora has a backtesting and replay module next to the journal: bar-by-bar replay on historical data with speed and step control, drawing tools that stay between sessions, and a position tool that puts entry, stop and target on the chart. Backtest sessions feed a backtest journal kept separate from your live one, and challenge presets let you test under a prop firm's rules. Details are on the trading journal with backtesting page, or see all features.

The 7-day trial gives you full access, no card.

Start my 7-day trial

Frequently asked questions

How do you backtest a trading strategy?
Write rules with no room for interpretation, run them in order on historical data, charge every trade its real costs, judge expectancy and drawdown over a large sample, check the result on data you did not use to build the rules, then confirm it in bar-by-bar replay.
How many trades do you need for a reliable backtest?
Ten trades prove nothing. Aim for at least 100 trades, spread across different market conditions, before drawing a conclusion.
What is the difference between backtesting and replay?
Backtesting measures whether a strategy has an edge over many trades. Replay plays the market back bar by bar with future bars hidden, to test whether you can actually execute the strategy.
Can you backtest a strategy manually?
Yes. Scroll a chart or use replay and log every signal. It is slower than code but works for discretionary strategies, as long as the rules are precise enough that two people would take the same trades.
Why does a strategy that worked in backtest fail live?
The usual causes are overfitting, look-ahead bias, missing costs, a sample that was too small, or execution: hesitating, skipping trades or changing size live.

About the author

L’équipe Altiora

Altiora editorial team

Altiora's editorial team brings together active traders and the product team. We write about discipline, journaling and performance analysis, grounded in how the platform actually works. We never give investment advice.

Read next