Have 2 alertconditions set up, one for a Buy Signal and one for a Sell Signal. I want the alerts to be always active, but only show on the bar the alertcondition evaluates to true. Which is what this code should be doing, but somehow the alerts continuously fire every bar even when the condition for it evaluates to false.
// Update signalBarIndex when a new signal is generated - otherwise leave it the original bar index
if (signal != 0)
signalBarIndex := isDifferentSignalType and (isNewBuySignal or isNewSellSignal) ? bar_index : signalBarIndex
// Condition to check if the alert should fire (same bar or next bar)
isAlertActive = bar_index == signalBarIndex
alertcondition(signal == 1 and isAlertActive, title="Buy Signal")
alertcondition(signal == -1 and isAlertActive, title="Sell Signal")
As you can see in the picture, the bar_index and signalBarIndex ARE NOT equal so this should not be firing every bar, but it is. I also provided the alert settings, which fires once per bar, but from what I read it should only fire when the alertcondition is true. How can I fix this?
pic of chart with indexes
alert settings
I’ve tried multiple different things, but this code should work as the condition clearly evaluates to false.
Matt E is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.