Glossary

What is lookahead bias?

Lookahead bias means a backtest uses information that did not exist yet at the time of the simulated trade, such as the final high of a day that is not over.

On historical bars the future is already in the data, so a script can read it by mistake; in real time it does not exist. TradingView calls lookahead bias a common cause of unrealistic strategy results. The classic Pine Script case is request.security() with lookahead = barmerge.lookahead_on and no [1] offset, which returns the final value of a higher-timeframe bar on every historical bar.

The fix for higher-timeframe data is to request the previous, confirmed value: high[1] together with lookahead_on. The two belong together; remove either and the request is no longer safe. Forward testing on real-time data can often confirm the bias, because there is no future data to leak.

In practice

In our repainting guide, a hypothetical leaky line books about +1.99% per trade before fees; on 30 such days a year, reinvested, that compounds to roughly +81% – from signals a live strategy could never have seen.

Illustrative numbers from the post, not a backtest result.

Read more

Topic: Data pitfalls

Part of the guide: Overfitting and luck

Sources