在Pine脚本中,如何通过引用上一个栏来消除多个警报
在TradingView Pine脚本中,如何通过引用先前的栏来消除多个背对背警报?例如,下面的警报可能会连续多次触发。我希望它仅在上一个栏尚未达到触发因素的情况下才能触发。这样,它就不会背对背。
indicator(title="DIs Indicator v1", shorttitle="DIs Indicator v1", format=format.price, precision=4, timeframe="", timeframe_gaps=true)
// Get User Inputs
len = input.int(defval=5, minval=1, title="ADX and DI Length", group="ADX and DI")
adxThreshhold = input.int(title="ADX Threshhold",defval=20, group="ADX and DI")
diAbove = input.int(title="DIAbove",defval=20, group="ADX and DI")
diBelow = input.int(title="DIBelow",defval=20, group="ADX and DI")
// ADX Value
TrueRange = math.max(math.max(high-low, math.abs(high-nz(close[1]))), math.abs(low-nz(close[1])))
DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? math.max(high-nz(high[1]), 0): 0
DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? math.max(nz(low[1])-low, 0): 0
SmoothedTrueRange = 0.0
SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange
SmoothedDirectionalMovementPlus = 0.0
SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus = 0.0
SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus
DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = math.abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100
ADX = ta.sma(DX, len)
//Plot
hline(price=adxThreshhold,color=color.white,linestyle=hline.style_dashed)
ADXBuySignal = DIPlus > diAbove and DIMinus < diBelow
ADXSellSignal = DIMinus > diAbove and DIPlus < diBelow
plot(ADX, color=color.yellow, title="ADX")
plot(DIPlus, color=color.blue, title="+DI")
plot(DIMinus, color=color.purple, title="-DI")
plotshape (ADXBuySignal, color=color.green, style=shape.circle)
plotshape (ADXSellSignal, color=color.red, style=shape.circle)
// Trigger alerts
alertcondition(ADXBuySignal, title="ADXBuySignal", message="ADXBuySignal {{ticker}}")
alertcondition(ADXSellSignal, title="ADXSellSignal", message="ADXSellSignal {{ticker}}")```
In TradingView Pine Script how do I eliminate multiple back to back alerts by referencing the prior bar? For example, the alert below may trigger multiple times in a row. I would like it to only trigger if the previous bar had not already met the trigger factors. This way it doesn't back to back.
indicator(title="DIs Indicator v1", shorttitle="DIs Indicator v1", format=format.price, precision=4, timeframe="", timeframe_gaps=true)
// Get User Inputs
len = input.int(defval=5, minval=1, title="ADX and DI Length", group="ADX and DI")
adxThreshhold = input.int(title="ADX Threshhold",defval=20, group="ADX and DI")
diAbove = input.int(title="DIAbove",defval=20, group="ADX and DI")
diBelow = input.int(title="DIBelow",defval=20, group="ADX and DI")
// ADX Value
TrueRange = math.max(math.max(high-low, math.abs(high-nz(close[1]))), math.abs(low-nz(close[1])))
DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? math.max(high-nz(high[1]), 0): 0
DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? math.max(nz(low[1])-low, 0): 0
SmoothedTrueRange = 0.0
SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange
SmoothedDirectionalMovementPlus = 0.0
SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus = 0.0
SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus
DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = math.abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100
ADX = ta.sma(DX, len)
//Plot
hline(price=adxThreshhold,color=color.white,linestyle=hline.style_dashed)
ADXBuySignal = DIPlus > diAbove and DIMinus < diBelow
ADXSellSignal = DIMinus > diAbove and DIPlus < diBelow
plot(ADX, color=color.yellow, title="ADX")
plot(DIPlus, color=color.blue, title="+DI")
plot(DIMinus, color=color.purple, title="-DI")
plotshape (ADXBuySignal, color=color.green, style=shape.circle)
plotshape (ADXSellSignal, color=color.red, style=shape.circle)
// Trigger alerts
alertcondition(ADXBuySignal, title="ADXBuySignal", message="ADXBuySignal {{ticker}}")
alertcondition(ADXSellSignal, title="ADXSellSignal", message="ADXSellSignal {{ticker}}")```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要检查您的信号是否不是
true
一个bar,并且它是true
在当前栏上。You need to check if your signal was not
true
one bar ago and it istrue
on the current bar.