# Pine Script look-ahead checker

Paste Pine Script to locate potential higher timeframe look-ahead patterns. The static scan runs in your browser. The pasted script is not sent to a server.

## Check a script

The synthetic example below requests a daily close with lookahead_on and no expression history offset. It produces an alert.

Pine Script source//@version=6
indicator("HTF close example", overlay=true)
dailyClose = request.security(syminfo.tickerid, "1D", close, lookahead=barmerge.lookahead_on)
plot(dailyClose)

The example result appears below. Enable JavaScript to check another script locally.

### Result

potential look-ahead risk

- Line 3: security() with lookahead_on and no explicit expression history offset can leak higher timeframe values into historical bars.
request.security(syminfo.tickerid, "1D", close, lookahead=barmerge.lookahead_on)

Possible false positives: Same or lower timeframe requests, an offset inside a helper or intermediate variable, or a non-price expression can require manual review.

## What the alert means

On historical bars, lookahead_on can place a higher timeframe value before that value was available. TradingView documents a history offset on the requested expression, such as close[1], for earlier higher timeframe values.

The default lookahead_off avoids that historical future leak, although values can still change on realtime bars. barstate.isconfirmed does not work inside request.security().

The scanner recognises direct expression offsets and tuples with an offset on each member. It does not trace wrapper calls, intermediate variables, arrays or request.security_lower_tf. Timeframe relationships and script execution are not evaluated. A result of “no pattern matched (static scan, partial recall)” is not a validation of the strategy. Review the [look-ahead bias guide](https://stochastly.com/learn/look-ahead-bias) and [Pine Script backtest validation](https://stochastly.com/learn/pine-script-backtest-validation) before interpreting a backtest.

TradingView documentation, read 2026-10-03: [other timeframes and data](https://www.tradingview.com/pine-script-docs/concepts/other-timeframes-and-data/), [repainting](https://www.tradingview.com/pine-script-docs/v5/concepts/repainting/), and [bar states](https://www.tradingview.com/pine-script-docs/concepts/bar-states/). Pine v1/v2 security() used the older lookahead behavior; the scanner alerts on those calls when the version directive is present.

## Frequently asked questions

### Does an empty result mean the script is free of look-ahead?

No. The scan has partial recall and cannot establish how a script behaves when Pine executes it.

### Does a result mean my backtest is biased?

The alert identifies a pattern for manual review. Same or lower timeframe requests and expressions resolved through variables can change the interpretation.

### Is my pasted code uploaded?

The checker reads the textarea in the browser and makes no request with its contents. Do not put the script in a shareable page URL.

## Embed this calculator

Other sites can show the Pine Script look-ahead checker in a frame served from [/embed/pine-script-lookahead-checker](https://stochastly.com/embed/pine-script-lookahead-checker): the same fields and results, computed in the visitor's browser, with a visible credit and a link to the full calculator. The code below places the Pine Script look-ahead checker frame, a plain link to the full calculator under it, and a script that fits the frame height to its content.

The script applies a height message only when it comes from https://stochastly.com and from the Pine Script look-ahead checker frame, with a height from 200 to 4000 pixels, and drops any other message. The Pine Script look-ahead checker frame registers no message handler of its own, so a host page has no channel to change its inputs or its results.

```
<iframe id="stochastly-pine" src="https://stochastly.com/embed/pine-script-lookahead-checker" title="Pine Script look-ahead checker by Stochastly" width="100%" height="800" style="border:0;max-width:720px" loading="lazy" sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" allow="clipboard-write"></iframe>
<p style="font-size:13px"><a href="https://stochastly.com/tools/pine-script-lookahead-checker">Pine Script look-ahead checker</a> by Stochastly</p>
<script>
(function () {
var allowed = ["https://stochastly.com"];
window.addEventListener("message", function (e) {
var f = document.getElementById("stochastly-pine");
if (!f || allowed.indexOf(e.origin) < 0 || e.source !== f.contentWindow) return;
var d = e.data;
if (!d || d.type !== "stochastly-pine-height" || typeof d.height !== "number") return;
if (!(d.height >= 200 && d.height <= 4000)) return;
f.style.height = Math.ceil(d.height) + "px";
});
})();
</script>
```

Copy the code

## Cite this calculator

To cite the Pine Script look-ahead checker in a paper, a report or a post, copy the reference below. Its address is [https://stochastly.com/tools/pine-script-lookahead-checker](https://stochastly.com/tools/pine-script-lookahead-checker).

```
Stochastly (2026). Pine Script look-ahead checker [web calculator]. https://stochastly.com/tools/pine-script-lookahead-checker
```

Copy the citation

---
Source: https://stochastly.com/tools/pine-script-lookahead-checker
