I am trying to write a script on Pine (related to a Tradingview strategy) where I want to use the series and take the previous value or past values to make a set of operations.
Something as:
a = if(Alerta1[-1] == 5, 10,0)
the pine script is saved without error, but during the execution, an error is shown:
Index can’t be a negative value (-1)
Is there anybody that could let me know how to solve it?
I would like to use “[-1]” and other “minus” such “[-20]” for a script.
many thanks in advance
The answer
The answer is as simple that I’m embarrassed of not being able to see it: