Need assiatnce in checking Time Based Alert

 

Hi, I Have written an EA which should generate alert as soon as time exceed the current sever time. My time zone differ from server time by 30 min so I have a condition like

 if (Cur_time >(Alert_Time_1 - 0.30))  Alert ()

But Instead of working on Alert time it executes on very next tick. Please show me the right way to use time function in attached EA.


//+------------------------------------------------------------------+
//|                                                   Time Alert.mq4 |
//|                                                      Akshay Jain |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Akshay Jain"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict


extern double Alert_Time_1 = 19.30;
input string MSG1 = "Hi, type you msg here";
input double Alert_Time_2 =12.30;
extern string MSG2 = "Hi, type you msg here";
bool   T1 = false;
bool   T2 = false;
input double High_Alert  = 100000;
input double Low_Alert  = 0;
bool SP1 = false;
bool SP2 = false;
//--------------------------------------------------------------- 2 --
int start()                            // Spec. start function
  {
  int    Cur_Hour=Hour();             // Server time in hours
   double Cur_Min =Minute();           // Server time in minutes
   double Cur_time=Cur_Hour + Cur_Min;  
  
   
   if (Cur_time >(Alert_Time_1 - 0.30) && T1 == false)             // If the time for the event has come
   
   {
    Alert(MSG1);
    string subject   = (MSG1);
    string some_text = "";
    SendMail( subject,  some_text);
    PlaySound("PriceAlert.wav");    
    SendNotification (MSG1);
   T1 = true;
   }
   
    
   if (Cur_time>(Alert_Time_2 - 0.30) && T2 == false)             // If the time for the event has come
  
   {
      Alert(MSG2);
     string subject   = (MSG2);
     string some_text = "";
     SendMail( subject,  some_text);
     PlaySound("PriceAlert.wav"); 
     SendNotification (MSG2); 
   T2 = true;
   }
     
     
    if (Bid >= High_Alert && SP1 == false)
{
Alert(Symbol()," High_Alert at ", DoubleToStr(High_Alert) ," is complete at " ,TimeToStr(TimeLocal(),TIME_SECONDS));
   string subject   = (Symbol()+ " High_Alert at " + DoubleToStr(High_Alert) + " is complete at " + TimeToStr(TimeLocal(),TIME_SECONDS));
   string some_text = "";
   SendMail( subject,  some_text);
      PlaySound("PriceAlert.wav");    
   SP1 = true;
} 
     
      if (Bid <= Low_Alert && SP2 == false)
{
Alert(Symbol()," Low_Alert at ", DoubleToStr(Low_Alert) ," is complete at " ,TimeToStr(TimeLocal(),TIME_SECONDS));
   string subject   = (Symbol()+ " Low_Alert at " + DoubleToStr(Low_Alert) + " is complete at " + TimeToStr(TimeLocal(),TIME_SECONDS));
   string some_text = "";
   SendMail( subject,  some_text);
      PlaySound("PriceAlert.wav");    
   SP2 = true;
} 
     
   
   return(0);                             // Exit from start()
} 
 
  int    Cur_Hour=Hour();             // Server time in hours
   double Cur_Min =Minute();           // Server time in minutes
   double Cur_time=Cur_Hour + Cur_Min/100;  
  
As you are inputting time as a decimal, you need to divide the minutes by 100
 

Hi,

 Thanks for your prompt response, it worked correctly after your suggestion :)

 
akshay12489:

Hi,

  Sorry to bother you again, but unfortunately I'm missing something. Lets say I want to generate an alert at 13:00  and server time is 12:25 so I added a server lag of 30 min but its still end of getting alert on wrong time.  Im posting a shorter version this time please correct it.

extern double Alert_Time_1 = 13.00;
input string MSG1 = "Hi, type you msg here";
bool   T1 = false;

//--------------------------------------------------------------- 2 --
int start()                            // Spec. start function
  {
  
  int server_lag = 30;
    if (TimeCurrent()+ server_lag/100 >=Alert_Time_1  && T1 == false)             // If the time for the event has come
  
   {
     Alert(MSG1);
     T1 = true;
   }





 

Why don't you trigger the alert based on your local time? TimeLocal()

Start() will only get called when a new tick comes in. If there is no tick, there is no check of your alert.

Try running your alert from OnTimer() with maybe a 1 second timer

 

Thanks Knave, I have no issue with TimeLocal() can you tell me what data type should I use before Alert_Time_1 to correctly execute the condition mentioned below


 if (TimeLocal() >=Alert_Time_1  )  
Alert ();


Also let say I want to execute an alert on Local pc time 19:30, should I write Alert_Time_1 = 19.30 or after converting the fractional part to 19 hr + 30/60 min = 19.5 ?

Reason: