What Is Backtesting in Trading? How It Works and How to Do It

Backtesting trading means taking a strategy and testing it on past market data to see how it would have performed, before you risk real money on it. Done properly, it turns “I think this setup works” into numbers you can trust or throw away.
What backtesting is
A trading strategy is a set of rules: when to enter, where to put the stop, where to take profit, how much to risk. Backtesting applies those rules to historical prices, trade by trade, and records what would have happened. The result is a list of trades you can measure exactly like a live journal.
Manual or automated backtesting?
- Automated: you code the rules into a program (an Expert Advisor, a Pine Script strategy) and it runs through years of data in seconds. It is fast, but it only tests rules you can write as code
- Manual (replay): you scroll back to a past date, reveal candles one by one and take every decision yourself, as if it were live. It is slower, but it tests the strategy as you really trade it, judgement and hesitation included
Discretionary traders usually get more from a manual replay, because the thing being tested is the trader as much as the rules.
How to backtest a strategy, step by step
- Write the rules down first. Entry, stop, target, position size and the conditions to stay out. If a rule is vague, the test is worthless
- Pick the market and the period. Include different conditions: trending months, ranging months, high and low volatility
- Take every signal. Skipping the ones you “would not have liked” is the easiest way to fool yourself
- Count the costs. Spread, commission and slippage turn many winning strategies into losing ones
- Record each trade with its risk and result in R, exactly as you would in a trading journal
- Collect enough trades. Twenty trades prove nothing; many traders look for at least a hundred before drawing conclusions
Pro Tip: Decide in advance how many trades the test needs and what result would make you drop the strategy. Setting the bar after you see the numbers is how backtests end up confirming what you hoped.
The numbers to read at the end
- Win rate: the share of winning trades. Not enough on its own
- Average R: your average result in units of risk
- Expectancy: what you make per trade, on average, in R
- Profit factor: the sum of the wins divided by the sum of the losses
- Max drawdown: the worst fall from a peak, which tells you whether you could live through the strategy. Our guide to max drawdown explains how to calculate it
Expectancy is the one that ties them together: win rate × average win − loss rate × average loss. A strategy that wins 40% of the time with an average win of 2R and an average loss of 1R has an expectancy of 0.4 × 2 − 0.6 × 1 = +0.2R per trade. Low win rate, positive edge.
The traps that make a backtest lie
- Hindsight: using information you could not have known at that candle, for instance when you can see what comes next on the chart
- Curve fitting: tweaking the rules until the past looks perfect. The more parameters you tune, the less the result means
- Too few trades or one market phase: a strategy tested only in a strong uptrend has told you nothing about a range
- Ignoring costs and slippage: the backtest is cleaner than real trading
Careful: A good backtest does not predict the future. It tells you the strategy had an edge in the past under your rules and costs, which is a reason to test it on a demo or with very small size, not to trade it at full size.
Backtesting in TradeTrackz
The TradeTrackz Backtest replays real market history candle by candle. You choose a market and a date, place orders with a stop loss and a take profit, and the spread and commission are applied as on a real account. At the end of a session you read your profit factor, average R, expectancy and win rate, and you can share a read-only link with a mentor. A free trial session of up to 10 trades lets you try it before deciding on the pack.
Ready to test your strategy before you risk money? Try TradeTrackz free and open the Backtest.
Trading carries a high risk of loss. This article is educational and is not trading or financial advice.