Time Alert calculation..!!

 

Hi,

I'm trying to generate alert by EA at a specific time in MT4 . What data type I should use before Alert_time to correctly execute the code.


extern double Alert_Time = 21.45;
input string MSG = "Hi, type you msg here";
bool   T = false;

//--------------------------------------------------------------- 2 --
int start()                            // Spec. start function
  {
  
    if (TimeLocal() >=Alert_Time && T == false)             // If the time for the event has come
  
   {
     Alert(MSG);
     T = true;
   }
return(0);
}
 

You can now use:

extern datetime Alert_Time = D'21:45';
 

Thank you so much for your suggestion :) 

It solved a big headache for me.

One small issue I'm facing that it pick a random date if I use D' is it possible to use today's date by default as I usually set alerts for the same day

 
Well you could risk a look into the editors reference: datetime yyyy.mm.dd hh:mm:ss - so D'2015.10.22 21:45'
 

It should pick today's date, or maybe the date when the EA was last initialized (not sure which, probably the latter).

If you still have problems, you'll need to calculate it:

datetime Alert_Time = D'21:45';
#define DAY 86400
datetime now      = TimeCurrent(),
         midnight = now - (now % DAY),
         alert    = midnight + (Alert_Time % DAY);


Or use enumerations and have dropdown list(s) 

 
Thanks, After removing the #property from EA,  problem solved :)
Reason: