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

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
amrali, 2024.11.26 15:58
The fastest replacement for the built-in TimeToStruct() function,
I recommend using this function:
Even faster.
Forum on trading, automated trading systems and testing trading strategies
Features of mql5 language, subtleties and techniques of work
amrali, 2024.11.26 15:58
Here is the error of the 31st of January.
Here is the error of the 31st of January.
Which is correct :-)
You missed that day_of_year is zero-based index. So, doy=31 means actually 1 February.
algo_checker.mq5:
Even faster.
bravo, it seems faster!
I should do a larger test before applying these changes to my function.
Here is the improved script for benchmarks:
You missed that day_of_year is an index based on zero. So doy=31 actually means 1 February.
Thanks, realised this before your post, so deleted it.
Also, in real life (not in synthetic benchmarks), caching once a day can be useful to skip repeated calculations of the same year, month and day.
Forum on trading, automated trading systems and testing trading strategies
Features of mql5 language, subtleties and techniques of work
amrali, 2024.11.26 15:58
The fastest replacement for the built-in TimeToStruct() function,
I recommend using this function:
My previous version had a bug, so removed it.
Changed Months[] and got rid of the isleap calculation on any date. Now it's correct and faster.
My previous version had a bug, so removed it.
Changed Months[] and got rid of the isleap calculation on any date. Now it's correct and faster.
It's still there: doy - !(year & 3)
Only when doy >= 59.
Thanks Alain for your test. The replacement for built-in TimeToStruct() is only 4-5 times faster as I reported before.
However, the replacements for TimeYear(), TimeDayOfWeek() is at least 10-20 times faster than using MQL's TimeToStruct()
This code executes slow while using wrappers of built-in StructToTime.
Using the optimized functions really helps here.
Another thing: decompressing (TimeToStruct) is always faster than compressing (StructToTime). Built-in StructToTime is really slow than TimeToStruct().
If your code is creating a lot of 'datetime' variables from time components, you will find CreateDateTime() is much faster than MQL's StructToTime().
I faced the problem of slow StructToTime() while constructing datetime variables for Daylight switch times in TimeZoneInfo library. Replacing it for this custom CreateDateTime() made a nice improvement in speeds.