Tests a value for na and returns true when it is missing, the only reliable way to check.
na(x) is true when x is na and false otherwise. It works on numbers, strings, colours and drawing objects. A comparison like x == na never works, because na is not equal to anything, itself included.
Combine it with nz() and fixnan() to repair series, or with the ternary operator to choose a fallback: na(x) ? close : x.
Syntax
na(x: simple int/float) -> simple bool
na(x: series int/float/color/string/label/line/box/table/linefill/polyline/array<>/matrix<>/map<>) -> series boolArguments
| Name | Type | Default | Description |
|---|---|---|---|
| x | simple int/ | required | The value to test. A series is tested on the bar being calculated. |
Returns
simple/series bool: true when x is na, false when it holds a value.
Remarks
- Indicators return na until they have enough bars.
ta.sma(close, 20)is na on the first 19 bars, and na(ta.sma(close, 20)) is true there. - The na variable is the value itself; the na() function is the test. Writing na(na) is true.
Example
//@version=6
indicator("na test", overlay = true)
avg = ta.sma(close, 20)
plot(avg, "SMA 20", color.blue)
bgcolor(na(avg) ? color.new(color.gray, 85) : na)See also
Runs on Sidechair