Reputation: 3
Is anyone familiar with Pinescript 5.I mean,I can't figure out why this work in Pinescript 2 and not in Pinescript 5
buying = l3_0 > threshold ? true : l3_0 < -threshold ? false : buying[1]
Error : Undeclared identifier 'buying'
Upvotes: 0
Views: 158
Reputation: 11
buying = l3_0 > threshold ? true : l3_0 < -threshold ? false : buying[1]
Fix :
var bool buying = false
buying := l3_0 > threshold ? true : l3_0 < -threshold ? false : buying[1]
Reason : You're trying to use a ternary operator while calling upon the previous value of buying with buying[1], in this case, while defining the variable, pinescript is unable to find the previous value of buying. Thus you need to first declare the variable with its bool value as FALSE, and then reassign it with your desired formula.
Upvotes: 0
Reputation: 21342
It is because Self-referenced variables are removed in v3
.
You need to declare the variable first.
buying = false
buying := l3_0 > threshold ? true : l3_0 < -threshold ? false : buying[1]
Upvotes: 1