Reputation: 63
I am trying to plot values for the variable test that come only after a time or bar moment. The moment is when high == highest(high,63)
and from then I would like to plot the high values on further bars and not on previous bars. This is possible with show_last of the plot function, but how can I use an automatic constant for show_last which could be the number of bars back when the first high == highest(high,63)
without using a manual input?
//@version=4
study(title="Test", overlay=true)
moment = valuewhen(high == highest(high,63),time,0)
test = time < moment ? na : high
plot(test, title="test", color=color.yellow)
Upvotes: 0
Views: 806
Reputation: 6905
You can't use show_last
for that purpose, because that parameter needs to be an input integer (which value is constant).
You're asking to provide the show_last
parameter with a series integer
, but that would lead to a compile error.
I think this is what you want:
//@version=4
study(title="Test", overlay=true)
var bool moment_occurred = false
if high == highest(high,63)
moment_occurred := true
plot(moment_occurred ? high : na, title="test", color=color.yellow)
But once that condition is hit for the first time, it'll always plot af that moment.
It never gets reset.
Upvotes: 1