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

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Forum on trading, automated trading systems and testing trading strategies
Features of mql5 language, subtleties and techniques of work
Nikolai Semko, 2024.04.16 05:02
My realisation of such a task without numerical methods, but only logically, would be, for example, the following:
I don't think the difference in performance would be significant, especially I don't have double types
Thank you, that's quicker.
Yeah, I checked, too.
the result:
function calculation time 1-3 ns. Light during this time passes 30 cm - 1 metre :)))Yeah, I checked, too.
You can do it without uint.
return datetime((Year-1970)*365+(Year-1968)/4 - ((Year%4==0 && Month<3)?1:0) + dm[Month])*24*60*60;
Oh, right. I didn't realise that DAY could be put outside the brackets.
I don't understand why this is here.
ignore it.
ignore it.
You shouldn't. Corrected.
Forum on trading, automated trading systems and testing trading strategies
Peculiarities of mql5 language, subtleties and techniques of work
Nikolai Semko, 2024.04.16 05:02
Try to solve the problem of getting the day of the month from the input time datetime usingthis numerical method . I doubt that you will be able to.
Perhaps, overminded, but to find the day of the month you need to know the year and month.
Let's start with the year.
We've got the function we're looking for.
Or the same function in integer form.
Now the month.
For simplicity, I decided to search for the month in year zero - 1970.
We could not achieve a coincidence (zero in OnTester).
So I divided it into two cases: 1-2 months and 4-12 months.
We got the desired function.
Or the same in integer form.
Day of the month.
Finally, let's try to apply the obtained results. Not forgetting leap year features.
It seems to work.
Probably overthinking it
Yeah, I checked, too.
the result:
function calculation time 1-3 ns. Light during this time passes 30 cm - 1 metre :)))Thanks, it is really fast!
Thanks, it is really fast!
The function is a smart subset of the algorithm of StructToTime in mql5, or mktime in C https://github.com/lattera/glibc/blob/master/time/mktime.c.
Nicely formatted: