How do you convert a UTC timestamp to Unix Time (seconds since the epoch)? Of course the right answer is “you use a standard library function.” But what if you don’t have one available? Or what if you’re the person implementing that library? Converting the time portion is trivial. Unix Time pretends that leap seconds do not exist and makes...
I did. Checked it. Surprisingly, my variant, whose logic was describedhere, turned out to be the fastest. The ported function from C++ library turned out to be the slowest.
but it is more reasonable to use this variant to use the saved previous values in case the requested day is the same. Therefore, the function will work even faster.
char GetMonth(datetime time) { // return 1...12staticint last_days = 0;
staticchar last_result = 0;
int days = int(time/(24*60*60));
if (last_days!=days) {
last_days = days;
int d1 = (days+306+365)%1461;
char m = 3;
if (d1==1460) {
last_result = 2;
return2;
}
int d = d1-(d1/365)*365+1;
if (d!=31) if (d==276) {
last_result = 12;
return12;
} else m = char (d/30.68)+3;
if (m>12) m-=12;
last_result = m;
}
return last_result;
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Forum on trading, automated trading systems and testing trading strategies
Features of mql5 language, subtleties and techniques of work
Vladislav Boyko, 2024.04.18 02:29
Maximum optimisation:
No optimisation:
The performance of imported functions cannot depend on the selected compiler settings.
Forum on trading, automated trading systems and testing trading strategies
Features of mql5 language, subtleties and techniques of work
amrali, 2024.04.18 01:50 PM
Put this summand into the array.
lookup tables are always faster than switch (linear search).
Alternative.
The encoding of year and month components into a timestamp was the main challenge.
Other components of MqlDateTime struct are trivial to claculate. (multiply by seconds)
Forum on trading, automated trading systems and testing trading strategies
Peculiarities of mql5 language, subtleties and techniques of work
fxsaber, 2024.04.16 00:35
Alternative.
A slightly improved mechanism for applying optimisation produced this. I think this is the fastest calculation.
A slightly improved mechanism for applying optimisation produced this. I think this is the fastest calculation.
Very fast.
To the piggy bank of algorithms on the topic.
Check out this implementation.
I did. Checked it.
Surprisingly, my variant, whose logic was describedhere, turned out to be the fastest. The ported function from C++ library turned out to be the slowest.
test result:
but it is more reasonable to use this variant to use the saved previous values in case the requested day is the same. Therefore, the function will work even faster.
Forum on trading, automated trading systems and testing trading strategies
Features of mql5 language, subtleties and techniques of work
Nikolai Semko, 2024.04.19 09:23
Forum on trading, automated trading systems and testing trading strategies
Peculiarities of mql5 language, subtleties and techniques of work
fxsaber, 2024.04.16 12:46
x64:
To the piggy bank of algorithms on the topic.
I checked days_from_civil() and epoch_days_fast() from the links you sent.
These are not the fastest (probably the MQL5 compiler).