Wrote an strategy and having an issue with same type of alert (buy or sell) firing multiple times in a row
i.e buy, sell, sell, buy, buy, buy, sell
I need only one alert (for buy or sell) to fire at a given time till the next condition cancel the prior
i.e buy, sell, buy, sell, buy
I’ll post just my logic to execute or not the alert, hopefully that will suffice to get a second opinion here:
if buy
buy_signal := true
sell_signal:= false
if sell
sell_signal := true
buy_signal := false
// buy condition represents the boolean check above + other logic in the strategy
buyCondition = buy_signal and close > signal
sellCondition = sell_signal and close < signal
buyAlert = buyCondition and not buyCondition[1]
sellAlert = sellCondition and not sellCondition[1]
// ALERT (SHOULD ONLY FIRE ONCE PER CONDITION MET)
if buyAlert and not buyAlert[1]
alert(long, alert.freq_once_per_bar)
if sellAlert and not sellAlert[1]
alert(short, alert.freq_once_per_bar)
issue shown on pictures bellow