What is lookahead bias? How a test uses the future
By Oalgo · Last reviewed
Lookahead bias means a test uses information that was not yet known when the rule acted. It makes a backtest look better than the rules could have done at the time, because the rules saw something from the future.
When is each value of a candle known?
#| Value | Known when |
|---|---|
| Open | At the start of the candle |
| High | Only when the candle ends, because a higher price can still come |
| Low | Only when the candle ends, because a lower price can still come |
| Close | When the candle ends |
| A 20-candle Donchian upper line | When the current candle ends, because the line includes that candle's high |
How does lookahead bias creep in?
#- Acting on a value before it exists. A candle's close is only known when the candle ends. A rule that reads the close and fills at that same close assumes the order could be placed at that very price.
- Using a value that contains the candle itself. The upper line of a Donchian channel includes the current candle's high, so a rule that compares the candle with it compares the candle with itself. The breakout strategy page shows why such a rule reads the line from one candle earlier.
- Choosing the rules after seeing how the whole period turned out. You knew the future when you picked them, and the usual result is overfitting.
How does an Oalgo test avoid it?
#A backtest in Oalgo steps through the prices one candle at a time and applies your rules using only the data that existed at that moment.
The Entry Fill setting says where an entry fills. With Next open, which a new strategy starts with, a rule that fires on a candle's close fills at the next candle's open. With Trigger close, it fills at the close of the candle the rule fired on. Check which one a test used before you compare two reports.
How can you check your rules for it?
#- Read each condition and ask: at the moment this rule acts, is this value already known?
- Run a forward test. New prices cannot hold the future, because it has not happened yet.
- Look again at a result that seems too smooth, with very few losing trades.
A test with no lookahead can still be overfitted. This check says the rules used only what was known. It does not say they will hold up on new prices.
Read next
- What is overfitting?Overfitting is tuning rules so closely to past prices that they stop working on new ones. Learn why it fools people and how to check for it.
- What is paper trading? Practice with simulated fundsPaper trading is trading on live prices with simulated funds and no real order. Learn what it shows, what it cannot, and how Oalgo's forward test does it.