Martinko
Martinko

Reputation: 3

Referencing history within the identifier [PineScript v5]

I want to reference to the history of the identifier in the same line. It is probably not possible this way. But it works in thinkorswim. I would want the signal either print +1 or -1 else print the last signal that is either +1 or -1 so it is in a loop & wont skip signals. Is there a work around that? Any help is appreciated!

ATRFactor = ta.tr(true)
Avg = ta.ema(close, 50)

Signal = close>(Avg+ATRFactor) ?  1 : close<(Avg-ATRFactor) ? -1 :  signal[1]

Upvotes: 0

Views: 98

Answers (1)

G.Lebret
G.Lebret

Reputation: 3108

You where on the good way. You just need to declare the variable before using it :

//@version=5
indicator("My script")
ATRFactor = ta.tr(true)
Avg = ta.ema(close, 50)

var Signal = 0.0
Signal := close>(Avg+ATRFactor) ?  1 : close<(Avg-ATRFactor) ? -1 :  Signal[1]
plot(Signal)

Upvotes: 0

Related Questions