Skip to content

GuideBacktest vs. live

Look-ahead bias in backtesting: what it is, with examples

Look-ahead bias is a backtest using information that didn’t exist yet when the trade was placed. In bar-based strategies it hides in fills, timestamps, late-confirmed patterns and rebuilt prices; here’s how to find and fix it.

Key takeaways

  • Look-ahead bias means a backtest used information that wasn’t available yet at the moment of the trade.
  • In bar-based strategies it usually hides in timing: a bar’s close, a pattern that needs later bars, or a higher time frame that hasn’t finished.
  • For every input, write down the moment it becomes known. A rule may only use what’s known before its order goes in.
  • Delaying every entry by one bar is a quick check: a collapse is a reason to recheck input timing, not proof of a peek.

Look-ahead bias in backtesting is the use of information that wasn’t available yet at the moment a trade would have been placed. The classic case is a rule that waits for a bar to close and then buys at that same bar’s open. The test books a price no trader could have had, so the results look better than anything you could repeat live.

The same idea applies to any study of the past: if it uses data from after the moment it simulates, it has look-ahead bias. In trading backtests it’s rarely deliberate. Below are seven common examples from bar-based futures strategies, and how to check for and avoid them.

What are examples of look-ahead bias in trading?

The common examples in bar-based trading are filling at the signal bar’s open, misreading bar timestamps, marking swings and gaps too early, reading unfinished higher time frames, trusting back-adjusted price levels, setting cutoffs from the whole history and using revised data.

1. Deciding on the close, filling at the open

A rule like “buy when the bar closes above the last 20-bar high” can’t act until that bar has closed. If the backtest fills the order at the same bar’s open, or anywhere inside it, it buys before the signal existed. A fill at the signal bar’s close is fair only if the rule could decide just before the close.

Filling before the signal existed
A breakout rule’s signal only exists once the bar closes above the level. A backtest that fills at that same bar’s open buys before the signal existed, and books the bar’s open-to-close move as a head start, trade after trade. The honest fill comes at the next bar’s open. Computer-drawn illustration, not real market data.

Honest version: fill at the next bar’s open.

2. Bar timestamps

Many charts label a bar by the time it opens. A 1-hour bar marked 10:00 covers 10:00 to 10:59, and its close isn’t known until 11:00. A rule that uses the 10:00 bar’s close at 10:00 is looking an hour ahead.

Honest version: use a bar’s close only from the time the bar ends.

3. Patterns that need later bars

Some patterns only exist once later bars have closed. A swing high defined as a peak with two lower highs on each side is confirmed two bars after the peak. A three-bar gap, such as an ICT fair value gap (a gap between the first bar’s high and the third bar’s low, or the reverse in a falling market), is only known when the third bar closes. A backtest that marks either one at the bar where it starts is trading on bars that hadn’t happened yet.

For example, take a made-up rule that sells every swing high. Marked at the peak bar, the backtest can sell at the peak itself, the exact top of every swing, a fill no trader gets. Marked at its confirming bar, the entry comes two bars later and below the peak, often well below.

Honest version: mark each swing or gap at the bar that confirms it.

4. Higher time frames and sessions that haven’t finished

Reading the day’s high, the day’s close or a 4-hour average during that day or those four hours uses a value that isn’t final yet. The same goes for session ranges: the Asian range or a 30-minute opening range is final only when its window closes. A rule that trades a break of the range high can’t know that high until then.

Honest version: use only the last completed higher-time-frame bar or session.

5. Prices that were rebuilt later

Long futures histories are usually continuous contracts: each expiring contract is joined to the next. In a back-adjusted series, the usual method shifts every older price by the gap at each rollover so the joins don’t leave jumps. A 10-point move stays a 10-point move, but old price levels move again with every new roll (RealTest user guide; TradeStation help). A rule built on exact old levels is then using prices that never traded, set by rolls that came later.

Honest version: use point distances on back-adjusted data, and the actual contracts for rules about exact levels.

6. Cutoffs set from the whole history

Setting a cutoff from the whole history lets early trades use later years. For example, a filter that only trades when volume is in the top 20% peeks if that top 20% was measured across all the data, including years after the trade. Machine learning calls this data leakage. The scikit-learn guide shows that picking inputs using all the data, test part included, makes a model built on random numbers look 76% accurate instead of the 50% it really is (scikit-learn).

Honest version: set every cutoff from earlier data only, as in walk-forward analysis.

7. Data that was revised

Economic numbers are often revised, and many databases keep only the latest figure. Testing a news rule on the revised figure uses a number no trader had at the time (AnalystPrep; Vontobel).

Honest version: use first-released values at their real release time.

When does each input become known?

Every input has a moment it becomes final, and a rule may only use it after that moment. This table lists the common ones.

Input Final when Earliest honest use
A bar’s close, high or low The bar closes The next bar
A 1-hour bar labeled 10:00 11:00 11:00 or later
A swing high, two bars each side Two bars after the peak After the second bar closes
A three-bar gap The third bar closes After the third bar
A session range (Asian, opening range) The window closes After the window closes
The day’s high, low or close The session ends The next session
A cutoff tuned on history The tuning data ends Later data only
An economic number that gets revised Each figure at its own release time The first-released value, from its release time

How much can one peek change a result?

One peek can turn a losing rule into a winning one: in the made-up example below, a 6-point head start on 50 trades turns a 100-point loss into a 200-point gain.

The head start isn’t an accident. A breakout rule only fires on bars that pushed through a level, so their open is usually below their close. Filling at the open hands the rule the very move that triggered it. A rule that bets against a bar’s move gets a worse price instead, so the same slip can also make a strategy look worse than it is.

A published teaching example shows the same effect. Built on five made-up stocks over four quarters, its momentum rule (buying recent winners) picked the two best performers of the current quarter instead of the previous one. That raised the average quarterly return from 0.50% to 6.50%, and the Sharpe ratio (return per unit of risk) from 0.09 to 2.08 (Vontobel).

How do you check your backtest for look-ahead bias?

To check a backtest for look-ahead bias, write down when each input becomes known, then confirm it with a one-bar-delay re-run and a bar-by-bar replay.

  1. Write down when each input is known. For every value your rules use, note the moment it becomes final. A rule may only use what’s known before its order goes in. Use the table above as a starting point.
  2. Delay every entry by one bar and re-run. A same-bar peek usually makes results collapse, but a real edge in fast entries can weaken too, so a collapse is a reason to check the timing, not proof of a peek (look-ahead bias in the live-trading guide).
  3. Replay a few winning trades bar by bar. At the entry, could you have seen every condition on the chart? If the honest answer is “only after the next bar”, you’ve found it.
  4. Be wary of smooth results. An equity curve with almost no losing stretches is one of the classic warning signs (is your backtest overfit?).

How do you fix and avoid look-ahead bias?

To avoid look-ahead bias, let every rule use only values that were final before its order goes in: fill at the next bar’s open, mark patterns at their confirming bar and set cutoffs from earlier data only. When you find a peek, fix the rule, re-run the whole test and judge the new result as if it were a first try. Don’t tune until the old numbers come back, because that swaps one problem for overfitting. For your next strategy, write the timing table before you write the rules. Often the honest answer is that most of the edge was the peek, and history is the cheapest place to find that out.

Sources and further reading

Questions people ask

Is look-ahead bias the same as overfitting?

No. Overfitting fits the noise in past data, while look-ahead bias uses data from the future. Both make a backtest look better than live trading, and a strategy can suffer from both at once.

Is a repainting indicator look-ahead bias?

In effect, yes: if an indicator changes its past values when new bars arrive, its history shows what it knew later, not what you’d have seen live. Test it on values recorded bar by bar, or only use a signal after its last bar has closed. Higher-time-frame values that a charting script requests with a look-ahead setting turned on, without shifting back to the last finished bar, do the same on history: they show each bigger bar’s final value before it closed.

Is a stop and target hit in the same bar look-ahead bias?

A stop and target hit in the same bar isn’t strictly look-ahead bias, but it has the same effect. One bar can’t show whether the stop or the target came first, so the backtest has to assume an order, and an optimistic one hands the strategy wins nobody could count on.

Can manual backtesting have look-ahead bias?

Yes. Scrolling through a chart with the later bars visible makes it easy to pick setups you’d have skipped, or to hold winners you’d have closed. A replay mode that hides the bars to the right helps, but you still have to mark each swing or gap only at the bar that confirms it.

Does tick or 1-minute data remove look-ahead bias?

Tick or 1-minute data removes most of the guessing inside each bar, but not the timing mistakes. A rule that reads a value before it’s final peeks just as much on tick data.

Can forward testing have look-ahead bias?

Forward testing can’t peek in its trades, because the future hasn’t happened yet. It can still mislead you if you judge it with indicators or levels that were recalculated later, such as a repainted signal on the chart.

General education about testing strategies, not investment advice. Figures are computer-drawn illustrations, not real market data.