Looking for a workaround, can't use plotshape in this way because it doesn't work in a local scope.
//@version=3
study("MA test ", overlay=true)
FastMA = sma(close, 9)
SlowMA = sma(close, 15)
Diff = FastMA - SlowMA
if Diff > 0
plotshape(Diff, style=shape.arrowup, location=location.belowbar, color=green)
You can directly apply your condition to series
argument of the plot()
function (also to color
argument).
I also added another plotshape()
that uses crossover()
in its series
and it only plots the triangles when FastMA crosses over SlowMA (orange triangle). I thought it might come handy for you in the future :)
//@version=3
study("MA test ", overlay=true)
FastMA = sma(close, 9)
SlowMA = sma(close, 15)
Diff = FastMA - SlowMA
plot(series=FastMA, title="FastMA", color=color.green, linewidth=3)
plot(series=SlowMA, title="SlowMA", color=color.red, linewidth=3)
bgcolor(color=Diff > 0 ? green : red)
plotshape(series=Diff > 0, style=shape.arrowup, location=location.belowbar, color=color.green, size=size.normal)
plotshape(series=crossover(FastMA, SlowMA), style=shape.triangledown, location=location.abovebar, color=color.orange, size=size.normal)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With