Features of the mql5 language, subtleties and tricks - page 243

 
Nikolai Semko #:

maybe then:

uchar WhatWeekDay(datetime t) {
   return uchar(t/(24*60*60)+4 )%7;
}

Nope, doesn't work. (((

 
Mikola_2 #:

Nope, it's not working. (((

It works very accurately. I use this. You can convert the value to ENUM_DAY_OF_WEEK

 
Alexey Viktorov #:

It works very accurately. I use this. You can convert the value to ENUM_DAY_OF_WEEK

There is no such thing as "very accurate". It's either always accurate, or it's not always accurate. It's like a second fresh herring. What period did you test it on? I couldn't do it.
 
Mikola_2 #:

Nope, it's not working. (((

The brackets are missing, the remainder on division by 7 is taken from the number converted to uchar type.

 
Mikola_2 #:
There's no such thing as "very precise." Either it's always accurate or it's not. It's like a second fresh herring. What period did you test it on? I couldn't do it.

What do you mean, what period? The function just returns the day of the week. What does that have to do with the period? Put any time and you get the day of the week.

Put your date of birth and you get the day of the week of your birth.

Or here's the day of the week by candle time


 
Aliaksandr Hryshyn #:

The brackets are missing, the remainder on when dividing by 7 is taken from a number cast to uchar type.

It's all there. I just replaced 24*60*60 to my liking.

uchar WhatWeekDay(datetime t)
 {
  return uchar(t/(PeriodSeconds(PERIOD_D1))+4)%7;
 }

Results above...

Note how long I've been using this formula since


 
Alexey Viktorov #:

Everything in there is sufficient. I just replaced the 24*60*60 to my liking.

results above...

Notice how long I've been using this formula.


There is no error in the screen! Take a good look. I pointed out the error.

 
Aliaksandr Hryshyn #:

The brackets are missing, the remainder on when dividing by 7 is taken from a number cast to uchar type.

Oh, right! Now it seems to be true.
 
Aliaksandr Hryshyn #:

There's no error on the screen! Take a good look. I pointed out the error.

Well, I showed the full code of the function too. Again:

uchar WhatWeekDay(datetime t)
 {
  return uchar(t/(PeriodSeconds(PERIOD_D1))+4)%7;
 }

I agree with you, though. Perhaps Nikolai wrote from memory and made an inaccuracy. But it is not quite right to say that it does not work.

 
Alexey Viktorov #:

What do you mean "on what period"? The function just returns the day of the week. What does period have to do with it? Put any time and you get the day of the week.

Put the date of your birth and get the day of the week of your birth.

Or here's the day of the week by candle time


Period != timeframe. The above function returns the correct day of the week for some date range, and then it returns the wrong one. The brackets are really lost in the above function - you should be more careful... ))))))))