1. Valmy
  2. Learn
  3. Testing ideas
  4. X3

What is look-ahead bias, and how does it get into a backtest?

Intermediate 14 min read

Short answerLook-ahead bias is a backtest's use of information that was not available when the trading decision had to be made. It gets in through small shortcuts, such as filling a trade at a price from the same candle whose close produced the signal, or selling at a candle's high before that candle has finished. The simulated trader then acts on the future, so the result usually looks better than any real trader could have done. In the synthetic example below, the same rule on the same random candles made +0.9% with honest fills at the next candle's open and +14.5% when it was allowed to sell at the high of the exit candle.

Other routes in are indicators computed with later prices (a centered average, or a value scaled by the whole period's range), data revised afterward, testing only markets that still exist today and misaligned timestamps. Asking of every input "could a trader have known this at the decision time?" lets you reject a flattering backtest before it talks you into trading a losing rule.

Valmy noteAs specified on 25 November 2026, Valmy's backtests evaluate a strategy when a five-minute candle closes and simulate the earliest execution on a later candle, never at a price from the signal candle. That rule keeps same-candle fills out of Valmy's backtests. It does not protect analysis done elsewhere, and details in the live app could differ, so check them there. Nothing in this lesson is a recommendation to trade a rule.

What look-ahead bias is: using information before it existed#

Every decision in a backtest has a decision time: the moment the rule decides to buy or sell. Only information that existed at that moment may be used, and the trade can only happen at a price available after it. Look-ahead bias is any break in that order. The test is a simple question for each input: at the decision time, could a real trader have known this value?

For a rule evaluated on closed candles, the decision time is the close of the signal candle. At that moment the trader knows that candle's open, high, low and close and everything before it. The trader does not know the next candle's prices, any value computed from them, or any correction published later. The earliest realistic fill is the next candle's open, plus spread and slippage.

The bias is dangerous because it rarely looks like cheating. It usually comes from a reasonable shortcut in a spreadsheet or script, and it makes results look better in a way that feels plausible.

Same-candle fills: trading at a price the rule had not yet seen#

The most direct form of look-ahead bias is filling a trade with a price from the candle that produced the signal. There are two versions, and they differ a lot in size.

Filling at the signal candle's close#

A rule that buys "when the close crosses above the average" learns the close at the end of the candle. A backtest that fills at that same close assumes the order executed at the very last trade of the candle, with no delay and no spread. In a market that trades around the clock, the next candle usually opens very close to the previous close, so the error per trade is often small, roughly a spread plus whatever price does while the order is sent. It is still an error, and it is systematic for rules that trigger in fast moves, when spreads widen and price moves quickly.

In markets that close overnight, it can be large. A stock that closes at 50.00 after a buy signal and opens the next morning at 50.60 cannot be bought at 50.00 by a rule that needed the close to decide: the honest fill is 1.2% higher.

Filling at the signal candle's own open#

A worse shortcut fills the trade at the open of the signal candle, before the move that created the signal. This usually happens through an off-by-one error: the signal is computed for candle t, and the trade is booked at candle t's open instead of candle t + 1's. The backtest then pockets the signal candle's own move on every trade. For a buy signal triggered by a rising candle, that move is a gain no one could have captured.

Highs and lows used before the candle closes#

A candle's high and low are known only once the candle has closed. Using them earlier is look-ahead bias in its most tempting form, because the high is the best price of the candle. Examples include a rule that "sells at the high" of a candle on which it decides to sell, or a rule that checks whether today's low broke a level and then buys at today's open.

A related problem is intrabar order. If a candle's range covers both a stop-loss and a profit target, candle data cannot show which was reached first. A backtest that always assumes the target came first is quietly assuming knowledge of the path inside the candle. A careful test assumes the worse outcome, or uses finer data. Valmy's specification states the same limit for its own simulator: a five-minute candle cannot establish the order of prices inside it, so uncertain liquidation assumptions are reported and a documented conservative tie-break is used for events that could have happened in either order (as specified, 25 November 2026).

Worked example: one rule, four fill assumptions (synthetic data)#

The same crossover rule on the same random candles made +0.9% before costs with honest fills, +9.5% when it filled at the signal candle's own open, and +14.5% when it sold at the high of the candle that triggered each exit. The data are 2,016 invented five-minute candles (seven days) built as a random walk: each candle's move is random and unrelated to the past, so no rule can predict it. Holding over the test lost 4.1%. Twenty earlier candles provide history for the averages.

The rule is a long-or-flat crossover of simple moving averages: buy when SMA(5) of the close crosses above SMA(20), sell when it crosses below. It made 63 round trips under every fill assumption:

Fill assumption What it assumes Result before costs Winning trades
Next candle's open (honest) Act after the signal candle closes +0.9% 20 of 63
Signal candle's close Trade at the last price that formed the signal +0.9% 20 of 63
Signal candle's own open Trade before the move that formed the signal +9.5% 29 of 63
Sell at the exit signal candle's high Buy honestly, sell at the best price of the candle that triggered the exit +14.5% 38 of 63

The first two rows are identical because in this synthetic market every candle opens exactly at the previous close, as a continuously traded market roughly does. That makes the close fill harmless here, and only here: with real spreads, delays and gaps, the two would differ.

Synthetic five-minute candles around one trade of an SMA(5) and SMA(20) crossover. The buy signal candle opened at 100.38 and closed at 100.53, so the honest buy is the next open at 100.53 while a biased backtest buys at 100.38. Twelve candles later the sell signal candle reached a high of 100.42 and closed at 99.94; the honest sell is the next open at 99.94 while a biased backtest sells at 100.42.
Figure 1. Synthetic data. One trade from the test. Points A and C are prices from inside or at the start of the signal candles, which the rule could not have known it wanted; points B and D are the first prices available after each signal.

Figure 1 shows one trade in detail. The buy signal candle opened at 100.38 and closed at 100.53. The honest buy is the next open, 100.53. Twelve candles later the sell signal candle opened at 100.19, reached 100.42 and closed at 99.94, and the honest sell is the next open, 99.94:

  • Honest fills (B to D): 99.94 ÷ 100.53 − 1 = −0.59%.
  • Own-open fills (A, then the sell signal candle's open): 100.19 ÷ 100.38 − 1 = −0.19%.
  • Honest buy, sell at the high (B to C): 100.42 ÷ 100.53 − 1 = −0.11%.

The trade lost money under every assumption, but the biased versions lost much less. Repeated over 63 trades, those small differences add up.

Equity of 1,000 USDT over seven days of synthetic random-walk five-minute candles, before costs, for the same SMA(5) and SMA(20) crossover rule with 63 round trips. Filling at the next candle's open ends at plus 0.9%. Filling at the signal candle's own open ends at plus 9.5%. Selling at the high of the exit signal candle ends at plus 14.5%.
Figure 2. Synthetic data. The honest curve wanders around its start, as it should on a random walk. Notice that both biased curves climb steadily: a smooth, rising equity curve on data that cannot be predicted is a warning sign.

How large the bias is per trade#

The bias looks small on each trade and large in total:

  • Own-open fills add the signal candles' own moves. Of the 63 buy-signal candles, 42 closed above their open, and on average they rose 0.07% from open to close. The sell-signal candles fell 0.06% on average. Capturing the first and avoiding the second raised the average trade from +0.02% to +0.15%.
  • Selling at the high adds the distance from each exit candle's close back up to its high, 0.20% on average. It raised the average trade to +0.22% and the number of winners from 20 to 38.

Those amounts are similar to real trading costs. At 0.30% per round trip, the honest rule lost 16.5%, the own-open version lost 9.4% and the sell-at-high version lost 5.3%. A biased backtest can therefore hide most of a rule's costs, which is exactly the size of error that turns a losing rule into a tempting one.

Indicators computed with later data#

An indicator leaks the future when its value at a candle uses prices from later candles. The chart can look perfect, because the line turns exactly at the turning points.

  • Centered averages. A 21-candle average plotted at the middle of its window uses the 10 candles after it. Charting tools sometimes use centered or "detrended" lines for smoothing. A rule that trades on them is using up to 10 future candles. A trailing SMA, which averages only the current and earlier closes, does not have this problem; it is the version Valmy's language uses, as specified.
  • Full-sample normalization. Scaling prices by the whole test period's average, highest value or standard deviation uses numbers that only exist at the end of the period. A rule that buys "below the period's average" knows where the average will be.
  • Values confirmed later. A swing high is confirmed only after later candles close, and some indicators redraw past values as new data arrive. A backtest must use each value as it stood at the decision time, not as it looks on the finished chart.
  • Warm-up. An indicator has no valid value until it has enough history. Filling the first values with zeros, or with an average computed from the full period, puts future or invented information into the first trades.

Revised data, survivorship and timestamps#

Three quieter forms of look-ahead bias come from the data set itself, not from the rule. They matter most for research outside a strategy tool, where the trader assembles the data.

Restated or revised data#

Some data are corrected after first publication: company accounts can be restated and economic statistics are revised. A test that uses today's corrected values for past decisions assumes knowledge of corrections that came later. The Federal Reserve Bank of St. Louis keeps an archive, ALFRED, of each economic data release as it stood on past dates, so researchers can use the values that were actually known. Exchange price archives can also be corrected. Valmy's market-data specification keeps such corrections as new dataset revisions and pins the exact revision a backtest used, so a replay can be reproduced (as specified, 25 November 2026).

Survivorship: testing only what still exists#

Survivorship bias comes from choosing the test universe with hindsight. A test run only on coins that are large and listed today leaves out every coin that collapsed or was delisted, and those are often the ones a rule would have bought on the way down. A University of St. Gallen working paper by Ammann, Burdorf, Liebi and Stöckl (2022), not yet refereed according to its repository record, studied 3,904 cryptocurrencies from 2014 to 2021 and estimated the annual survivorship bias at 0.93% for value-weighted portfolios and 62.19% for equal-weighted ones. The same problem affects stock indexes whose members change, as explained in How many stocks are joining the rally? The Advance/Decline Line and Is a rally broad or narrow?. The Valmy engineering proposal starts with BTC/USDT and ETH/USDT, two markets that are large today, so a rule tested only there says nothing about markets that failed.

Timestamps and time zones#

A candle has an open time and a close time, and data sources label it differently. Binance's Spot API identifies each kline by its open time, returns times in UTC milliseconds by default, and lets a caller shift interval boundaries with a time-zone parameter. Binance's public data archive notes that Spot timestamps from 1 January 2025 onward are in microseconds. Two typical errors follow:

  • Joining a candle labeled 10:00 (covering 10:00 to 10:05) with an event at 10:03, as if the candle's close was known before the event, or the reverse.
  • Mixing daily candles cut at different times, such as UTC midnight and a local midnight, so that a "previous day" overlaps the decision day.

Valmy's specification uses the exchange event timestamp for each strategy evaluation, and its market-data import is specified to handle mixed timestamp units (as specified, 25 November 2026).

How Valmy's specification avoids same-candle fills#

As specified on 25 November 2026, the Valmy strategy runtime and backtester close off the forms of look-ahead bias that a rule itself could introduce:

  • Decisions at the close. A strategy is evaluated once a five-minute candle has closed, using that candle and earlier closed candles only.
  • Fills on a later candle. A backtest simulates the earliest execution on a subsequent candle, with the configured spread, slippage and fee model, so the signal candle's own prices are never fills.
  • Trailing indicators only. The only indicator, the simple moving average, averages the current and earlier closes. A crossover compares current and previous fully warmed values, and too little history gives a hold with a warm-up reason.
  • Pinned data. A backtest pins the dataset revision, cost model and other inputs, and refuses unsupported periods and data gaps.

What the specification cannot prevent are look-ahead choices made by the person: picking a rule because it fit the chart you already studied, testing only markets that survived, or analyzing data in another tool with the shortcuts above. The first is the subject of Why did my backtest work when live trading didn't? Overfitting and data snooping.

What could change the conclusion about look-ahead bias#

The example exaggerates nothing, but its size depends on the market and the rule:

  • The size varies. The bias from own-open fills grows with how much the signal candle moves, and the high-peek bias grows with how far highs sit above closes. Volatile markets and rules that trigger on big candles are hit hardest.
  • Close fills are not always small. In this synthetic market the next open always equals the previous close. In markets with gaps, pauses or thin books, filling at the signal close can be a large error.
  • Look-ahead does not always flatter. A leak makes a result meaningless, not only too good. A rule that uses future data the wrong way round can look worse than it is, which is no more reliable.
  • A simple check. Delay every fill by one more candle and rerun the test. An honest rule's result usually changes a little. A result that collapses suggests the rule depended on the price at, or just before, the signal.

Check your understanding: finding the leak#

Question.

  1. A spreadsheet test of a daily rule buys at each day's open when that day's close is above its 10-day SMA. On one day the candle opened at 100.00, reached a high of 101.20 and a low of 99.60, and closed at 100.90. What does the spreadsheet record for that day, and what is the honest version?
  2. A backtest enters at 100.00 with a stop-loss at 99.00 and a target at 101.50. The next candle has a high of 101.80 and a low of 98.70. What result should the backtest record?
  3. Which of these is look-ahead bias: (a) using SMA(20) computed through the latest closed candle to trade at the next open; (b) buying when price is below the average of the whole test period; (c) testing a rule only on coins that are listed today?
Show the answers

Answer.

  1. The spreadsheet records a gain of 100.90 ÷ 100.00 − 1 = 0.90% for the day, earned by buying at the open on the strength of a close that came hours later. Honestly, the signal exists only after the close of 100.90, so the earliest buy is the next day's open, and that day's 0.90% belongs to no one.
  2. Both the stop and the target were inside the candle's range, and candle data cannot show which was hit first. Assuming the target gives +1.50%, assuming the stop gives −1.00%, a difference of 2.5 percentage points on one trade. A careful backtest records the stop, or checks finer data.
  3. (a) is honest. (b) is look-ahead bias: the whole period's average is known only at its end. (c) is survivorship bias, a selection made with later knowledge of which coins survived.