Download MetaTrader 5
To add comments, please log in or register
Ask your broker to open the official channel. Thousands of traders will read the news!
walidabou
35
walidabou 2016.09.27 18:39 

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
8028
Keith Watford 2016.09.27 18:50  
   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
35
walidabou 2016.09.28 10:38  
GumRai:

.

Thank you very much Friend
whroeder1
13656
whroeder1 2016.09.28 11:28  
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());
}
/
To add comments, please log in or register