why sometime delay 2 or 3 minutes to pop up alert message?

 

why sometime delay 2 or 3 minutes to pop up alert message? Code at below, which line of code causing the pop up alert message delay? 

#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

enum ENUM_SOUNDS{
   SOUND_ALERT,      //alert.wav
   SOUND_ALERT2,     //alert2.wav
   SOUND_CONNECT,    //connect.wav
   SOUND_DISCONNECT, //disconnect.wav
   SOUND_EXPERT,     //expert.wav
   SOUND_NEWS,       //news.wav
   SOUND_OK,         //ok.wav
   SOUND_STOPS,      //stops.wav
   SOUND_TICK,       //tick.wav
   SOUND_TIMEOUT,    //timeout.wav
   SOUND_WAIT,       //wait.wav
};

input int                  Candle         = 1;           //Number of Candle for signal (0 - current candle)
input string               NoteMess       = "<---- A L E R T S ---->";     //<--------------------->
input bool                 Alert_chart    = true;        //Show alerts on Chart
input bool                 Alert_email    = true;        //Send message to E-mail
input bool                 Alert_push     = true;        //Send message to Phone
input bool                 Alert_sound    = true;        //Play sound
input ENUM_SOUNDS          Sound          = SOUND_ALERT; //Sound Alert
input string               NoteSMA        = "<---- SMA CrossOver Justin ---->";     //<--------------------->
input string               NameSMA        = "SMA CrossOver_Justin (1).ex4"; //Indicator name      
input bool                 EachTickMode   = false;       //EachTickMode
input int                  Fast_MA_Period = 1;           //Fast_MA_Period
input int                  Slow_MA_Period = 34;          //Slow_MA_Period
input int                  Signal_Period  = 5;           //Signal_Period
input string               NoteBI         = "<---- The Best indicator ---->";     //<--------------------->
input string               NameBI         = "TheBeast Indicator V4.ex4"; //Indicator name      
input int                  WPRPeriod      = 1;           //WPRPeriod
input int                  HighWPR        = -5;          //HighWPR
input int                  LowWPR         = -95;         //LowWPR
input int                  RSIPeriod      = 2;           //RSIPeriod
input int                  HighRSI        = 90;          //HighRSI
input int                  LowRSI         = 10;          //LowRSI
input int                  CCIPeriod      = 3;           //CCIPeriod
input int                  HighCCI        = 99;          //HighCCI
input int                  LowCCI         = -99;         //LowCCI
input bool                 DoubleFilterRSI= false;       //DoubleFilterRSI
input int                  HighRSI2       = 95;          //HighRSI2
input int                  LowRSI2        = 5;           //LowRSI2

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(){
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]){
   double SMA_sell=iCustom(Symbol(),PERIOD_CURRENT,NameSMA,
               EachTickMode,Fast_MA_Period,Slow_MA_Period,Signal_Period,0,Candle);//BUY-1 SELL-0
   double SMA_buy=iCustom(Symbol(),PERIOD_CURRENT,NameSMA,
               EachTickMode,Fast_MA_Period,Slow_MA_Period,Signal_Period,1,Candle);//BUY-1 SELL-0

   double BI_buy=iCustom(Symbol(),PERIOD_CURRENT,NameBI,
               WPRPeriod,
               HighWPR,
               LowWPR,
               "",
               RSIPeriod,
               HighRSI,
               LowRSI,
               "",
               CCIPeriod,
               HighCCI,
               LowCCI,
               "",
               DoubleFilterRSI,
               HighRSI2,
               LowRSI2,
               "",
               true,
               false,
               "",
               "","","","","",0,1,0,Candle);//SELL-1 BUY-0
   double BI_sell=iCustom(Symbol(),PERIOD_CURRENT,NameBI,
               WPRPeriod,
               HighWPR,
               LowWPR,
               "",
               RSIPeriod,
               HighRSI,
               LowRSI,
               "",
               CCIPeriod,
               HighCCI,
               LowCCI,
               "",
               DoubleFilterRSI,
               HighRSI2,
               LowRSI2,
               "",
               true,
               false,
               "",
               "","","","","",0,1,1,Candle);//SELL-1 BUY-0               
               
   static datetime timeSig=0;
   if(time[0]>timeSig){
      if(SMA_buy<Ask*2 && BI_buy<Ask*2){
         string text=Symbol()+" "+TFtoString(PERIOD_CURRENT)+" BUY";
         Messenger(text,Alert_chart,Alert_email,Alert_push,Alert_sound,Sounds(Sound));
         timeSig=TimeCurrent();
      }
      if(SMA_sell<Ask*2 && BI_sell<Ask*2){
         string text=Symbol()+" "+TFtoString(PERIOD_CURRENT)+" SELL";
         Messenger(text,Alert_chart,Alert_email,Alert_push,Alert_sound,Sounds(Sound));
         timeSig=TimeCurrent();
      }   
   }   
   Comment(BI_buy,"|",BI_sell)   ;      
   return(rates_total);
}
//--------------------------------------------------------------------+
//        Send Notification (Chart, E-mail, Phone, Sound)             |
//--------------------------------------------------------------------+
void Messenger(string   text        , 
               bool     alert_chart ,
               bool     alert_email ,
               bool     alert_push  ,
               bool     alert_sound ,
               string   sound){

   if(alert_chart)Alert(text);
   if(alert_sound)PlaySound(sound);
   
   int NumberAttempts=5;

   int counterPhone=0;
   int counterEmail=0;
   int numberAttempt=0;
   datetime Timer=0;
   bool SetTimer=true;
   bool sendMessageToPhone=false;
   bool sendMessageToEmail=false;
   if(alert_push)sendMessageToPhone=true;
   if(alert_email)sendMessageToEmail=true;
   
   bool FirstAttempt=true;
   bool NextAttemptPhone=false;
   bool NextAttemptEmail=false;   
   
   while((sendMessageToEmail || sendMessageToEmail) && counterPhone<=numberAttempt && counterEmail<=numberAttempt){
      if(SetTimer){
         Timer=TimeCurrent();
         SetTimer=false;
      }
      if(FirstAttempt){
         if(!SendMessagePhone(text))NextAttemptPhone=true;
         if(!SendMessageEmail(text))NextAttemptEmail=true;
         FirstAttempt=false;
         counterPhone++;
         counterEmail++;
      }
      if(NextAttemptEmail){
         if(!SendMessageEmail(text))SetTimer=true;
         else{
            NextAttemptEmail=false;
            sendMessageToEmail=false;
         }
         counterEmail++; 
      }
      if(NextAttemptPhone && TimeCurrent()-Timer>=7){
         if(!SendMessagePhone(text))SetTimer=true;
         else{
            NextAttemptPhone=false;
            sendMessageToPhone=false;
         }
         counterPhone++;         
      }
      if(counterEmail>=NumberAttempts)sendMessageToEmail=false;
      if(counterPhone>=NumberAttempts)sendMessageToPhone=false;
   }
}
//+------------------------------------------------------------------+
//|              Send Message Phone                                  |
//+------------------------------------------------------------------+
bool SendMessagePhone(string text){
   if(!IsTesting()){
      ResetLastError();
      if(!SendNotification(text)){
         Print(__FUNCTION__," ",GetLastError());
         return(false);
      }
   }
   return(true);
}
//+------------------------------------------------------------------+
//|              Send Message E-mail                                 |
//+------------------------------------------------------------------+
bool SendMessageEmail(string text){
   if(!IsTesting()){
      ResetLastError();
      if(!SendMail(text,text)){
         Print(__FUNCTION__," ",GetLastError());
         return(false);
      }
   }
   return(true);
}
//--------------------------------------------------------------------+
//                      Return name of sound file                     |
//--------------------------------------------------------------------+
string Sounds(ENUM_SOUNDS sound){
   if(sound==SOUND_ALERT)     return("alert.wav");
   if(sound==SOUND_ALERT2)    return("alert2.wav");
   if(sound==SOUND_CONNECT)   return("connect.wav");
   if(sound==SOUND_DISCONNECT)return("disconnect.wav");
   if(sound==SOUND_EXPERT)    return("expert.wav");
   if(sound==SOUND_NEWS)      return("news.wav");
   if(sound==SOUND_OK)        return("ok.wav");
   if(sound==SOUND_STOPS)     return("stops.wav");
   if(sound==SOUND_TICK)      return("tick.wav");
   if(sound==SOUND_TIMEOUT)   return("timeout.wav");
   if(sound==SOUND_WAIT)      return("wait.wav");
   return("alert.wav");
}
//--------------------------------------------------------------------+
//      Time Frame to String                                          |
//--------------------------------------------------------------------+
string TFtoString(ENUM_TIMEFRAMES TimeFrame){
   string value="";
   int tf=PeriodSeconds(TimeFrame)/60;
   if(tf==1)value="M1";
   if(tf==5)value="M5";
   if(tf==15)value="M15";
   if(tf==30)value="M30";
   if(tf==60)value="H1";
   if(tf==240)value="H4";
   if(tf==1440)value="D1";
   if(tf==10080)value="W1";
   if(tf==43200)value="MN1";
   return(value);
}
Automated Trading and Strategy Testing
Automated Trading and Strategy Testing
  • www.mql5.com
Ask questions on technical analysis, discuss trading systems and improve your MQL5 programming skills to develop your own trading strategies. Communicate and share your experience with traders from anywhere in the world, answer questions and help beginners — MQL5.community is developing along with you. why sometime delay 2 or 3 minutes to pop...
 
Zac are you refering to alert_chart type of message? 
Have you checked alert using some simple fast trigger like bar open? Perhaps the custom indicator is the issue? Also which time you checked? In slow market time like evening, sometimes bar & tick comes in minutes interval and this indicator is working in tick mode so if there is no tick then there is no alert
 
Sergey Golubev:

Done. Sorry I am 1st time using this forum haha.

 
Bartlomiej Gorski:
Zac are you refering to alert_chart type of message? 
Have you checked alert using some simple fast trigger like bar open? Perhaps the custom indicator is the issue? Also which time you checked? In slow market time like evening, sometimes bar & tick comes in minutes interval and this indicator is working in tick mode so if there is no tick then there is no alert

I see. Thanks for the guidelines, I am going to check them now.

 
      if(SMA_buy<Ask*2 && BI_buy<Ask*2){
Likely bogus test. SMA should be near market. EURUSD is at 1.23 so twice that is 12300 pips away. Use the debugger or print out your variables, and find out why.
Reason: