Pine Script 初学者,plotshape

Pine Script beginner, plotshape

寻找解决方法,不能以这种方式使用 plotshape,因为它在本地范围内不起作用。

//@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)

您可以直接将条件应用于 plot() 函数的 series 参数(也可以应用于 color 参数)。

我还添加了另一个 plotshape(),它在其 series 中使用了 crossover(),它仅在 FastMA 穿过 SlowMA(橙色三角形)时绘制三角形。我想它以后可能对你有用:)

//@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)