alert once

 

Does this code only check the Bid > Bands at the first tick of each bar?

I want the alert to sound once but for the code to be checked on every tick during the bar:


         // 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, Sigma, 0, PRICE_CLOSE, MODE_UPPER, 0)) {PlaySound("button-8.wav");}
            if (Bid <= iBands(Symbol(),NULL, 20, Sigma, 0, PRICE_CLOSE, MODE_LOWER, 0)) {PlaySound("button-8.wav");}
         }
 
well, if you read your comments, you will have the answer
 
zzuegg:
well, if you read your comments, you will have the answer

Yes, but how do I get it to check on every tick?

Should I add the Bid>Bands part to this section:

 if (Time[0] > MostRecentBarStart)

so:
      //Alerts
      // See if this bar is new
         if 
         (  Time[0] > MostRecentBarStart &&
            ((Bid  >= iBands(Symbol(),NULL, 20, Sigma, 0, PRICE_CLOSE, MODE_UPPER, 0)) || 
             (Bid <= iBands(Symbol(),NULL, 20, Sigma, 0, PRICE_CLOSE, MODE_LOWER, 0))
            )
         ) 
         {
            // Store the time of the current bar, preventing further action during this bar
	         MostRecentBarStart = Time[0];
            PlaySound("button-8.wav");
         }
 
         // See if this bar is new and conditions are met
         static datetime MostRecentBarStart=0;
         if (Time[0] != MostRecentBarStart &&
            ((Bid  >= iBands(Symbol(),NULL, 20, Sigma, 0, PRICE_CLOSE, MODE_UPPER, 0) || 
             (Bid <= iBands(Symbol(),NULL, 20, Sigma, 0, PRICE_CLOSE, MODE_LOWER, 0)
            )
         ) 
         {
            // Store the time of the current bar, preventing further action during this bar
                 MostRecentBarStart = Time[0];
            PlaySound("button-8.wav");
         }
should work...
 
zzuegg:
should work...

Can I set this at bthe top of the indicator?

static datetime MostRecentBarStart=0;

if it's  in the start() code, won't it be reset every tick?
 

hi,

if you declare the variable as static is not reset every tick, for that reason is static.