提醒每根新蜡烛我怎么能只有一个提醒

Alert each new candle how can i have just one alert

同一脚本的另一个问题。

我已经添加了警报,我希望我只在更改颜色时收到警报,但没有...我收到每支新蜡烛。

怎么可能只在颜色变化时才提示?

study("v 2", overlay=true)

varLo = input(title="Fast (Conversion) Line", type=integer, defval=9, minval=1, maxval=99999)
varHi = input(title="Slow (Base) Line", type=integer, defval=26, minval=1, maxval=99999)
emafreq = input(title="Ema on price frequency", type=integer, defval=2, minval=1, maxval=99999)

a = lowest(varLo)
b = highest(varLo)
c = (a + b ) / 2

d = lowest(varHi)
e = highest(varHi)
f = (d + e) / 2

//g = ((c + f) / 2)[varHi]
//h = ((highest(varHi * 2) + lowest(varHi * 2)) / 2)[varHi]

z = ema(close, emafreq)

bggreen = (z > c and z > f)
bgred = (z < c and z < f)

bgcolor(bggreen ? green : bgred ? red : na)
alertcondition(condition=bggreen, title="Buy", message="green buy")
alertcondition(condition=bgred, title="Sell", message="red sell")
plot(z, title="ema on Price", color=black)
plot(c, title="Fast (Conversion) Line", color=green)
plot(f, title="Slow (Base) Line", color=red)

当它是“新”绿色或“新”红色时,我只想要一个警报。

谢谢

那是因为你把你的条件和背景颜色联系起来了。因此,它将在多个柱上变为 true

您需要做的是,检查当前柱的颜色是否改变。因此,检查它在前一个柱上是否不是绿色以及在当前柱上是否是绿色。

is_new_green = not bggreen[1] and bggreen
is_new_red = not bgred[1] and bgred

bgcolor(bggreen ? green : bgred ? red : na)
alertcondition(is_new_green, title="Buy", message="green buy")
alertcondition(is_new_red, title="Sell", message="red sell")