在Pine脚本中,如何通过引用上一个栏来消除多个警报

发布于 2025-02-04 18:35:09 字数 2305 浏览 4 评论 0原文

在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还如梦归 2025-02-11 18:35:10

您需要检查您的信号是否不是 true一个bar,并且它 true在当前栏上。

isNewADXBuySignal = not ADXBuySignal[1] and ADXBuySignal
isNewADXSellSignal = not ADXSellSignal[1] and ADXSellSignal

alertcondition(isNewADXBuySignal, title="ADXBuySignal", message="ADXBuySignal {{ticker}}")
alertcondition(isNewADXSellSignal, title="ADXSellSignal", message="ADXSellSignal {{ticker}}")

You need to check if your signal was not true one bar ago and it is true on the current bar.

isNewADXBuySignal = not ADXBuySignal[1] and ADXBuySignal
isNewADXSellSignal = not ADXSellSignal[1] and ADXSellSignal

alertcondition(isNewADXBuySignal, title="ADXBuySignal", message="ADXBuySignal {{ticker}}")
alertcondition(isNewADXSellSignal, title="ADXSellSignal", message="ADXSellSignal {{ticker}}")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文