我正在尝试在此pinescript上添加alertcondition
,以提醒我ATR脚本的颜色是否已从绿色更改为红色,并从红色更改为绿色。
//Crée par J.Dow
//Double SuperTrend ATR, Le type ATR calcule la volatilité à partir de l'Average True Range (ATR), il est idéal pour le FOREX
study(title = "Double SuperTrend ATR", shorttitle = "Double SuperTrend ATR", overlay = true)
//Mode
Factor=input(title="Super Trend", defval=3, minval=1,maxval = 100)
ATR=input(title="ATR", defval=12, minval=1,maxval = 100)
//Super Trend ATR 1
Up=hl2-(Factor*atr(ATR))
Dn=hl2+(Factor*atr(ATR))
TUp=close[1]>TUp[1]? max(Up,TUp[1]) : Up
TDown=close[1]<TDown[1]? min(Dn,TDown[1]) : Dn
Trend = close > TDown[1] ? 1: close< TUp[1]? -1: nz(Trend[1],1)
Tsl1 = Trend==1? TUp: TDown
Tsl2 = Trend==1? TDown: TUp
linecolor = Trend == 1 ? green : red
//Affichage
P1 = plot(Tsl1, color = linecolor , style = line , linewidth = 1,title = "SuperTrend ATR-1")
P2 = plot(Tsl2, color = linecolor , style = line , linewidth = 1,title = "SuperTrend ATR-2")
fill(P1, P2, color = linecolor == red ? red : green)
greenColor = (Trend == 1)
alertcondition(condition=greenColor, title="Buy", message="green buy")
redColor = (Trend != 1)
alertcondition(condition=redColor, title="Sell", message="red sell")
我搞砸了如何对每种颜色发出警报,但是如何将其放在一个通知更改颜色的单个警报中,例如,带有“颜色已更改”消息。
答案 0 :(得分:0)
当趋势与以前的趋势不同时,您可以设置警报 在代码末尾更改
greenColor = Trend == 1 and Trend[1] != 1
alertcondition(greenColor, title="Buy", message="green buy")
redColor = Trend != 1 and Trend[1] == 1
alertcondition(redColor, title="Sell", message="red sell")
答案 1 :(得分:0)
我的理解是,您只想检测颜色的变化,实际上这是变量Trend从1变为not(1),反之亦然。我建议:
change_detection_flag = Trend != Trend[1]
alertcondition(change_detection_flag,title="Change",message="color changed")
请注意,这不是在查看它之前是绿色,现在是红色,还是之前是红色,现在是绿色-根据要求。