5
votes

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)
1
What exactly are you trying to do? - Baris Yakut
I want to plot an arrow under each bar where the fast ma is above the slow ma. I'm going to build on this, but first I need to figure out how to use the plotshape function. - sunspore

1 Answers

9
votes

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)

enter image description here