sunspore
sunspore

Reputation: 147

Pine Script beginner, plotshape

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)

Upvotes: 5

Views: 14440

Answers (1)

vitruvius
vitruvius

Reputation: 21342

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

Upvotes: 9

Related Questions