颜色变化警报

Alerts on Color changes

我试图在线条颜色变化时发出警报。此代码会在我不想要的每个柱上发出警报。

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!')

好吧,只要 alertcondition()condition 参数是 true,您就会收到警报。

如果绘制 col1col3,您将了解为什么会收到多个警报。这是因为其中一个在多个柱中保持 true。你需要的是一个脉冲.

要创造一个脉冲,您需要考虑您的实施。您的实现保证 col1col3 永远不会同时是 true。因此,您可以比较 col3[1]col1。因此,如果 col3[1] and col1 为真,则意味着前一个柱 col3 为真,但对于当前柱只有 col1 为真,这表明 col3 发生了变化至 col1.

看看下面的代码和图表:

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

中使用这些变量
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]
isNewCol1 = nz(col3[1]) and col1
isNewCol3 = nz(col1[1]) and col3
colorP = col1 ? green : col3 ? red : yellow
plot(T3, color=colorP, linewidth=3, title="T3")

plotshape(series=isNewCol1, title="col1", style=shape.triangleup, location=location.belowbar, color=green, text="Green", size=size.normal)
plotshape(series=isNewCol3, title="col3", style=shape.triangledown, location=location.abovebar, color=red, text="Red", size=size.normal)
alertcondition(condition=isNewCol1, title="isNewCol1", message="green")
alertcondition(condition=isNewCol3, title="isNewCol3", message="red")

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!')