pinescript-当EMA穿越SMA而高于/低于200移动平均线时绘制交叉图

时间:2018-10-09 21:43:20

标签: plot moving-average tradingview-api pine-script

我对pinescript非常陌生,现在我被困住了...我只想在10 EMA超过21 EMA而21高于50 EMA和50 EMA高于200 EMA时绘制十字。这表示长信号。同时,当10 EMA穿越21 EMA而21低于50 EMA而50 EMA低于200 EMA时。这是为了指示短路信号。

我有这么多代码,但是我不知道如何继续:

//@version=3
study(title="MA Cross ATTEMPT", overlay=true)

s10ema = ema(close, 10)
s21ema = ema(close, 21)
s50ema = ema(close, 50)
s200ema = ema(close, 200)

plot(s10ema, color = red, linewidth = 1, transp=0)
plot(s21ema, color = aqua, linewidth = 1, transp=0)
plot(s50ema, color = aqua, linewidth = 2, transp=0)
plot(s200ema, color = red, linewidth = 2, transp=0)

mycond = s200ema < s50ema and s50ema < s21ema and s21ema < s10ema
EMACross = cross(s10ema, s21ema) ? s10ema : na, style = cross, linewidth = 4, color = yellow, transp=0

plot(?????)

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:2)

执行此操作的方法是使用plotshape()函数。也有不同的plot函数,但我更喜欢为此目的使用plotshape()。绝对还要检查其他plot函数。 Tradingview有一个很好的有关pine-script的文档。

此外,如果两个系列相互交叉,cross()返回1。可能是从下方或上方,都没关系。但是,您想在发生crossover时触发条件。为此,有一个名为crossover()的函数(相反的情况也请参见crossunder())。

//@version=3
study(title="MA Cross ATTEMPT", overlay=true)

s10ema = ema(close, 10)
s21ema = ema(close, 21)
s50ema = ema(close, 50)
s200ema = ema(close, 200)

plot(s10ema, title="Ema 10", color = red, linewidth = 1, transp=0)
plot(s21ema, title="Ema 21", color = aqua, linewidth = 1, transp=0)
plot(s50ema, title="Ema 50", color = orange, linewidth = 2, transp=0)
plot(s200ema, title="Ema 200", color = blue, linewidth = 2, transp=0)

longCond = crossover(s10ema, s21ema) and (s21ema > s50ema) and (s50ema > s200ema)
shortCond = crossunder(s10ema, s21ema) and (s21ema < s50ema) and (s50ema < s200ema)

plotshape(series=longCond, title="Long", style=shape.triangleup, location=location.belowbar, color=green, text="LONG", size=size.small)
plotshape(series=shortCond, title="Short", style=shape.triangledown, location=location.abovebar, color=red, text="SHORT", size=size.small)

enter image description here