How can i get the value of previous highest high in pinescript?

2.7k views Asked by At

trying to get the value of the previous highest high in pinescript, but this code gives me the previous bar of current highest high.

myper=input(50, "LENGTH")
y1 = highest(high,myper)
yy = valuewhen(high>y1[1],high,0)
plot(yy[1], linewidth=2, color=#00FF00, title="alt")

Can anyone help ?

1

There are 1 answers

0
e2e4 On

Thats because you use the previous value ([1]) of the yy series in plot() function.

//@version=4
study("My Script")
myper=input(50, "LENGTH")
y1 = highest(high,myper)
yy = valuewhen(high>y1[1],high,0)
plot(yy, linewidth=2, color=#00FF00, title="alt")

enter image description here