Skip to content
MT5MT4soonTradingViewsooncTradersoonNinjaTradersoonPythonsoon
Backtesting & statistics

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 inWhat the test wrongly knowsHonest version
Same-candle entryThe close of a candle still formingEnter at the next candle's open
Higher-timeframe filterThe daily close while the day is still runningUse the last finished daily candle
Swing high or low signalsThat a turn was confirmed by later candlesCount the signal only on the candle that confirms it
Day's high or low as a levelThe full day's range at the morning entryUse 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.

Higher-timeframe filter: at a 09:00 entry, today's daily candle is only partly formed and its close is still far ahead
Illustrative candles. At the 09:00 entry, most of today's daily candle has not formed yet. A filter that reads today's daily close is using a price from the future, so use yesterday's finished daily candle.

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.

Repainting indicator: a buy signal shown live moves to a later candle on the history chart
Illustrative candles. The history chart shows only the corrected signal on candle 6. The candle 4 signal you actually saw live is gone, so a backtest on this history never sees it.

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.

Look-ahead bias: biased entry at the signal candle's open versus honest entry at the next open
The signal only exists once the highlighted candle has closed. An entry on the highlighted candle, before the dashed line, used a close that did not exist yet.

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.

How much of the backtest profit came from look-ahead bias
Biased result per trade50 × $1= $50
Honest result per trade20 × $1= $20
Phantom profit per trade$50 - $20= $30
Over 100 similar trades$30 × 100= $3,000
Profit that never existed$3,000

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.

The 30-pip head start from look-ahead bias, on a winning trade and on a losing trade
The biased test adds the same 30 pips to every trade. On the losing trade that is enough to carry the result from -10 across zero to +20.

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.

Related terms