Fills each na in a series with the most recent value that was not na.
fixnan(source) carries the last real value forward over any gaps. If source has a value on the bar, that value is returned; if it is na, you get the last value seen before.
Until the series has produced its first real value there is nothing to carry, so the result stays na on those bars.
Syntax
fixnan(source: series int/float) -> series float
fixnan(source: series int) -> series int
fixnan(source: series color) -> series colorArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | series int/ | required | The series whose na values are filled with the latest earlier value. |
Returns
series float or series int or series color: The source where it has a value, otherwise the latest earlier value.
Remarks
- Use it on sparse series such as pivots: fixnan(
ta.pivothigh(high, 5, 5)) turns the occasional pivot into a level that stays until the next pivot. - fixnan() reads the series on every bar, so call it at the top level of the script, not inside an if block.
Example
//@version=6
indicator("Last pivot high", overlay = true)
ph = ta.pivothigh(high, 5, 5)
plot(fixnan(ph), "Last pivot high", color.red, 2, plot.style_stepline)
plot(ph, "Pivot", color.red, 4, plot.style_circles, offset = -5)See also
Runs on Sidechair