If you've ever seen "The function ... should be called on each calculation for consistency" and ignored it, this is what it's actually warning about.
Local scopes don't get a history entry on every bar
Pine commits a value to a series' historical buffer only when the scope containing it is evaluated on the bar's closing tick. Global variables get a new entry on every bar, so x[1] always means "one bar ago". Code inside an if, a loop, a function body, or the unused branch of a ternary may not run on a given bar, and then nothing gets committed for that bar.
Per the docs (Execution model > Time series in scopes), [] on a local series therefore means "last committed value as of N bars back", not "value from N bars back". If the scope last ran 10 bars ago, localVar[1] through localVar[9] all return that 10-bar-old value.
Function parameters count as local too: each call site has its own buffer for its arguments, even when you pass a global like close.
Same thing applies to built-ins
Anything in ta.* that looks at past values internally (ta.sma, ta.rsi, ta.ema, ta.crossover, ...) keeps its own history of the source you pass. Call ta.sma(close, 20) only on bars where some condition is true and you get an average of the last 20 calls, not the last 20 bars. It compiles fine and looks plausible on the chart, which is why it's easy to miss.
The v6 trap: lazy and / or
In v5, and/or evaluated both operands every time. In v6 they short-circuit. The migration guide's own example: if close > open and ta.rsi(close, 14) > 50 gave correct RSI values in v5, but in v6 ta.rsi is skipped whenever close > open is false, so its internal history has gaps and the values are wrong. A script ported from v5 can change behavior with no compile error. The ternary ?: was already lazy in v5, so cond ? ta.sma(close, 20) : na has the same problem in both versions.
The fix is boring
Evaluate history-dependent calls once per bar in the global scope, store the result, and use the variable in your conditions:
rsi = ta.rsi(close, 14) then if close > open and rsi > 50sma = ta.sma(close, 20) then cond ? sma : na- Same for your own functions that use
[] on a parameter.
Lazy evaluation is still useful where you want to skip work, e.g. array.size(a) > 0 and array.first(a) > 0 no longer throws on an empty array in v6. The rule of thumb is just: guards can be lazy, anything with memory can't.
A couple of edge cases I'd like to hear how people handle: loops that call a history-dependent function per iteration (one buffer per call site, so iterations overwrite each other), and switch arms that each call a different ta.* function. Do you precompute every variant globally, or restructure some other way?