How to stop repeating Alert

To add comments, please log in or register
walidabou
41
walidabou  

Hi EveryBody ,, i have a a problem with my simple expert advisor which gives Alert with some conditions as shown in code below ,, but the Alert works when every tick ,, how can i stop it ??

Thanks in advance


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
   
double Kijun_H4_2 = iIchimoku(Symbol(), 240, 9, 26, 52, MODE_KIJUNSEN, 2),
       Kijun_H4_1 = iIchimoku(Symbol(), 240, 9, 26, 52, MODE_KIJUNSEN, 1);
       
       if(iClose(Symbol(), 240, 2) < Kijun_H4_2 && iClose(Symbol(), 240, 1) > Kijun_H4_1)
       {
         
         Alert("Break Up on " + Symbol());
         
       }
       
       else if(iClose(Symbol(), 240, 2) > Kijun_H4_2 && iClose(Symbol(), 240, 1) < Kijun_H4_1)
       {
        
         Alert("Break Down on " + Symbol());
         
       }

  }
//+------------------------------------------------------------------+
Keith Watford
Moderator
21914
Keith Watford  
   static datetime alert_bar_time=0;

   double Kijun_H4_2=iIchimoku(Symbol(),240,9,26,52,MODE_KIJUNSEN,2),
   Kijun_H4_1=iIchimoku(Symbol(),240,9,26,52,MODE_KIJUNSEN,1);

   if(alert_bar_time!=iTime(Symbol(),240,0))
     {
      alert_bar_time=iTime(Symbol(),240,0);
      if(iClose(Symbol(),240,2)<Kijun_H4_2 && iClose(Symbol(),240,1)>Kijun_H4_1)
        {
         Alert("Break Up on "+Symbol());
        }

      else if(iClose(Symbol(),240,2)>Kijun_H4_2 && iClose(Symbol(),240,1)<Kijun_H4_1)
        {
         Alert("Break Down on "+Symbol());
        }
     }

.

walidabou
41
walidabou  
GumRai:

.

Thank you very much Friend
William Roeder
20741
William Roeder  
You are alerting on a condition. Remembering the alert time is one way.
if(iClose(Symbol(), 240, 2) < Kijun_H4_2 && iClose(Symbol(), 240, 1) > Kijun_H4_1){
   Alert("Break Up on " + Symbol());
}
The other is look for a change in the condition.
static bool is_up=false; 
bool was_up = is_up;
is_up = iClose(Symbol(), 240, 2) < Kijun_H4_2 && iClose(Symbol(), 240, 1) > Kijun_H4_1;
if(is_up && !was_up){
   Alert("Break Up on " + Symbol());
}
Malcolm Okechukwu
37
Malcolm Okechukwu  
Thanks Keith Watford for the reply on Walidabou difficulties, however, all global variables are static by default, so, there would be no need including the static keyword in defining the datatime variable except inside a function where variables are dynamic (not static) by default. 
Malcolm Okechukwu
37
Malcolm Okechukwu  
datetime curTime = 0;
datetime prevTime = iTime(_Symbol, _Period, 0);

if (curTime != prevTime) {
 Alert("do something ");
 curTime = prevTime;
}
Keith Watford
Moderator
21914
Keith Watford  
Malcolm Okechukwu:
Thanks Keith Watford for the reply on Walidabou difficulties, however, all global variables are static by default, so, there would be no need including the static keyword in defining the datatime variable except inside a function where variables are dynamic (not static) by default. 

Walidabou's code is inside the function OnTick() so the static datetime variable is necessary..

Keith Watford
Moderator
21914
Keith Watford  
Malcolm Okechukwu:
datetime curTime = 0;
datetime prevTime = iTime(_Symbol, _Period, 0);

if (curTime != prevTime) {
 Alert("do something ");
 curTime = prevTime;
}

Use the code button (Alt + S) when posting code.

Seems to me that you have curTime and prevTime back to front.

Your datetime variable curTime needs to be static as it will not be remembered next execution.

Why are you replying to a 4 year old thread ?

Guillaume Perinet
22
Guillaume Perinet  
walidabou:

Hi EveryBody ,, i have a a problem with my simple expert advisor which gives Alert with some conditions as shown in code below ,, but the Alert works when every tick ,, how can i stop it ??

Thanks in advance


Well, I am using this for an indicator and in the section   

for (i=limit; i>=0;i--) 

I use :

if (i<1) Alert("do something ");

If I do not, every time I modify/compile the indicator or open it, it sends so many notifications. Hope this comment may help.

William Roeder
20741
William Roeder  
Guillaume Perinet: I use :
if (i<1) Alert("do something ");

That condition will be true each and every tick.

To add comments, please log in or register