颜色变化警报

时间:2018-10-25 09:08:00

标签: tradingview-api pine-script

我正在尝试仅在更改行颜色时获得警报。此代码会在不需要的每个栏上发出警报。

study("Tillson T3", overlay=true)
length1 = input(8, "T3 Length")
a1 = input(0.7, "Volume Factor")

e1=ema((high + low + 2*close)/4, length1)
e2=ema(e1,length1)
e3=ema(e2,length1)
e4=ema(e3,length1)
e5=ema(e4,length1)
e6=ema(e5,length1)
c1=-a1*a1*a1
c2=3*a1*a1+3*a1*a1*a1
c3=-6*a1*a1-3*a1-3*a1*a1*a1
c4=1+3*a1+a1*a1*a1+3*a1*a1
T3=c1*e6+c2*e5+c3*e4+c4*e3

col1= T3>T3[1]
col3= T3<T3[1]
color = col1 ? green : col3 ? red : yellow
plot(T3, color=color, linewidth=3, title="T3")

alertcondition(col1, title='Alert on Green Bar', message='Green Bar!')
alertcondition(col3, title='Alert on Red Bar', message='Red Bar!')

2 个答案:

答案 0 :(得分:1)

好吧,只要condition的{​​{1}}参数为alertcondition(),您就会收到警报。

如果绘制truecol1,您将看到为什么收到多个警报。这是因为其中一个停留在col3上的多个小节。您需要的是脉冲

enter image description here

要创建一个脉冲,您需要考虑实现。您的实现保证了truecol1永远不会同时col3。因此,您可以比较truecol3[1]。因此,如果col1为真,则意味着前一个小节col3[1] and col1为真,但对于当前小节,只有col3为真,这表示与col1的变化到col3

看看下面的代码和图表:

col1

enter image description here

编辑

您只需要在//@version=3 study(title="Color", overlay=false) T3 = close col1= T3>T3[1] col3= T3<T3[1] isNewCol1 = nz(col3[1]) and col1 isNewCol3 = nz(col1[1]) and col3 plot(series=isNewCol1 ? 1 : 0, title="isNewCol1", color=orange, linewidth=4) plot(series=isNewCol3 ? 1 : 0, title="isNewCol3", color=blue, linewidth=4) 中使用这些变量。

alertcondition()

enter image description here

答案 1 :(得分:0)

buy= T3>T3[1] and T3[1]<T3[2] 
sell= T3<T3[1] and T3[1]>T3[2]  
color = T3>T3[1] ? green : T3<T3[1] ? red : yellow
plot(T3, color=color, linewidth=3, title="T3")
alertcondition(buy, title='Alert on Green Bar', message='Green Bar!')
alertcondition(sell, title='Alert on Red Bar', message='Red Bar!')