How na values propagate and how nz() stops them in v6
In Pine Script, any mathematical operation performed on an na value results in na (for example, na + 5 equals na). Because moving averages and oscillators produce na during their initial warmup period, unshielded cumulative calculations will permanently fail without nz().
| Function call | Input state | Resulting output | Primary usage |
|---|---|---|---|
| nz(close[1]) | First bar of chart (where close[1] is na) | 0.0 | Prevents crash when calculating bar-over-bar differences on bar 0 |
| nz(fastMa, close) | Warmup period (where fastMa is na) | Current close price | Supplies a safe fallback so envelopes plot immediately |
| na(myVar) | myVar is unassigned or na | true | Guarding execution blocks before a signal has occurred |
| nz(dailyClose, dailyClose[1]) | Intrabar gap from request.security | Last known daily close | Forward-filling gaps in multi-timeframe datasets |