Alert triggering 3 or 4 times?

 

Hi

 

I have an alert in my indicator when it triggers its giving me the message multiple times?

Here is the code, I would just like the alert to send once please.

  

 if (Time[0] >= TimeCurrent())
      {
         AlertStatus = true;
         if (AlertStatus == true)
         {
            var1=TimeToStr(Time[0],TIME_DATE|TIME_SECONDS) + " " + Symbol()+ "  Potential Long Reversal";
            AlertStatus = false;
            if (MsgAlert == true) Alert(var1);
            if (SoundAlert == true) PlaySound("alert.wav");
 
kraziekris: I have an alert in my indicator when it triggers its giving me the message multiple times?
AlertStatus = true;
if (AlertStatus == true)
Don't look for a level; look for a change in level
bool StatusPrev = AlertStatus;
AlertStatus = true;
if (AlertStatus && !StatusPrev)

You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
 

Hi, thanks for the info, I actually had this coded for me a while back and cannot get hold of the guy who did it.

 There are actually 2 alerts, one for high and one for low.

 The code for alerts is here

 

  if (VHigh >= 8) 
   {
      //PlaySound("alert.wav");
      bool AlertStatus = true;
      if (Time[0] >= TimeCurrent())
      {
         Print(Time[0] >= TimeCurrent());
         AlertStatus = true;
         if (AlertStatus == true)
         {
            string var1=TimeToStr(Time[0],TIME_DATE|TIME_SECONDS) + " " + Symbol()+ " Potential Short Reversal";
            AlertStatus = false;
            if (MsgAlert == true) Alert(var1);
            if (SoundAlert == true) PlaySound("alert.wav");
         } 
      }      
   }
   
   if (VLow <= -8) 
   {
      if (Time[0] >= TimeCurrent())
      {
         AlertStatus = true;
         if (AlertStatus == true)
         {
            var1=TimeToStr(Time[0],TIME_DATE|TIME_SECONDS) + " " + Symbol()+ "  Potential Long Reversal";
            AlertStatus = false;
            if (MsgAlert == true) Alert(var1);
            if (SoundAlert == true) PlaySound("alert.wav");
         }  
      }
   }

 

Could you please help me mod this code. I tried the obvious approach and got errors. This is the code after I modded.

 

 if (VHigh >= 8) 
   {
      //PlaySound("alert.wav");
      bool StatusPrev = AlertStatus;
      if (Time[0] >= TimeCurrent())
      {
         Print(Time[0] >= TimeCurrent());
         AlertStatus = true;
         if ((AlertStatus && !StatusPrev)
         {
            string var1=TimeToStr(Time[0],TIME_DATE|TIME_SECONDS) + " " + Symbol()+ " Potential Short Reversal";
            AlertStatus = false;
            if (MsgAlert == true) Alert(var1);
            if (SoundAlert == true) PlaySound("alert.wav");
         } 
      }      
   }
   
   if (VLow <= -8) 
   {
      if (Time[0] >= TimeCurrent())
      {
         AlertStatus = true;
         if (AlertStatus && !StatusPrev)
         {
            var1=TimeToStr(Time[0],TIME_DATE|TIME_SECONDS) + " " + Symbol()+ "  Potential Long Reversal";
            AlertStatus = false;
            if (MsgAlert == true) Alert(var1);
            if (SoundAlert == true) PlaySound("alert.wav");
         }  
      }
   }

 

I get all sorts of errors....

any more help would be great... 

 
Previously answered, don't look for a level
 if (VHigh >= 8) 
Look for a change in level
double VHighPrev = VHigh;
VHigh = ...
if (VHigh >= 8 && VHighPrev < 8) 
Reason: