DayOfWeek and TimeDayOfWeek problems..

 

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?

 
Market is closed, you can't get 6
 

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

Thanks!

 

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.

 

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!

 
TimeCurrent also Returns the last known server time, use TimeLocal if you must see Saturday on your screen
 
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?

 
TimeLocal() is a very good idea! Thanks!