Look-ahead bias
Also called Lookahead bias, Look ahead bias, Peeking, Future leak, Future data leakage
Look-ahead bias is a backtesting error where a strategy uses information that was not yet available at the moment of the trade, such as a candle's close before that candle finished. It makes past results look better than live trading can deliver.
A test with this error does not crash or warn you. In the example below, 60% of the backtest profit is not real.
What look-ahead bias looks like inside a backtest
A backtest replays a trading rule over past prices to see how it would have done. In live trading you only know what has already happened. In a backtest the whole price history sits in one file, so a careless rule can read a value from the future without anyone noticing. The bias comes from how the rule reads that data.
The classic case is the same-candle entry. The rule says "buy when the 1-hour candle closes above its moving average" (the average price of the last several candles). The test then fills the order at that candle's open. The close was unknown at the open, so the test has traded on a price that did not exist yet.
| Where the future leaks in | What the test wrongly knows | Honest version |
|---|---|---|
| Same-candle entry | The close of a candle still forming | Enter at the next candle's open |
| Higher-timeframe filter | The daily close while the day is still running | Use the last finished daily candle |
| Swing high or low signals | That a turn was confirmed by later candles | Count the signal only on the candle that confirms it |
| Day's high or low as a level | The full day's range at the morning entry | Use the previous day's range |
Rules that remove the leak:
- If your rule needs a candle's close, high or low, read it from the last finished candle and enter at the next candle's open.
- If it needs a higher timeframe, read the last finished higher-timeframe candle, never the one still forming.
- If it needs a swing high or low, date the signal to the candle that confirmed it, not to the turning candle itself.
The drawing below shows why the higher-timeframe rule matters. At a morning entry, today's daily candle has barely started.
Indicators that redraw past signals as new candles arrive, known as repainting, cause the same problem. Their history shows the final, corrected signals, not what was on screen at the time.
How a peeked close inflates profit: a worked example
The figures below are an illustrative example, not real market prices. You trade 0.10 lot (10,000 units) on a USD-quoted pair, so one pip is worth $1.
The signal candle opens at 1.1000 and closes at 1.1030. The next candle opens at 1.1030. The trade exits at 1.1050.
The drawing above shows the two entries. The biased test buys at 1.1000 and banks 50 pips. The honest test can only act after the close, buys at 1.1030 and banks 20 pips.
Here the phantom profit equals the signal candle's body, 30 pips, because the next candle opens exactly at the signal candle's close. If price gaps between that close and the next open, the head start grows or shrinks by the size of the gap. Rules that trigger on big breakout candles therefore get the biggest free head start.
The same 30 pips can flip a loser into a winner. A trade that honestly loses 10 pips shows as -10 + 30 = +20 pips in the biased test.
Checks to run before you trust a backtest
- Shift test. Delay every entry by one candle and rerun. If profit collapses, suspect a leak and confirm it with the replay test before trusting the result.
- Timestamp test. For each input, ask "at what time was this number final?" If that is later than the entry time, remove it or use the previous finished value instead.
- Replay test. Step through 20 trades one candle at a time and confirm the signal appears before the fill, not on the same candle's open.
- Too-clean test. Treat an equity curve (the line of your account balance over the test) with almost no losing streaks as a warning sign, not a result.
- Live comparison. Run the rule on a demo account for a few weeks. If the live signals differ from the backtest signals for the same dates, find out why before risking money.
FAQ
Can look-ahead bias happen when I backtest by hand?
Yes. When you scroll back on a chart you can see what price did next, and that shapes which setups you "would have taken". Hide the right side of the chart or use a candle-by-candle replay mode, and write down the decision before revealing the next candle.
How do I know if my indicator repaints?
Watch it on a live chart instead of on history. Note each signal and its time as it appears, then look at the same candles a few hours later. If a signal has moved, vanished or appeared on a candle that had none, the indicator repaints and its past signals cannot be backtested as shown.
What is the difference between look-ahead bias and overfitting?
Look-ahead bias uses data from after the trade. Overfitting uses only past data but tunes the settings so tightly to it that the rule fits noise. A test can suffer from both, and each needs its own check.









