-
Day() should be nine (9) as last trading date, Friday, was Sep 9.
-
if( TimeDayOfWeek(TimeToStr(TimeCurrent() - 60 * 60 * 24 * i,TIME_DATE)) >= 1 && TimeDayOfWeek(TimeToStr(TimeCurrent() - 60 * 60 * 24 * i,TIME_DATE)) <= 5 ) { WorkDay++; Print("WorkDay = " + Day() + " = " + TimeToStr(TimeCurrent() - 60 * 60 * 24 * i,TIME_DATE) + " = " + TimeDayOfWeek(TimeToStr(TimeCurrent() - 60 * 60 * 24 * i,TIME_DATE)) + " = " + WorkDay );
Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling (or moving my eyes) back and forth trying to read it. Don't copy and paste code, write self documenting code.
-
Don't copy and paste code. Call your functions once and save the result in variables.
-
Why are you converting to a string. TimeDayOfWeek doesn't take a string as an parameter.
-
You have to count today also.
-
int WorkDay = 0; datetime now=TimeCurrent(); for (int i=Day(); i >= 1; i--) { datetime then=now - 86400*(i-1); int dow=TimeDayOfWeek(then); if( dow >= 1 && dow <= 5 ) { WorkDay++; Print("WorkDay = " + Day() + " = " + (string)then + " = " + dow + " = " + WorkDay ); } }
- wieb: It should be 72022.09.10 08:24:12.848 testscr USDSGD,Daily: WorkDay = 9 = 2022.09.09 23:58:02 = 5 = 7
2022.09.10 08:24:12.848 testscr USDSGD,Daily: WorkDay = 9 = 2022.09.08 23:58:02 = 4 = 6
2022.09.10 08:24:12.848 testscr USDSGD,Daily: WorkDay = 9 = 2022.09.07 23:58:02 = 3 = 5
2022.09.10 08:24:12.848 testscr USDSGD,Daily: WorkDay = 9 = 2022.09.06 23:58:02 = 2 = 4
2022.09.10 08:24:12.848 testscr USDSGD,Daily: WorkDay = 9 = 2022.09.05 23:58:02 = 1 = 3
2022.09.10 08:24:12.848 testscr USDSGD,Daily: WorkDay = 9 = 2022.09.02 23:58:02 = 5 = 2
2022.09.10 08:24:12.848 testscr USDSGD,Daily: WorkDay = 9 = 2022.09.01 23:58:02 = 4 = 1
1. Day() function return 9 as last date on MT4 Terminal was Friday, September 9 2022
2. I am not copy and paste code, that is myself code. Sorry if it looks like copy paste, but I am just beginner
3. Until September 9 2022 should be 7 working day, not 9 working day
4. I am trying to get how many working day on current month which is should be 7 working day (not 9)
5. Sorry if you have scroll to right corner. Edit the code by removing the Print command
int CurrentWorkDay() { int WorkDay = 0; for (int i=Day(); i >= 1; i--) { if( TimeDayOfWeek(TimeToStr(TimeCurrent() - 60 * 60 * 24 * i,TIME_DATE)) >= 1 && TimeDayOfWeek(TimeToStr(TimeCurrent() - 60 * 60 * 24 * i,TIME_DATE)) <= 5 ) { WorkDay++; } } return WorkDay; }
Please help how to fix the code
-
Day() should be nine (9) as last trading date, Friday, was Sep 9.
- 2022.09.10 08:24:12.848 testscr USDSGD,Daily: WorkDay = 9 = 2022.09.09 23:58:02 = 5 = 7
2022.09.10 08:24:12.848 testscr USDSGD,Daily: WorkDay = 9 = 2022.09.08 23:58:02 = 4 = 6
2022.09.10 08:24:12.848 testscr USDSGD,Daily: WorkDay = 9 = 2022.09.07 23:58:02 = 3 = 5
2022.09.10 08:24:12.848 testscr USDSGD,Daily: WorkDay = 9 = 2022.09.06 23:58:02 = 2 = 4
2022.09.10 08:24:12.848 testscr USDSGD,Daily: WorkDay = 9 = 2022.09.05 23:58:02 = 1 = 3
2022.09.10 08:24:12.848 testscr USDSGD,Daily: WorkDay = 9 = 2022.09.02 23:58:02 = 5 = 2
2022.09.10 08:24:12.848 testscr USDSGD,Daily: WorkDay = 9 = 2022.09.01 23:58:02 = 4 = 1
It works perfectly
Thank a lot @William Roeder for the help and kindness
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
How to get current month working day in MQL4?
Print result:
It should be 7 working day (not 9 as Print result above) and should be from 2022.09.01 (not from 2022.08.31)
How to fix it?
Please help