当不满足警报条件时,Pine 脚本警报显示而没有关闭栏(实时)

Pine script alert shows up without bar closed (real-time) when alertcondition is not met

我正在使用此代码,警报仍作为实时数据激活。

showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)

bb1 = cross(a1, a2) and rsi < 45 and srsi < 30 and d < 20
bb2 = cross(b1, b2) and rsi < 45 and srsi < 30 and d < 20

alertcondition(condition=bb1 and showsignals ? up : na and barstate.isconfirmed)
alertcondition(condition=bb2 and showsignals ? up : na and barstate.isconfirmed)

此代码会发出错误警报,而真正的警报有时不会出现。我已将警报设置为 'once per bar closed'。

哪里出了问题?

谢谢

如果您使用依赖于 high lowclose 的任何东西,而没有使用历史引用运算符在某个时间点延迟数据,例如close[1] 您正在使用更新每个报价单的实时值。这意味着条件可能会在逐个滴答的基础上评估为真,然后为假。这叫重绘。

您的代码不完整,但显而易见的方法是将 [1] 添加到 bb1 和 bb2,

alertcondition(condition=bb1[1] and showsignals ? up : na and barstate.isconfirmed)
alertcondition(condition=bb2[1] and showsignals ? up : na and barstate.isconfirmed)

这意味着最后(已确认)柱的条件评估为真。