Look-Ahead Bias: Why Your Backtest Wins but Your Live Account Loses
2026-07-06
You build a strategy, backtest it, and the equity curve goes up and to the right. You go live, and within a month the account is bleeding. The single most common cause is not bad luck — it is look-ahead bias: your backtest quietly used information that would not have existed at the moment a real trade had to be placed.
Look-ahead bias is dangerous precisely because it feels like nothing is wrong. The code runs, the numbers are beautiful, and the bug is a single index offset or one careless assumption about candle data.
Form 1: Trading the same candle that generated the signal
An indicator value for a candle is only final when that candle closes. If your RSI crosses 50 on candle N and your backtest enters at candle N's open — or at its low — you traveled back in time. During the live candle, RSI was fluctuating; the cross you acted on had not happened yet.
Form 2: Take-profit and stop-loss in the same candle
Suppose your position has a TP at +3% and an SL at −2%, and one candle's high crosses the TP while its low crosses the SL. Which one was hit first? From OHLC data alone, you cannot know — the candle does not record the path price took inside it.
Optimistic backtests assume the TP filled first, and their win rate is inflated by exactly the trades that matter most (volatile candles). The defensible choice is the conservative one: when both are touched, assume the stop-loss filled first. Your backtest will look slightly worse than reality instead of much better. This engine applies stop-first priority on every ambiguous candle.
Form 3: Using a higher-timeframe candle before it closes
A popular filter: "only take long entries when the 4-hour trend is up." The subtle bug: at 10:00, the current 4-hour candle (08:00–12:00) is still open. If your backtest looks up the 4h indicator value by timestamp, it reads the final value of a candle that, live, was still being drawn — three out of four 1-hour bars inside that window would be gated by the future.
Higher-timeframe filters must only reference HTF candles that have fully closed before the current lower-timeframe candle opened. It is one of the most common and most destructive bugs in multi-timeframe strategies, because trend filters look brilliant when they know the future of the trend.
Form 4: Indicators computed over the whole dataset
Anything that normalizes, ranks, or scales using the full history leaks the future into the past: min-max scaling over all data, a z-score using the full-period mean, or picking "the top decile of volume" computed across years that had not happened yet. Every value your strategy reads at candle N must be computable from candles 0..N only.
Form 5: Two-sided entries inside one candle
Breakout systems that place both a buy-stop above and a sell-stop below run into the same path problem as Form 2: if one candle sweeps both levels, OHLC cannot tell you which side triggered first. Backtests that resolve this ambiguity in favor of the profitable side (often "always long first" in a rising market) manufacture an edge that does not exist.
How to check your own backtest
- Shift test:delay every entry by one candle. If the edge mostly disappears, the "edge" was information leakage, not market behavior.
- Too-good test: win rates above ~70% with tight take-profits, or equity curves without meaningful drawdowns, deserve suspicion — not celebration.
- Path-ambiguity audit: count candles where TP and SL were both touched. If they are a large share of your winners, your result is an assumption, not a measurement.
- Cross-implementation: if you can, re-implement the strategy independently (different code, same spec) and compare trade-by-trade. Disagreement means at least one implementation is lying.