I have a series myLine, which I fill with value na
myLine = 1==1 ? na : na // Series with na
Now I want to create a function that updates t
Pine does not allow global variables to be modified from a function's local scope. These 2 ways should get the job done, with #2 being the most robust because it will not be constrained by compiler limits on the number of nested if
blocks in the ternary:
//@version=4
study("")
// ————— #1
isDate(y,m,d) => y==year and m==month and d==dayofmonth // Is the date of the current bar equal to the date provided by the parameters?
float myLine1 = na
myLine1 :=
isDate(2020,03,31) ? 1234 :
isDate(2020,04,01) ? 2345 : na
plot(myLine1, "myLine1", color.silver, 10, plot.style_circles, transp = 50)
// ————— #2
initOnDate(y,m,d, prev, init) =>
if y==year and m==month and d==dayofmonth
init
else
prev
float myLine2 = na
myLine2 := initOnDate(2020,03,31,myLine2,1234)
myLine2 := initOnDate(2020,04,01,myLine2,2345)
plot(myLine2, "myLine2", color.orange, 3, plot.style_circles)