Look-ahead bias: when a backtest sees the future

Look-ahead bias lets a backtest use information it could not have had. See how same-bar fills and revised data inflate results, and how to check for it.

Part of the Backtesting and Research track on Agenticks. About 11 minutes, written for a advanced reader.

Read first: What is backtesting, Turning an idea into a testable rule set.

Last reviewed .

Risk notice. Backtested and hypothetical results are simulated: no trades were placed, the rules were applied to past data with the benefit of hindsight, and they may not reflect liquidity, slippage or every cost. Past results, real or simulated, do not predict future results.

Key takeaways

Imagine sitting an exam with tomorrow's newspaper in your bag. You would ace it, and the score would say nothing about what you know. Look-ahead bias is the backtesting version of that: the test uses information that would not have been available at the moment a trade was taken. It is rarely deliberate. It hides in the plumbing of a test, in how fills are timed, which version of a data series was loaded, or how an indicator was calculated. The result is a backtest that looks brilliant for reasons no trader could ever have used. Standard references on backtesting list it beside survivorship bias and ignored trading costs as one of the classic ways a test lies. The question that catches it is always the same: at the exact moment this trade was taken, could anyone have known this? If the answer is no for even one input, the result is contaminated.

Only use what was known at the time

Every price, figure and indicator value a rule reads has a moment when it became known. A fair backtest only lets a decision use values that existed before that decision. Anything later, even by a few seconds, is a leak from the future.

Look-ahead bias gets in through three main doors. 1. Same-bar fills. A rule says "buy when today's bar closes above yesterday's high." The close only exists when the bar ends. If the test buys at that same bar's open, or at its low, it is acting on a close that had not happened yet. The honest version waits: the signal appears at the close, and the earliest fill is the next bar's open. 2. Revised data. Many figures change after they are first published. Economic numbers like GDP and employment are revised, sometimes several times, and company accounts can be restated. A test that uses today's corrected numbers for past dates is trading on information that arrived months or years later. Researchers keep "vintages", snapshots of each series as it looked on each date, precisely so tests can avoid this. Studies built on those snapshots show that the revised and first-release versions of the same series can tell different stories. Data kept as it stood on each date is called point-in-time data. 3. Indicators that change their past. Some indicators redraw earlier values once new bars arrive, which is called repainting. Others quietly use the whole dataset: a moving average centred on each bar (half its inputs are in the future), a swing high that is only confirmed several bars later but is plotted on the original bar, or scaling every value by the highest price in the full sample. On a finished chart they look perfect, because the chart already knows how things turned out.

Worked example: buying a bar before you could see it

The rule: buy when today's close is above yesterday's high, then exit at a later target. Here is one trade, filled two ways.

Signal bar (The close is above yesterday's high, so the signal fires at the close)Opens $100.00, closes $101.50
Peeking fill (The open of the bar whose close created the signal: impossible in real time)Buy at $100.00
Honest fill (The next bar's open, the first price available after the signal)Buy at $101.60
Exit (The same exit for both versions)$102.00
Profit per share, peeking (102.00 - 100.00)+$2.00
Profit per share, honest (102.00 - 101.60)+$0.40
200 trades of 100 shares, $1.00 a share of peeking on average (200 x 100 x $1.00 of profit that never existed)$20,000
Same rule, same tradesOne version is mostly fiction

Illustrative numbers, not a real test.

The worked example shows why this bias is so dangerous. The rule did not change. The trades did not change. Only the timing of the fill changed, and that alone moved most of the profit from real to imaginary. Over hundreds of trades a small, consistent peek adds up to a large, consistent fake edge. That is also why look-ahead bias produces results that feel too good: very high win rates on simple rules, equity curves with almost no losing stretches, and entries that land at the exact low of the bar again and again. Real trading is messier than that. When a result looks like it knew what was coming, it may well have. It is worth comparing this with overfitting. Overfitting bends the rules around past noise. Look-ahead bias does not need any bending at all: a perfectly simple rule can show a fantastic result if the test lets it see one bar ahead.

Known at the time
Yesterday's closing price, used to decide today's entry, A 20-day moving average ending at the last closed bar, An earnings figure as first reported, on its release date
Look-ahead leak
Today's close, used to buy at today's open, A GDP figure as revised two years later, applied to its original release date, This year's list of index members, used to pick stocks in 2010

You do not need special software to hunt for look-ahead bias. A few habits catch most of it. Run a one-bar delay test. Shift every entry one bar later and run the same test on the same data. A real edge usually loses a little, because you give up some of the move. An edge built on peeking tends to collapse, because the peek was the edge. Read individual trades. Pick ten trades and check each one on the chart. At the entry time, did every number the rule used already exist? Was the fill a price that actually traded after the signal? Ask where each number came from. For any economic or company figure, find out whether it is the first-published value or today's revised one. If you cannot tell, assume it is revised. Be suspicious of indicators that look perfect. If an indicator's signals line up with every turning point, check whether its past values change when new bars arrive. Distrust perfection in general. A simple rule with a win rate far above anything you have seen elsewhere deserves an audit before a celebration.

Put the steps of a one-bar delay test in order.

  1. Write down the original result: trade count, expectancy and win rate
  2. Move every entry to the open of the bar after the signal
  3. Run the same rules again on the same data
  4. Compare: a small drop is normal, a collapse points to a leak

A simple moving-average rule shows a 91% win rate. Moving every entry one bar later drops it to 48%. What is the most likely explanation? The original test was using information from the signal bar that was not available at the entry Right. A real edge does not vanish because the entry moved one bar. A drop that large means the first version was peeking.

Look-ahead bias has a close cousin: survivorship bias, which comes from testing only on the companies, funds or coins that still exist today. Choosing them is itself a peek at the future, because you already know they made it. The defence is the same for both: data recorded as it stood on each date. It also interacts with transaction costs. Moving a fill from the signal bar to the next bar's open is not only more honest, it usually means a worse price, and that price plus the costs of trading is what a real account would have seen. A test that gets the timing and the costs right will almost always look worse than one that gets them wrong. That is the point.

You can spot a backtest that sees the future

You know the three main sources of look-ahead bias, how a single bar of peeking turns into a large fake edge, and how a one-bar delay test exposes it.

Check your understanding

In the worked example, why is the $100.00 entry impossible in real trading?
The signal needed that bar's close, which did not exist yet when the bar opened. Right. At 100.00 nobody knew the bar would close above yesterday's high, so no real trader could have bought there for that reason.
A rule trades on monthly jobs reports. Which version of the data is safe to backtest on?
Each figure exactly as it was first released, on its release date. That is point-in-time data. It holds only what traders actually saw that day, before any revision.
Why is testing on today's list of index members a form of look-ahead bias?
Today's list already knows which companies grew large enough to stay in the index. Exactly. Picking from today's members uses knowledge of who survived and succeeded, which no trader had in the past.

Common questions

What is look-ahead bias in a backtest?
It is when a backtest uses information that was not available at the time a trade was taken, such as a closing price used to enter at that bar's open, or an economic figure that was revised months later. It makes the results look better than anything a real trader could have achieved.
How do I check a backtest for look-ahead bias?
Delay every entry by one bar and run the test again. A real edge usually shrinks a little; a result built on peeking tends to collapse. Then open a handful of trades and confirm on the chart that every input existed before the entry.
Is survivorship bias the same as look-ahead bias?
It is a close relative. Testing only on companies that still exist uses knowledge of which ones would survive, which is a kind of information from the future. The fix for both is data recorded as it stood on each date.

Terms defined in this lesson

Continue

Sources

Written and reviewed by the Agenticks Learn editorial team. How we write and check lessons.

Agenticks Learn is general education. It is not financial, investment, tax or legal advice, it does not take your situation into account, and nothing on it is a recommendation to buy, sell or hold any security or to open any account. Examples use illustrative numbers. Investing involves risk, including losing money you put in, and past performance does not predict future results. Tax rules and limits change; the official sources linked in each lesson are the final word.