Download MetaTrader 5

DayOfWeek and TimeDayOfWeek problems..

To add comments, please log in or register
mar
1146
mar  

Hi coders,

whatever I try with these functions, I only get 5 as a result today. But Saturday should be 6. Is there any trick to get the the weekday?

whroeder1
14780
whroeder1  
Market is closed, you can't get 6
mar
1146
mar  

I understand. So it is always the last server-(date)time which is responsible for the DayOfWeek-result.

Thanks!

GreenMoney
379
GreenMoney  

DayOfWeek() returns "the current zero-based day of the week (0-Sunday,1,2,3,4,5,6) of the last known server time." The last known server time is probably 23:xx on Friday (yesterday). Since the market is closed today (and no new tick has arrived since Friday), DayOfWeek() is returning the result for Friday. This is the expected and correct behavior for DayOfWeek().

TimeDayOfWeek() returns "the zero-based day of week (0 means Sunday,1,2,3,4,5,6) of the specified date." The date you are passing to TimeDayOfWeek() is probably a Friday, which is why it is returning a 5.

mar
1146
mar  

DayOfWeek() makes sense to me. I used TimeDayOfWeek(TimeCurrent()) as an alternative. But TimeCurrent() is right now (Saturday) still Friday night's server-time. So I solved my issue by checking if DayOfWeek() == 5 and TimeHour(TimeCurrent()) == 23. That works fine and I can do some weekend-analysis.

Have a nice weekend!

qjol
3243
qjol  
TimeCurrent also Returns the last known server time, use TimeLocal if you must see Saturday on your screen
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  
qjol:
TimeCurrent also Returns the last known server time, use TimeLocal if you must see Saturday on your screen

Lately my broker have this tick and thus TimeCurrent() change to reflect the tick arrival. Last time TimeCurrent() would be 23:59:59 but now since the tick arrives, the time changed too, approx. 1 hour 1 tick arrives. No volume changes, just ticks.

That happens on weekend. qjol, have your broker behaves the same way?

mar
1146
mar  
TimeLocal() is a very good idea! Thanks!
To add comments, please log in or register