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!')
解决方案
好吧,只要is的condition
参数,你就会得到一个警报。alertcondition()
true
如果您绘制col1
and col3
,您将看到为什么会收到多个警报。这是因为其中一个会留true
在多个酒吧。你需要的是一个脉搏。
要创建一个脉冲,您需要考虑您的实施。您的实施保证了这一点,col1
并且col3
永远不会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")
推荐阅读
- php - 在事件监听器中同步多对多关系(Laravel 5.7)
- javascript - 如何以这种方式设置/显示这个数组?- CSS/Javascript
- svg - SVG / Inkscape / 遮罩
- heroku - Heroku Buildpack 错误:无法打开库“opencc”
- javascript - 无法从列表中获取单个用户数据 - REST API
- c# - 发生错误后如何使try / catch继续工作?
- paypal - 如何正确使用 PayPal Webhook?模拟器有效,App无效
- angular - 响应中的错误“Access-Control-Allow-Origin”标头不能是通配符“*”,当标头包含“withCredentials”和请求时
- java - 概括规则:哪些操作总是会导致 IOException?
- react-native-ios - 架构 armv7 的未定义符号:YGConfig