Features of the mql5 language, subtleties and tricks - page 250
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Parity.
static wins for simple types and loses for structures.
static wins for simple types and loses for structures.
This is a very strange result. IMHO, they have something wrong. Below is the code that g++ generates. Either your test is incorrect or the developers have messed up in the compiler. Well, Test1 cannot consume more CPU time than Test2)
And yes, you can easily kill all this if you optimise the code incorrectly beforehand. Pay attention to Swap3. It seems to be an obvious optimisation, but at the output, due to the fact that we work not with a value, but with a reference, we have the most unbelievable overhead
Either your test is incorrect, or the developers have messed up the compiler. Well, Test1 cannot consume more CPU time than Test2)
That's a very strange result. IMHO, but something is wrong with them. Below is the code that g++ generates.
MQL is not C++ ; except for its appearance... It is not correct to compare it with gcc.
It is leaning towards C# in general .
PS/ well, in the example: static loses for structures, because there (figuratively) is also a destructor. On all calls except the first one, what was in static must be destroyed and/or the copy method must be called.
PPS/ (for those who wish) you can experiment with static T& or static T* to avoid unnecessary copies and destructors.
MQL is not C++ ; it is only externally similar...it is not correct to compare it with gcc
it is leaning towards C# in general .
PS/ well, in the example: static loses for structures, because there (figuratively) is also a destructor. On all calls except the first one, what was in static must be destroyed and/or the copy method must be called.
PPS/ (for those who wish) you can experiment with static T& or static T* to avoid unnecessary copies and destructors.
I don't agree with this one bit.
I don't agree once.
About the principle: the authors of the language pedal "managed code". And this is Sharp, from which, however, they had earlier renounced :-)
Again, it is not C++ and not even close to it. Neither you nor I can compare the final codes there and there and justify why it is so and why it is true/not true somewhere. That is why comparisons are incorrect. You don't have an asm output from MQL, do you? There is nothing to compare it with.
If this does happen during optimisation, it is a reason to correct it.
There are a lot of such corrections. Ilyas does not eat his bread for nothing. I am sure that work is going on.
From recent questions to optimisation, what I found.
time of bar opening for a given time and TF, when it is known for sure 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's some magic going on there that resulted from going from simple to complex.
Alternative.
Alternative.
Well, not quite an alternative, of course, because this is a completely different problem. I calculated the year and month from the date, but here they are already input.
My implementation 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 since I don't have double types
I am not against numerical methods of solving problems (what you call algorithmic optimisation), I often use them myself, but in this case you are applying algorithmic optimisation to a static system, and it is normal.
I am always against optimisation for TS, which are always dynamic rather than static systems, because the market itself is dynamic and variable. That is why such optimisation is more correctly called fitting of parameters to the historical period of time. This is self-deception and a waste of time. The set of parameters found with the help of such "optimisation" will behave quite differently in the future.
Try to solve the problem of getting the day of the month from the input datetime using such a numerical method . I doubt you will be able to.
I am always against optimisation for TS, which are always dynamic rather than static systems, because the market itself is dynamic and variable. That is why such optimisation is more correctly called fitting of parameters to the historical period of time. This is self-deception and a waste of time. The set of parameters found with the help of such "optimisation" will behave quite differently in the future.