CS5201
error A history offset cannot be negative or na (got offset).
#What it means
A history offset (x[n]) worked out while the script ran was negative or na. The script can only look back, never forward, and needs a number to do it.
#Typical cause
- An offset computed from the bar, such as
10 - bar_index, which turns negative. - An offset from a calculation that gives
naon the first bars.
#How to fix it
Clamp the offset, for example math.max(0, n), and handle na with nz(n). See Execution model.
#Example
//@chartscript 1
indicator("Look back")
const offset = 10 - bar_index
plot(close[offset])Fixed
//@chartscript 1
indicator("Look back")
const offset = math.max(0, 10 - bar_index)
plot(close[offset])