Skip to content

na() - Pine Script Function

na() checks if a value equals Pine’s dedicated “not available” marker. The function works with both simple and series arguments, so you can guard against uninitialized calculations, incomplete security requests, or lookups that fall outside the available history.

Use na(x) rather than x == na. Comparisons with na always return false because na is not a number; the helper is the only reliable way to detect it.

na(x) → simple bool
na(x) → series bool
NameTypeDescription
xsimple/series int/float/bool/colorValue to test for na. Works with arrays, matrices, and drawing handles by passing their IDs.

simple/series booltrue if x is na, otherwise false.

  • Warm-up values for many ta.* functions start as na. Use if not na(value) before plotting or branching on the result.
  • Paired helpers: nz(x, replacement) substitutes a fallback for na values, while fixnan(x) propagates the last non-na result.
  • na is also a literal you can assign (var float lastPivot = na) to denote an uninitialized state before you store actual data.
//@version=5
indicator("na() guard example", overlay=false)
length = input.int(14, "RSI length", minval=2)
rsi = ta.rsi(close, length)
// Plot RSI only after it becomes available.
plot(na(rsi) ? na : rsi, "RSI", color=color.teal)
// Flag bars where the value is still unavailable.
plotshape(na(rsi), title="Warm-up bar", style=shape.circle, size=size.tiny,
color=color.new(color.orange, 0), location=location.top)
// Compare with nz(): fill forward missing RSI values using the prior close.
smoothed = nz(rsi, close)
plot(smoothed, "nz() fallback", color=color.new(color.gray, 70))