Are you accounting for multiple symbols in the watchlist?
Can you post the text from Output Window and make sure that you're not generating signals on those bars.
AlertIf() works correctly, but you need to make sure that signals aren't fired or and you are testing with right timeframe and periodicity that you think it should be.
The small bit of code you posted is syntactically correct and that's all I can test with.
It works fine at my end.
so there must be an issue in other parts of your code.
Check if your code fires multiple signals of Different type on the same bar.
This can cause AlertIf() to flip flop.