VALYNOXSTRATEGY RESEARCH TECHNOLOGY
AlphaPrimeAlphaPrime
ACADEMY / Backtesting and validation

Look-ahead bias in backtests: common leaks and a one-bar check

Look-ahead bias means a backtest used information that did not exist yet when the trade was decided. Delay every order by one bar and compare: a real edge weakens a little, while a leaked edge usually collapses.

By · Published · updated · Editorial policy

Contents
  1. What is look-ahead bias?
  2. How does future information leak into a backtest?
  3. Entering at the close of the signal bar
  4. Revised and adjusted data
  5. Daily values used inside the day
  6. Wrong session and time alignment
  7. How do you check for look-ahead bias with a one-bar shift?
  8. What if the shift test is not clear?
  9. How is look-ahead bias different from overfitting and survivorship bias?
  10. Frequently asked questions
  11. References

What is look-ahead bias?

Look-ahead bias is the error of letting a backtest use information that was not yet available when the trade decision was made. It usually enters through same-bar fills, revised data, daily values used inside the day, or misaligned sessions. To check, delay every signal by one bar. If the results collapse, look for a leak.

Imagine betting on yesterday's football match while you hold today's newspaper. You would win every bet, and the wins would teach you nothing about betting. A backtest with a leak works the same way. It shows how well the rules can use the answer, not how well they predict. Chinese-speaking traders call this error 前視偏誤. Code that reads a future value is often called a 未來函數, which means "future function".

A leak almost always makes results better, so the usual symptom is a test that looks too good. Look for these signs:

  • The equity curve is close to a straight line, with very small drawdowns.
  • The win rate is much higher than other strategies of the same type on the same market.
  • Many entries happen at or very near the best price of their bar.
  • The strategy stops working on the first day of live or paper trading, not slowly over months.

How does future information leak into a backtest?

Most leaks come from four places, and each one has a simple fix.

LeakWhat happensFix
Same-bar close used for entryThe rule decides on the bar's close and also fills at that close.Fill on the next bar.
Revised or adjusted dataThe test sees corrected values or settlement prices that were published later.Use values as they were first known at that time.
End-of-day values used intradayAn intraday rule reads today's high, low or close before the day is over.Use only the last completed daily bar.
Wrong session alignmentTwo data series, or a series and its session, use different clocks or bar labels.Use one time zone and one timestamp convention for all data.

Entering at the close of the signal bar

A rule that is calculated on a bar's close cannot also trade at that close. You only know the closing price once the bar has ended, and by then the market has moved on. Next-bar execution is the rule that an order triggered by a bar's close is filled on the following bar, usually at its open. AlphaPrime (Valynox) evaluates each candidate with next-bar execution, fees and slippage in its backtesting, so this leak is closed by the setting itself.

A quieter version of this leak happens inside the bar. A rule such as "if the bar's high breaks a level, buy at the bar's low" assumes that the low came before the high. A bar only shows four prices, not their order. The same problem appears when a stop and a target both fall inside one bar and the test assumes the target was hit first.

Three bars on a time axis: the signal is known only at the close of Bar 1, so a fill at that close is not possible; a realistic fill uses the open of Bar 2, which is next-bar execution Fill on the next bar The signal is known only at the close Bar 1 Bar 2 Bar 3 Fill at close: no Fill at next open The close can't also be the fill. So: fill on the next bar.
The close that triggers a signal cannot also be the fill price. A realistic fill comes from the next bar.

Revised and adjusted data

Data that was corrected or recalculated later can carry future knowledge into the past. Point-in-time data is data stored exactly as it was known on each date, before any later revision. Three common cases:

  • Economic releases. Many reports are revised after their first publication. A rule that trades on the revised value is trading on a number nobody had on release day.
  • Settlement prices. An exchange sets the daily settlement price after trading ends. A rule that uses it as the price of an entry during the same day is using a later number.
  • Back-adjusted continuous contracts. A back-adjusted continuous contract is a joined series of futures contracts in which older prices are shifted at each roll to remove the price gap. Every new roll can change all earlier prices. A rule that compares price with a fixed level, or uses percentage changes, can then trigger on different bars than it did when those bars were live.

The guide to backtest data quality: gaps, bad ticks, time zones and rolls covers how to inspect a data file for these problems before you test anything on it.

Daily values used inside the day

An intraday rule must use only daily values from days that have already ended. On historical charts, the current day's bar often appears with its final high, low and close, and code can read those values from the first minute of the day. Typical leaks:

  • A filter such as "trade only on days with a wide range", where the range is today's range.
  • A daily volatility value that includes today's bar.
  • Pivot levels calculated from today's high, low and close instead of the previous day's.
  • A higher-timeframe trend filter that reads a weekly or daily bar before that bar has closed.

The fix is the same in every case: refer to the last completed bar of the higher timeframe. In plain words, use yesterday's values on today's chart.

Wrong session and time alignment

When two pieces of data are matched on the wrong clock, one of them can see minutes or hours ahead. Some data sources label a bar with its start time, and others label it with its end time. If you merge one of each, the row labelled 09:00 holds a bar from 09:00 to 09:05 next to a bar from 08:55 to 09:00. The first series now sees five minutes into the future.

Two data series both labelled 09:00: Series X covers 09:00 to 09:05 and Series Y covers 08:55 to 09:00, so after merging, Series X sees five minutes ahead of Series Y Same label, other minutes Both rows carry the label 09:00 5 min ahead Series X Series Y 08:55 09:00 09:05 One row sees 5 minutes ahead. So: one timestamp rule for all.
Two data series both say 09:00 but cover different minutes. Merged together, one series looks five minutes ahead.

Time zones cause the same problem on a larger scale. A US index future and a Taiwan market series compared in different clocks can line up the wrong hours. The gap also moves by one hour when US daylight saving time starts or ends, because Taiwan does not change its clocks. Daily bars are another trap. A futures "day" that starts the evening before is a different bar from a calendar day that starts at midnight. Session hours come from the exchange's contract page, and exchanges can change them, so check the current values there. The futures market hours tool shows trading hours by exchange and session in your own time zone.

How do you check for look-ahead bias with a one-bar shift?

Delay every order by one more bar and compare the results. A large drop is the clearest sign that a signal depends on data it could not see. The test works because a real edge rarely depends on the exact bar. A leaked edge does, because the leak gives information about that exact bar.

  1. Run the strategy with your normal settings, with costs included. Save the net average trade, the number of trades, the win rate and the maximum drawdown.
  2. Change only the execution: every entry and exit now happens one bar later than before. If the test filled at the signal bar's close, the first fix is the next bar's open. Then shift once more.
  3. Run the test again on the same data and the same costs.
  4. Compare the two sets of numbers side by side.
  5. Read the change with the table below.

Hypothetical example

Strategy A trades 5-minute index futures bars and makes 400 trades. With next-bar execution, its average trade after costs is $120. Delayed by one more bar, it falls to $15. Strategy B uses the same data and has an average trade of $60, which falls to $48 after the delay. A five-minute delay removed seven-eighths of Strategy A's edge. Strategy B kept four-fifths of its edge. Strategy A is the one to inspect.

Hypothetical example: after a one-bar delay, Strategy A's average trade falls from 120 dollars to 15 dollars, while Strategy B's falls only from 60 dollars to 48 dollars Which edge survives? Average trade, hypothetical Strategy A Strategy B $120 $15 $60 $48 Before After Before After A lost 7/8 of its edge; B kept 4/5. So: inspect Strategy A's inputs.
Hypothetical example: after a one-bar delay, Strategy A's average trade collapses and Strategy B's barely moves.
Result after the shiftWhat it suggestsNext step
Average trade falls a little, trade count similarThe edge does not depend on the exact bar.Move on to other validation.
Average trade falls by most of its valueThe edge depends on one bar's information. This can be a leak, or a very short-term edge.Run the cut-off test below.
Average trade turns negativeA leak is likely, especially if the strategy holds trades for many bars.Audit every input.
Average trade risesUsually random variation from different fill prices.No action needed.

What if the shift test is not clear?

Use the cut-off test, which catches leaks that the shift test can miss. A strategy that holds trades for one or two bars can lose much of its edge from a delay even without a leak. In that case, check whether old signals change when new data arrives:

  1. Cut the data at a chosen date and run the strategy. Save the list of trades.
  2. Run it again on the full data.
  3. Compare every trade before the cut-off date. Each one should have the same bar, direction and price in both runs.
  4. Any trade that changed used data from after its own bar. Indicators that confirm a swing high only after later bars, and series that were re-adjusted at a later roll, show up here.

Finish with a short input audit. Write each input of the strategy in one column. Next to it, write the exact moment that value becomes known, and compare it with the moment the order is sent. This takes a few minutes and finds the daily-value and time-zone leaks directly.

How is look-ahead bias different from overfitting and survivorship bias?

All three make a backtest look better than live trading, but each one comes from a different place and needs a different check. Overfitting is the error of picking rules or parameters that match random patterns in past data rather than a repeatable effect. Survivorship bias is the error of testing only on instruments that survived to today.

Look-ahead biasOverfittingSurvivorship bias
What goes wrongA rule reads data from after its decision time.Rules are chosen because they fit noise in the history.Only markets or instruments that still exist are tested.
Where it comes fromData timing and codeTesting many variants and keeping the bestHow the list of instruments was chosen
Typical signResults collapse after a one-bar delay.Results fall sharply on data not used for the choice.Results fall when delisted or expired instruments are added.
How to checkShift test, cut-off test, input auditOut-of-sample tests, walk-forward analysisRebuild the instrument list as it was on each past date.

With overfitting, each bar can be clean, yet the selection still used the whole history. Bailey and colleagues (2014) show that when many variants are tested, the best backtest is likely to perform much worse out of sample. The guide to overfitting in strategy generation explains how to keep a large search honest.

The two errors meet in one place: parameter choice. If you choose parameters on the full history and then report results on that same history, the parameters carry future information into every past trade. Walk-forward analysis removes this, because each out-of-sample period is traded with parameters chosen before it.

A stock universe built from today's index members leaves out the companies that failed. In futures, the same survivorship error happens when you test only the markets that are popular now, or only stock futures whose stocks are still listed.

What this means if you use AlphaPrime: next-bar execution and trading session settings are part of every evaluation, so the same-bar fill leak is already handled. Your part is the data and the strategy's inputs. Use one time zone and one timestamp convention, and leave out revised or re-adjusted values the strategy could not have seen. Then run the shift test and walk-forward analysis on the strategies you plan to keep.

Frequently asked questions

What is look-ahead bias in simple terms?

Look-ahead bias means a backtest used information that did not exist yet when the trade was decided. A common example is buying at a bar's close because of a signal calculated on that same close. The result looks better than anything a live trader could have done.

What does 未來函數 mean in backtesting?

未來函數, or "future function", is the Chinese trading term for code or an indicator that reads values from later bars. A strategy that uses one shows look-ahead bias, often called 前視偏誤. The one-bar shift test and the cut-off test both reveal it.

Does next-bar execution remove look-ahead bias completely?

No. Next-bar execution removes the same-bar fill leak only. Revised data, daily values read during the day and mismatched timestamps can still leak future information. Check those with the cut-off test and an input audit.

Can a strategy lose most of its edge after a one-bar shift and still be valid?

Yes, if it is a very short-term strategy that holds trades for only one or two bars. Its edge can fade quickly without any leak. Use the cut-off test to decide: if no past trade changes when new data is added, the drop comes from timing, not from future data.

Is repainting the same as look-ahead bias?

Repainting is one cause of look-ahead bias. A repainting indicator changes its past values after later bars arrive, so the history shows signals that were not there in real time. A backtest that trades those signals is using future data.

References

  • Bailey, D. H., Borwein, J., López de Prado, M., & Zhu, Q. J. (2014). Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the American Mathematical Society, 61(5), 458–471.

What AlphaPrime does here

AlphaPrime's backtesting evaluates each candidate with next-bar execution, fees, slippage and trading sessions. Its strategy validation adds Basic, Standard and Extensive validation with walk-forward analysis, so parameter choice stays separate from out-of-sample results.

See plans and pricing