So I have this code that draws zigzag-alike line
indicator("Custom zigzag", overlay=true)
bullish(at) => open[at] < close[at]
bearish(at) => open[at] > close[at]
break_up() =>
if close != open
at = 1
while close[at] == open[at]
at = 1
if bearish(at) and bullish(0)
true
else
false
else
false
break_down() =>
if close != open
at = 1
while close[at] == open[at]
at = 1
if bearish(0) and bullish(at)
true
else
false
else
false
u = break_up()
d = break_down()
plot(u?open[0] : d?open[0] : na, color = color.fuchsia, linewidth = 1, style = plot.style_line, offset=0)
I want to use the result in some further calculations, but I dont get it, how can I put the whole u?open[0] : d?open[0] : na
in an array?
Roughly pushing values to an array variable leads to recalculation on each bar, IMO.
Or can I access somehow my own previous plot, since custom script call is not possible?
CodePudding user response:
There are two ways to do it depending on do you want na values as it is or previous calculated values in place of na. You can save the whole thing in a variable and then use that to calculate anything like sma etc. First way
//Keeping na value
val=u?open[0] : d?open[0] : na
s=ta.sma(val,10)
plot(s)
Second way
//Replacing na values with previous values
var val=open[0]
val:=u?open[0] : d?open[0] : val[1]
s=ta.sma(val,10)
plot(s)