← Backtesting guide

Look-Ahead Bias

Look-ahead bias (also called data snooping or future leak) occurs when a backtest uses information that would not have been available at the exact moment a trade decision was made. It is one of the most insidious bugs in backtesting because it produces spectacular results that silently evaporate in live trading.

Common sources of look-ahead bias

The most common source is using the close price of the current bar as the entry price — you cannot fill at the close if your signal is generated on the close. Other sources include using a rolling mean computed over the entire dataset (including future bars), adjusting for corporate actions using data that did not exist at trade time, and selecting the best strategy parameters over the full in-sample period.

How to prevent look-ahead bias

Process your data bar-by-bar, strictly in time order. Only use data up to and including the current bar when computing indicators. Enter at the open of the next bar after your signal fires, not at the current bar's close. Use a vectorised backtesting library that enforces this discipline (such as zipline, which backtester.run uses).

Next: In-sample vs. out-of-sample →

© 2026 backtester.run · All rights reserved · support@backtester.run

Backtest results are hypothetical and do not guarantee future performance.