Time Alert calculation..!!

Back to topics list To post a new topic, please log in or register
avatar
12
akshay12489 2015.10.22 08: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);
}
avatar
2017
gooly 2015.10.22 10:46 #
 

You can now use:

extern datetime Alert_Time = D'21:45';


avatar
12
akshay12489 2015.10.22 12: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

avatar
2017
gooly 2015.10.22 12: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'
avatar
736
honest_knave 2015.10.22 12: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) 

 

 

avatar
12
akshay12489 2015.10.23 07:44 #
 
Thanks, After removing the #property from EA,  problem solved :)
Back to topics list  

To add comments, please log in or register