Lookahead bias is one of the quietest ways an indicator test can go wrong. Nothing looks broken. The chart draws, the numbers come out, and the results look unusually good. The problem is that somewhere in the calculation, information from the future was used to judge the past. This article explains what lookahead bias is, how it can inflate a test, and what it means in practice for a band to use only information available at the prior close.
Lookahead bias occurs when a calculation uses data that would not have been available at the moment it claims to describe. If a band for Tuesday is drawn using Tuesday's close, and then scored on whether Tuesday's close landed inside it, the test has looked ahead. The outcome being measured has leaked into the thing doing the measuring.
The leak does not have to be large or obvious. A single row of misalignment in a spreadsheet, a statistic computed over the whole history rather than up to each date, or a setting chosen after seeing the results can all introduce it. What they share is that the test knows something it could not have known in real time.
Lookahead bias almost always flatters the result, because the leaked information is precisely the information the test is supposed to be uncertain about.
Take a band built from a rolling window of returns. If the window includes the bar being scored, a large move on that bar enters the standard deviation and widens the band on exactly the day it would otherwise have missed. Containment rises, and the rise is entirely artificial. The band backtesting guide describes how a window that ends one row too late produces this effect.
A second form uses whole-sample statistics. Sizing every band from the volatility of the entire history gives each early bar knowledge of crises that had not happened yet. A third form sits in the choice of settings. Trying many window lengths and reporting the one that scored best is a softer kind of lookahead, because the test set has influenced the design. The overfitting post covers that problem in more detail.
In each case, the reported number describes a band that could not have been drawn in real time. It says little about how the band would have behaved when the future was still unknown.
Oisigma's expected range is built to avoid all three. The how it works page sets out the construction. For each bar, the rolling window of recent percentage returns ends at the prior bar's close. The expected price is anchored to that prior close. The inner and outer bands are measured in return space from that window and then projected onto price. By the time the bar opens, its range is already fixed by data the market had already produced.
The bar is then scored on its own close. The band was drawn without that close, so the test asks a genuinely forward question of each bar: given only what was known at the prior close, did the next close land inside the stated range?
That has a visible consequence on the chart. A closed bar's range and its markers are fixed and do not change afterwards. A forming bar's live abnormal-move marker can update until the bar closes, because price is still moving relative to a range that was set in advance. Once the bar closes, the marker is fixed too.
Avoiding data leaks is necessary but not sufficient. A band can be computed causally on every bar and still have been designed with the test set in view. The FAQ states that there is no lookahead and no fitting to the test set.
The design choices are deliberately few. The band has one main input, window length, with a canonical setting of 60 bars, about a calendar quarter on daily data, used across instruments rather than tuned per market. Two further checks address the design question directly. When each instrument's history was split in half, containment was essentially unchanged. A set of 79 randomly chosen U.S. stocks, not used for tuning, averaged about 73.6% containment, with every name above 70%. Past behavior is not a guarantee of future results. The working paper also reports that the result survives out-of-sample tests and a 2025 to 2026 holdout.
Repainting is a related but separate problem. It happens when an indicator's historical values change after the fact, so the chart shows a cleaner history than anyone saw live. The repainting check guide explains how to detect it, and the post on whether the Behavioral Transform Model repaints applies the check to this band.
Some signs suggest a test may have looked ahead, even without access to its code. Markers that sit exactly at historical turning points are one, because a causal calculation cannot know a turning point until after it has passed. Coverage that sits far above any reasonable benchmark is another. Settings that differ by market, each seemingly chosen to look best, are a third. None of these proves lookahead, but each is a reason to ask how the calculation was aligned in time.
Lookahead bias lets information from the future shape a measurement of the past, and it almost always flatters the result. It can enter through misaligned data, whole-sample statistics or settings chosen after seeing the test. A band that uses only information available at the prior close, with fixed settings and out-of-sample checks, is built to ask an honest forward question of each bar. That is a statement about how the test was run, not a claim about profit or direction.
Is lookahead bias the same as survivorship bias? No. Survivorship bias comes from testing only on assets that still exist, which leaves out those that failed or were delisted. Lookahead bias comes from using information that was not available at the time. A test can suffer from either, both or neither.
Can lookahead bias happen in Pine Script? Yes, in general. A common source is requesting higher-timeframe data in a way that exposes a bar's final value before that bar has closed. The result can look excellent on history and behave differently in real time.
Does a non-repainting indicator rule out lookahead bias? Not entirely. A non-repainting indicator keeps its history fixed, which removes one source of misleading results. A test can still look ahead through its design, for example by choosing settings after seeing the outcomes.
Why does the live marker change during a forming bar? The marker compares price with a range that was fixed at the prior close. While the bar is still forming, price can move in and out of that range, so the marker can update. At the close, it is fixed.
If you want to see a band built only from information available at the prior close on the markets you follow, the 30-day free trial gives full access to the indicator on TradingView, then $15 a month, and you can cancel anytime. You can start the trial here.
Oisigma provides descriptive market analytics for educational use. It is not investment advice, does not predict prices, and does not provide buy or sell signals. Statistics referenced are historical and were measured in our working paper (not peer-reviewed); past behavior is not a guarantee of future results. Trading and investing involve substantial risk of loss, including the possible loss of all capital invested. Leveraged products (futures, options, margin) carry additional risk and can result in losses that exceed your initial investment. Bollinger Bands® is a registered trademark of John Bollinger; Oisigma is not affiliated with or endorsed by Mr. Bollinger. RiskMetrics® is a registered trademark of MSCI Inc.; Oisigma is not affiliated with or endorsed by MSCI Inc. Nothing in this article is a recommendation to use any particular strategy. Read the full Disclaimer →
Try it free for 30 days and see the range update as new bars print, on whatever symbols and timeframes you actually trade.
30 days free, then $15/mo. Cancel anytime from your account.
Pick up where you left off.