alert once not working

 

I tried adding this code to stop the alerts from sounding continuiously. They should only sound once for each candle. If a new candle starts, then it should be reset and allowed to sound again.

Any ideas on what is wrong with the code?

// Store the start time of the most recent bar which has been examined, in a static variable which persists
// across calls to start() - but ***not*** across reloads of the EA...
static int MostRecentBarStart = 0;
.....
.....

int counted_bars = IndicatorCounted();
int i;
int limit;
if(counted_bars < 0)
return(-1);
if(counted_bars > 0)
counted_bars--;
if (Point==0.00001) iDigits=5;
if (Point==0.001) iDigits=3;

limit = Bars - counted_bars;
for(i=0; i<=limit; i++)
{

// See if this bar is new
if (Time[0] > MostRecentBarStart)
{
// Store the time of the current bar, preventing further action during this bar
MostRecentBarStart = Time[0];
//...process potential signals here
if (Bid > iBands(Symbol(),NULL, 20, 2, 0, PRICE_CLOSE, MODE_UPPER, 0)) {Alert( "Event "+Symbol());}
if (Bid < iBands(Symbol(),NULL, 20, 2, 0, PRICE_CLOSE, MODE_LOWER, 0)) {Alert( "Event "+Symbol());}

}

.....

.....