What is look-ahead bias in backtesting?
In one line: Look-ahead bias is when a backtest uses information that wasn't available at the moment of the trade, which makes results look better than they could really be.
The idea
A fair test only uses what you could have known at that moment. Anything from later is cheating, even by accident.
Look-ahead bias is that accident.
Simple examples
The closing price. Your rule says "buy if today closes above yesterday's high." Your test buys at today's open. But at the open, you can't know how the day will close. The test used the future.
The candle that's still forming. On a 1-hour chart, a candle at 10:15 isn't finished. Its body could still change. A rule like "a body close past the level" only counts once the candle closes. See Candlestick.
Peeking on replay. You step forward on a chart, see the next big move, then "decide" to take the trade. That's look-ahead with your eyes.
Why it matters
Look-ahead bias can turn a losing rule into a winning one on paper. Say a fair test shows −5R over 100 trades. With look-ahead, the same rule might show +30R. A math example, not a promise.
You'd be trusting a number that was never possible.
A common mistake
Trusting code you didn't check. In Pine Script, pulling data from a bigger timeframe can leak future values if it's set up wrong. Pine's request.security() has a lookahead setting; with it on and no offset, a test can see a bar's final value too early. See Pine Script strategy backtest.
Our practice rule: on replay, never peek. Decide, log the trade, then step forward. See TradingView bar replay.
Look-ahead is the testing cousin of hindsight bias. More in how to backtest a trading strategy.
Questions
What is an example of look-ahead bias?
Buying at the open based on that same day's close. At the open, the close hasn't happened yet.
How do you avoid look-ahead bias in a backtest?
Only act on closed candles, enter on the next bar after a signal, check how your code pulls other timeframes, and never peek during manual replay.
Is look-ahead bias the same as overfitting?
No. Look-ahead uses data that didn't exist yet. Overfitting tunes rules too tightly to data that did exist. Both make tests look too good.
Want the next step? We'll walk you through it.
Four free lessons by email, one every few days — each with a 10-minute exercise on a real chart.
Send Me the Free Lessons 4 short emails · No spam · Unsubscribe anytimeOr see the whole method, step by step:
See What’s Inside the Course Try everything free first. Decide when you're ready. · Open the free chart tool (works in the TradingView phone app)One chart idea a day, in plain English. Follow along: