Features of the mql5 language, subtleties and tricks - page 335
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
Sometimes I can open or close a trade.
I believe that 5 out of 6 of the results below are correct.
I believe that 5 out of 6 of the results below are correct.
Correction:
Result:
Correction:
Yes, it matches now.
I took a real-world task where, at the end of a backtest, I needed to calculate the duration of all positions. I stored the open and close times of the positions in an array. Then I ran the following script on it.
In tasks like this, you only need to go through all the positions once, so I wasn’t able to gain any performance benefit from caching. I suppose the only thing that might help here is table data hard-coded into the programme before compilation. But it’s probably not worth fighting for half a millisecond. Thanks for the research!
P.S. Thanks to you, I’ve spotted a mistake in my own code.
Thanks again.I took a real-world task where, at the end of a backtest, I needed to calculate the duration of all positions. I stored the open and close times of the positions in an array. Then I ran the following script on it.
The attached file "Time.bin" contains 324,865 positions, of which 324,425 (99.87%) have a short duration < 24 hours (does not span weekends or holidays).
For an objective comparison, increase the ratio of positions with a longer duration, and you will see a real increase in performance thanks to my optimizations.
The attached file ‘Time.bin’ contains 324,865 entries, of which 324,425 (99.87 per cent) are of short duration (< 24 hours) (excluding weekends and public holidays).
For an objective comparison, increase the proportion of entries with longer durations, and you will see a real improvement in efficiency thanks to my optimisations.
The result.
The larger this operand, the faster the cached version is.
P.S. Thanks to you, I’ve spotted a mistake in my own code.
Thanks again.Test:
Good day,
Unfortunately, while running a date/time simulation, I found that none of the faster replacements for StructToTime() and TimeToStruct() posted before here and here worked correctly for years beyond 2100.
I had to revise the implementations to fix the issue so they now work correctly for all years.
In addition, significant performance improvements were achieved (thanks to some micro-optimizations, such as the use of unsigned division and modulus).
MQL's StructToTime() alternative:
MQL's TimeToStruct() replacement:
Benchmarks:
did not work properly for the years after 2100
I’m sorry, but it’s 2026 now, and by 2100 there will most likely be no trace of the MT5 terminal left on the internet.
What’s the point of all this?
What’s the point of all this?
High-performance time functions valid for the full MQL5 datetime range (1/1/1970 to 31/12/3000):
(Derived from the Neri–Schneider calendar conversion algorithm: here)
The attached script file contains the source codes + complete validations.