Let an EA operate just before the markets close

 

Dear all,

I  am trying to code an EA that is supposed to operate only during the following two particular moments of the day:

- within the first 5 minutes since the markets opened

- and in the last 5 minutes before the markets close.


I guess I figured out how to handle the first event (namely, checking whether Volume[0]>0 - would you confirm it, please?), but I cannot really get how to educate my EA about the closing time of the markets.

Is there a way to understand whether the market is about to close? Could you please advise me o suggest me any kind of workaround?


Thank you in advance!


Best,

anddm

 

Check function TimeCurrent() - it returns current server time. You can extract day using TimeDayOfWeek() function, extract hour and time using TimeHour() and TimeMinute() functions.

Another way is to read value in Time[] array. Time[0] is time of the current candle. Beware that if you are looking at H1 chart, Time[0] will contain time rounded to hour when candle opened.

 
Drazen Penic:

Check function TimeCurrent() - it returns current server time. You can extract day using TimeDayOfWeek() function, extract hour and time using TimeHour() and TimeMinute() functions.

Another way is to read value in Time[] array. Time[0] is time of the current candle. Beware that if you are looking at H1 chart, Time[0] will contain time rounded to hour when candle opened.

thank you for your reply!

Yes, I've checked the function TimeCurrent() but I stil don't get how to use it to deduce that the current time is 5 minutes before the market closing hour.

Plus, Time[0] contains the time of the opening candle, doesn't it? I am more interested in the closing time.

 

As I wrote, take a look at TimeDayOfWeek(), TimeHour() and TimeMinute() functions in the help.


  • Read time with TimeCurrent() 
  • TimeDayOfWeek() can tell you if it is for example Friday
  • TimeHour() will tell you which hour in a day it is
  • TimeMinute() will tell you which minute 
For example:

datetime time = TimeCurrent();
if(TimeDayOfWeek(time) == 5 && TimeHour(time) == 23 && TimeMinute(time) == 55)
  Print("Friday, 23:55");
Reason: