Download MetaTrader 5
To add comments, please log in or register
Publish your article to let the traders see it in MetaTrader 5!
Akshay
48
Akshay 2015.10.22 06:16 

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
5937
Carl Schreiber 2015.10.22 08:46  

You can now use:

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

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
5937
Carl Schreiber 2015.10.22 10:42  
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
954
honest_knave 2015.10.22 10:43  

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 2015.10.23 05:44  
Thanks, After removing the #property from EA,  problem solved :)
/
To add comments, please log in or register