I'm working on something in Pine Script v5, but I'm stuck with something. I would like to store a value once, if conditions are met, and use this value later. But the value is still recalculated at each candle.
For example:
// initiate value
int go_long = 0
BullTrend = (close - lowest(low, 50)) / atr(5)
// Wait for condition 1
if BullTrend < 2 and ta.sma(close,15) > 15
go_long := 1
// Wait for condition 2 later , but based on previous status of go_long
if go_long == 1 and open > close
go_long := 2
plotshape(go_long == 2, style=shape.arrowup)`
This is just a nonsense example to highlight the problem I'm facing.
In this case the go_long
value changes at each candlestick, and that's not what I want.