Download MetaTrader 5
To add comments, please log in or register
Do you need a trading robot? Orderit via Freelance service!
Farrokh Faghih
316
Farrokh Faghih 2014.05.16 14:47 

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
9831
Bambang Sugianto 2014.05.16 17:44  
yesterday=DayOfWeek()-1; 

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

And if yesterday is holiday like new year holiday? It can take place on middle of the week.
GreenMoney
379
GreenMoney 2014.05.16 19:18  
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 2014.05.16 20:47  
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 2014.05.16 22:20  
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 2014.05.17 08:15  
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