Download MetaTrader 5

How I can Have Last working day number?

To add comments, please log in or register
Farrokh Faghih
316
Farrokh Faghih  

Hi

Suppose that today is MONDAY and I want to number of yesterday. I know I can use DayOfWeek() but if it's MONDAY I cannot do this | DayOfWeek()-1 |, because it returns 0 but I meant 5. And also if yesterday the market was closed what then?! I want to have last working day number.

Could anyone help on this?

Bambang Sugianto
10522
Bambang Sugianto  
yesterday=DayOfWeek()-1; 

if (yesterday==0) yesterday=5;
Farrokh Faghih
316
Farrokh Faghih  
WDholic:

And if yesterday is holiday like new year holiday? It can take place on middle of the week.
GreenMoney
379
GreenMoney  
farrokhfa:

Hi

Suppose that today is MONDAY and I want to number of yesterday. I know I can use DayOfWeek() but if it's MONDAY I cannot do this | DayOfWeek()-1 |, because it returns 0 but I meant 5. And also if yesterday the market was closed what then?! I want to have last working day number.

Could anyone help on this?

Try:

int previous_trading_day = TimeDayOfWeek(iTime(_Symbol, PERIOD_D1, 1));

Remember to trap and properly deal with a 4066 runtime error. The above works well with broker servers that don't have weekend bars.

Farrokh Faghih
316
Farrokh Faghih  
Thirteen:

Try:

Remember to trap and properly deal with a 4066 runtime error. The above works well with broker servers that don't have weekend bars.


So helping. Thank you very much.
Halley
198
Halley  
Thirteen:

Try:

Remember to trap and properly deal with a 4066 runtime error. The above works well with broker servers that don't have weekend bars.


I never found a way how to properly deal with the 4066 error. Whatever I did in the code, the error appeared once every time, and never twice, regardless if the history was still loading or the chart has already been up to date.

Could you show us how to properly deal with the 4066 error?

Farrokh Faghih
316
Farrokh Faghih  
DeepThought:


I never found a way how to properly deal with the 4066 error. Whatever I did in the code, the error appeared once every time, and never twice, regardless if the history was still loading or the chart has already been up to date.

Could you show us how to properly deal with the 4066 error?


It seems we should just wait for around 10seconds to send another request. No other solution found.


see also: https://www.mql5.com/en/forum/127460

To add comments, please log in or register