Download MetaTrader 5

Time Alert calculation..!!

To add comments, please log in or register
Akshay
48
Akshay  

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);
}
Carl Schreiber
6691
Carl Schreiber  

You can now use:

extern datetime Alert_Time = D'21:45';
Akshay
48
Akshay  

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

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

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) 

Akshay
48
Akshay  
Thanks, After removing the #property from EA,  problem solved :)
To add comments, please log in or register