I am using Pine Script which is used in tradingview.com.
My question is: how I can get the last value that equals the current value? I thought about using a for
loop or something else.
I tried this code but it returns an error:
getval(x,y) =>
for i = 1 to 100
val = valuewhen(i, y, 1)
val2 = valuewhen(x=i, val, 1)
val2