How I can Have Last working day number?

 

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?

 
yesterday=DayOfWeek()-1; 

if (yesterday==0) yesterday=5;
 
WDholic:

And if yesterday is holiday like new year holiday? It can take place on middle of the week.
 
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.

 
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.
 
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?

 
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

Reason: