Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pine Script beginner, plotshape

Tags:

pine-script

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)
like image 493
sunspore Avatar asked Oct 18 '18 14:10

sunspore


1 Answers

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

like image 121
vitruvius Avatar answered Oct 01 '22 21:10

vitruvius