![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
C programmers.
The example is very simple in this case. Calculating the totallifetime of all closed positions is a much more difficult task for fast performance.
The example is very simple in this case. Calculating the totallifetime of all closed positions is a much more difficult task for quick performance.
I explained the reason to you earlier, but you didn't take it into account.
I explained the reason to you earlier but you didn't take it into account.
Apparently I need to search the forum for your explanation.
Apparently I need to search the forum for your explanation.
Last time you had a similar issue, where the passed parameter was not cached, but passed straight into the code.
And after you cached it, the speed increased. Always allocate memory for a variable and only use it later.
It's the same here, you declare a variable, memory is already allocated and further work with the variable will be faster since there are no memory allocation costs.
This also applies to getting values from mql function.
Even the developers recommended here on the forum, first get a value from a function into a variable and then use that variable in an if() condition
Calculating the cumulativelifetime of all closed positions is a much harder task for fast performance.
Forum on trading, automated trading systems and strategy testing
Libraries: MT4Orders
fxsaber, 2020.08.29 04:17
There may be a faster option. But a step to the left in the condition of what needs to be calculated, and the logic may have to change considerably. Not easy, in general.
There may be a faster option. But one step to the left in the condition of what needs to be counted, and the logic may have to change considerably. Not easy, in general.
It's not the condition, it's the writing of the code.
Although you can replace condition with switch, it will work faster than if else.
Try this code, will it get faster or not? If not, try replacing if else with switch.
I hope you understand the point now, that all variable declarations should be put out of the loop, and not re-execute them 100500 times.
Also, for each returned value, allocate memory in the form of a variable.
This is another variant of the code, so that we don't have to yank History for the second condition.
You can also think which condition will be fulfilled more often, put it first in the loop and continue iteration.
This is another variant of the code, so as not to pull History for the second condition.
From here on, it's up to you.
In MT4 it works the same way, just the cache creation is hidden. At every OnTick/OnStart of MT4 the terminal automatically and sparingly creates a snapshot of the market environment for each EA.
Therefore, you cannot assess the true latency of data preparation from the MQL4 code. Fortunately, in MT4 the data is small and simple.
closed positions.
You can take it from here.
If you do it yourself, then you do it yourself.
But it's strange why the result is so strange, that's a question for Renate.
My suspicion is the hashmap check DealsIn.TryGetValue
Look under the profiler.