Skip to main content

The missing-value problem

OHLCV accessors return null when data is unavailable (e.g. before the lookback window is filled). Technical indicator functions also return NaN during their warmup period. Both values need to be handled before use in downstream math.

Function reference

boolean
Zero-argument form: returns true if no value has been set yet in the current context. Rarely used directly.
boolean
One-argument form: returns true if x is null or NaN. Use this to guard before arithmetic.
number
Returns fallback (default 0) if x is null or NaN; otherwise returns x.

Two modes of na

Why NaN propagates

JavaScript NaN is infectious - any arithmetic involving NaN produces NaN:
NaN + 1 === NaN. If you pass a NaN into your calculation chain, every downstream result will also be NaN. Use na(x) or nz(x) to break the chain early.

Practical patterns

NaN coordinates render nothing

For drawing entities, assigning NaN or null to any coordinate (x1, y1, etc.) causes the entity to render as invisible. No error is raised - it simply disappears silently.

Bar context

OHLCV accessors that return null during warmup.

Series

Series.get() during warmup also returns NaN.

Gotchas

Silent NaN propagation and invisible entities.