Key points
- Historical results do not predict future results.
- Look-ahead bias, survivorship bias and ignored costs inflate backtests.
- Judge results by drawdown, trade count and robustness, not just total return.
- Walk-forward and out-of-sample tests reduce, but do not remove, overfitting.
What a backtest can and cannot tell you
A backtest answers a narrow question: if these exact rules had been followed on this data, with these assumptions about costs and fills, what trades would have occurred? It can reveal that an idea loses money, trades too rarely, or suffers deep drawdowns. It cannot show that the future will resemble the past.
Data quality comes first
- Use data with correct session times and time zone; Indian equity sessions run on IST.
- Adjust share prices for splits and bonuses, or your signals will react to artificial jumps.
- Handle futures expiries and rollovers explicitly; a continuous series is a construction with its own assumptions.
- Look for gaps, duplicate bars and zero-volume periods, and decide how to treat them before testing.
- Know whether your candles are traded prices or transformed values such as Heikin-Ashi averages.
Biases that inflate results
| Bias | What happens | Mitigation |
|---|---|---|
| Look-ahead | Rules use information not available at decision time, such as the bar's close for an entry at its open | Evaluate on closed bars and enter on the next bar |
| Survivorship | The test universe excludes companies that were delisted or removed from an index | Use point-in-time constituent lists |
| Overfitting | Parameters are tuned until noise looks like signal | Few parameters, out-of-sample and walk-forward tests |
| Cost blindness | Brokerage, taxes, exchange fees and slippage are ignored | Model all costs conservatively |
| Fill optimism | Limit orders are assumed filled whenever price touches them | Require price to trade through, or add slippage |
Modelling costs and fills
Indian trades carry several charges: brokerage, securities transaction tax or commodities transaction tax, exchange transaction charges, SEBI turnover fees, stamp duty and GST on certain charges. Rates differ by segment and change over time, so take current figures from your broker's charges page and apply them per trade.
Add slippage on top. A simple approach is a fixed number of ticks per side, larger for less liquid instruments and for stop orders, which tend to fill at worse prices during fast moves. High-frequency strategies with small average profits are the most sensitive to these assumptions.
Reading the results
| Metric | Why it matters |
|---|---|
| Number of trades | Few trades mean results may be luck |
| Expectancy after costs | Average outcome per trade in rupees or R |
| Maximum drawdown | The deepest peak-to-trough fall; can you sit through it? |
| Profit factor | Gross profit divided by gross loss, after costs |
| Longest losing streak | Tests your sizing and your patience |
| Results by year or regime | Shows whether a few periods carry everything |
Max drawdown = max over time of (previous equity peak − current equity) ÷ previous equity peakOut-of-sample and walk-forward testing
Split history into an in-sample period for development and an out-of-sample period you look at only once at the end. Walk-forward analysis repeats this: optimise on a window, test on the following window, roll forward and stitch together only the test-window results. If performance collapses outside the tuning windows, the strategy was probably fitted to noise.
After historical testing, forward paper trading reveals issues history cannot: data delays, session-start behaviour and operational errors. The paper testing tutorial walks through that stage.
A pre-flight checklist before trusting a backtest
- Can every rule be evaluated with data available at that moment, with entries on the next bar?
- Does the instrument universe include stocks that were later delisted or removed from indices?
- Are all charges and a realistic slippage allowance applied to both entry and exit?
- Is the trade count large enough, and are results spread across years rather than concentrated in a few trades?
- Do nearby parameter values give broadly similar results?
- Has the out-of-sample period been examined only once?
- Would you be able to tolerate the maximum drawdown and the longest losing streak with real money?
If any answer is no or unknown, treat the result as provisional. A modest result that survives these checks is more informative than an impressive one that does not.
Frequently asked questions
How many trades does a backtest need?
There is no fixed number, but a few dozen trades say little about a strategy's long-run behaviour. More trades across different market conditions give more information.
Why do backtests look better than live results?
Typical reasons are underestimated costs and slippage, look-ahead or survivorship bias, overfitted parameters and changes in market behaviour after the test period.
Can AlgoStok backtest options strategies?
AlgoStok refuses option backtests that lack contract data rather than inventing prices. Historical testing features depend on the data available in your environment.