na - Pine Script Variable
Overview
Section titled “Overview”A keyword signifying “not available”, indicating that a variable has no assigned value.
naQualifier
Section titled “Qualifier”simple
Remarks
Section titled “Remarks”- Use the
na()function to test values. Direct comparison (value == na) is invalid. - Initialize typed variables with
nabefore assigning their first real value. - Do not use this variable with comparison operators to test values for na, as it might lead to unexpected behavior. Instead, use the na function. Note that na can be used to initialize variables when the initialization statement also specifies the variable’s type.
Example
Section titled “Example”//@version=6indicator("Warm-up guard", overlay=false)
len = input.int(20, "SMA length")value = bar_index < len ? na : ta.sma(close, len)
plot(value)