Features of the mql5 language, subtleties and tricks - page 235
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
If it stopped working, it's good to know if it's the right thing to do.
If you make pointers instead of objects, the old version will work too.
Great point and thanks for the tip!
Yes, indeed, the situation is perfectly solved with a pointer:
Fans of fast algorithms. Those who fight for nanoseconds :)
Task: Find the time of bar opening according to the given time and TF, when it is known that the bar exists at this time. For example, by the time of opening and closing positions.
Most programmers will use a combination of iTime and iBarShift. This will be the slowest implementation, especially such an implementation requires an up-to-date history of uploaded data or combed arrays. Moreover, this approach may generate errors if the required history is missing.
More advanced programmers will solve this problem through MqlDateTime structure and TimeToStruct() function. This is not a bad solution and fast enough.
But there is a third solution, which is more productive than the previous solution several times:
The main difficulty in this algorithm is calculating the time of the beginning of the month (highlighted in green) Please don't try to understand the workings of the algorithm. There is magic going on there, which is the result of going from simple to complex. The reverse path from complex to simple will be much harder to go through.
The performance gain is also provided by the algorithm of getting seconds in a bar from the TF instead of the standard PeriodSeconds() function - highlighted in yellow colour.
I attach a test script that calculates and compares the performance of all three methods:
The checksum with iBarShift will not match , because iBarShift works with real bars. The checksum will coincide only on MN1 and W1 timeframes, because there are no holes in the history of such bars.
Performance will be higher if you use a small time step in the loop (less than one day) when the algorithm starts working to save previous calculations:
Excessive values for the algorithm via iBarShift (highlighted in blue) are caused by the current lack of necessary history or TFs calculated by the array, which initiates their uploading.
After uploading the result will be as follows:
Fans of fast algorithms. Those who fight for nanoseconds :)
...😮😲😳🥴🤪
...
ah...
mmm....
oooh....
gkghm... I didn't think my simple question would come out like this.
Just like that. Oh.
😮😲😳🥴🤪
...
ah...
mmm.
ohhhh....
ahem. I didn't think my simple question would come out like this.
Oh.
Yes, Artem, you fooled me for a while.
It was a sporting interest.
I hope it will be useful to someone, including me. :))
Yes, Artem, you have cheated me for a while.
I worked on sporting interest.
I hope it will be useful to someone, and me among others. :))
Of course it will. Great. Thank you again!
S.F. This amused me: "counts correctly only till 28.02.2100 !!!!".
What do we do after that?
Of course it'll come in handy. Great. Thank you again!
S.F. This amused me: "counts correctly only till 28.02.2100 !!!!".
What do we do after that?
haha.
I doubt that this algorithm will be in demand for 75 years. Quantum computers will probably rule the world already, with completely different programming.
To be honest, it was lazy to take into account the Gregorian calendar. 2000 was high-stakes, 2100 is not anymore.
haha.
I doubt that this algorithm will be in demand for 75 years. Quantum computers will probably rule the world already, with completely different programming.
to be honest, it was lazy to take into account the Gregorian calendar completely. 2000 was high-stakes, 2100 is not anymore.
For MN you can use a pre-calculated array, there's almost nothing in there
Ln2(12 months * hundred years)...11 if`'s and comparisons in binary search, but without other calculations.
You can use a pre-calculated array for MN, there is hardly any data there.
Ln2(12 months * hundred years)...11 if`'s and comparisons in binary search, but without other calculations.
You can use a pre-calculated array for MN, there is hardly any data there.
Ln2(12 months * hundred years)...11 if`'s and comparisons in binary search, but without other calculations.
ah, I read it wrong at first.
No, you are wrong. Performance increase will not work. You will still be stuck in calculations. And access to array elements slows down the algorithm very much.