Na - Nz

nz

Definition: Replaces NaN values with zeros (or given value) in a series.

Syntax:

nz(source, replacement) β†’ simple int/float/color/bool
nz(source, replacement) β†’ series int/float/color/bool
nz(source) β†’ simple int/float/color/bool
nz(source) β†’ series int/float/color/bool

Returns:

The value of `source` if it is not `na`. If the value of `source` is `na`, returns zero, or the `replacement` argument when one is used.

Arguments:

NameTypeDescription

source

series int/float/bool/color

Series of values to process.

replacement

series int/float/bool/color

Value that will replace all 'na' values in the source series.

Example:

//@version=5
indicator("nz", overlay=true)
plot(nz(ta.sma(close, 100)))

na

Definition: Tests if x is na.

Syntax:

na(x) β†’ simple bool
na(x) β†’ series bool

Returns:

Returns true if `x` is na, false otherwise.

Arguments:

NameTypeDescription

x

series int/float/bool/string

Value to be tested.

Example:

//@version=5
indicator("na")
// Use the `na()` function to test for `na`.
plot(na(close[1]) ? close : close[1])
// ALTERNATIVE
// `nz()` also tests `close[1]` for `na`. It returns `close[1]` if it is not `na`, and `close` if it is.
plot(nz(close[1], close))

Last updated