Alerts in indicator looping..

 
I added an Alert to an indicator and it loops continusouly...

Is there a way to add an Alert to an indicator using the Alert function without it looping or do you have to use it in experts only...

thanks

david
 
In an indicator you'll need to make sure that once your condition is met, you don't Alert on the same bar again. Something like this:
   static datetime lasttimealert= 0;


...


  if (lasttimealert!=Time[0] &&  ...some signal condition.... ) {
         Alert("Blah blah ", Symbol(),"/",Period());
         lasttimealert= Time[0];
   }




Markus

 
that works great.. thanks so much...

Is there a "code snippet" thread on this forum.. if not perhaps the moderator could create a place for code snippets like this...

thanks again

david
 
I am attempting to modify an existing indicator to generate alerts. i have used the code above and got it to display alerts; however i don't believe it is function properly. It is not displaying the last signal triggered. Furthermore, i noticed that all the alerts are triggered in the same time for the various condition and not only the last one. I am also trying to have date and time the event triggered displayed in the alert but no luck there either. I will post the code snippet pertaining to the alert for your review and comments
 
if (PrintTags)
      {
            
            TagName = "Entry" + TagCount;
            ObjectCreate(TagName, OBJ_TEXT, 0, Time[i], RangeLimit+40*Point);
            if(Shorttxt)
                     {
                 ObjectSetText(TagName,"S "+" "+Lots+"  "+TagCount +"  (" + DoubleToStr(Close[i],4) + ")", 9, "Arial", White);
                     }
                
                 else
                     {
                 ObjectSetText(TagName, "SELL "+" "+Lots+" Lots  " + TagCount + " (" + DoubleToStr(Close[i],4) + ")", 9, "Arial", White);
                     }
                    
          if (ScreenAlerts)
           { 
            

          if (lasttimealert!=Time[i] && SellPrimed)
               {
                  Alert("SELL "+Symbol()+" "+Lots+" Lots  " + "(" + DoubleToStr(Close[i],4) + ")"+"  "+Day()+"/"+Month()+"/"+Year()+" ("+Hour()+":"+Minute()+":"+Seconds()+")");
               if (EmailAlerts)
                     {
                  SendMail("4HR Tunnel Alert","SELL "+Symbol()+" "+Lots+" Lots  " + TagCount + "(" + DoubleToStr(Close[i],4) + ")"); 
                     }
            lasttimealert= Time[i];
               }
          } 
         
        }
      }
    }



Thank you in advance

 
AB,

if you just want to check current signals you should do your check for alerting only when i==0 ... (e.g. if (ScreenAlerts && i==0) ... ).



Markus
 
Here is what i changed it to but i am still not getting the correct time tag in the alert. It pulls time as (23:0:0).
if (PrintTags)
      {
            
            TagName = "Entry" + TagCount;
            ObjectCreate(TagName, OBJ_TEXT, 0, Time[i], RangeLimit+40*Point);
            if(Shorttxt)
                     {
                 ObjectSetText(TagName,"S "+" "+Lots+"  "+TagCount +"  (" + DoubleToStr(Close[i],4) + ")", 9, "Arial", White);
                     }
                
                 else
                     {
                 ObjectSetText(TagName, "SELL "+" "+Lots+" Lots  " + TagCount + " (" + DoubleToStr(Close[i],4) + ")", 9, "Arial", White);
                     }
                    
          if (ScreenAlerts && i==0)
           { 
            

          if (lasttimealert!=Time[i] && SellPrimed)
               {
                  Alert("SELL "+Symbol()+" "+Lots+" Lots  " + "(" + DoubleToStr(Close[i],4) + ")"+"  "+Day()+"/"+Month()+"/"+Year()+" ("+Hour()+":"+Minute()+":"+Seconds()+")");
               if (EmailAlerts)
                     {
                  SendMail("4HR Tunnel Alert","SELL "+Symbol()+" "+Lots+" Lots  " + TagCount + "(" + DoubleToStr(Close[i],4) + ")"); 
                     }
            lasttimealert= Time[i];
               }
          } 
         
        }
      }
    }
Reason: