Download MetaTrader 5
To add comments, please log in or register
Publish the program in the Market and sell it to millions of traders!
mar
1143
mar 2014.04.19 18:16 

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
13593
whroeder1 2014.04.19 18:40  
Market is closed, you can't get 6
mar
1143
mar 2014.04.19 19:09  

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

Thanks!

GreenMoney
379
GreenMoney 2014.04.19 19:16  

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
1143
mar 2014.04.19 19:37  

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 2014.04.19 22:47  
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 2014.04.20 00:02  
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
1143
mar 2014.04.20 13:26  
TimeLocal() is a very good idea! Thanks!
/
To add comments, please log in or register