![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
He means that the time it takes to execute is pre-determined or almost constant. Usually this is achieved by doing the calculations incrementally, on each bar for example, so that the calculation are spread out over many bars instead of having to do the whole calculation all at once.
This is one of the reasons why the exponential moving average can be calculated so much faster than the simple moving average for increasingly larger periods. An exponential moving average always takes the same amount of time to calculate irrespective of the period, while a simple moving average (which is the case here) gets slower, and slower the longer its period.
EDIT: That is the reason why in his calculations he is keeping track of a ring buffer, so that the sum can be calculated incrementally on each bar.
He means that the time it takes to execute is pre-determined or almost constant. Usually this is achieved by doing the calculations incrementally, on each bar for example, so that the calculation are spread out over many bars instead of having to do the whole calculation all at once.
This is one of the reasons why the exponential moving average can be calculated so much faster than the simple moving average for increasingly larger periods. An exponential moving average always takes the same amount of time to calculate irrespective of the period, while a simple moving average (which is the case here) gets slower, and slower the longer its period.
EDIT: That is the reason why in his calculations he is keeping track of a ring buffer, so that the sum can be calculated incrementally on each bar.
Thanks for the explanation.
From my previous roles/experiences, I am always conscious of performance when writing MQL code (which is still a relatively new area for me). So far I am yet to find any MQL computation which takes more than a couple of milli-secs and often it is far less.
Given it is predominantly in-memory and relatively simple in architecture, it has that advantage of not being heavily encumbered.
Mine is O(n), his is O(1)
Yes, I prefer this simpler approach also
Yes, I prefer this simpler approach also
Yes exactly - one can start simple and test the performance - if it needs something better one can implement it.
It is just about getting the balance right between effort and benefit
He means that the time it takes to execute is pre-determined or almost constant. Usually this is achieved by doing the calculations incrementally, on each bar for example, so that the calculation are spread out over many bars instead of having to do the whole calculation all at once.
This is one of the reasons why the exponential moving average can be calculated so much faster than the simple moving average for increasingly larger periods. An exponential moving average always takes the same amount of time to calculate irrespective of the period, while a simple moving average (which is the case here) gets slower, and slower the longer its period.
EDIT: That is the reason why in his calculations he is keeping track of a ring buffer, so that the sum can be calculated incrementally on each bar.
I hope it compiles and I havent forgotten anything. I had to extract it from my library.
As far as I understand this, I would call the function once, and get a result, which is the EMA value. Then, on subsequent calls, I would feed in the result of the last call as init_val and use a period of 1 to calculate the next value. Is that right?
It does compile (in MQL5) - I suggest pasting it into a script and compiling it first before posting.
In fact better if you post a working script - makes it easier for others who wish to participate
It does compile (in MQL5)
I was thinking about this - if you have a variable to sum up the values, and another to count the values, you have the simplest/fastest (and deterministic) way to compute the mean.
Only 3 operations: 1. add the new value to the sum 2. increment the count 3. mean = new sum divided by the new count.
Of course this does not retain a complete history of all values, but that is a simple matter of adding each new entry to an array, should one need it for deeper analysis.
Alternatively if one chooses to keep an incremental history array, just use ArraySize() instead of having a count variable, all of this would occur in microsecs anyway
I was thinking about this - if you have a variable to sum up the values, and another to count the values, you have the simplest/fastest (and deterministic) way to compute the mean.
Only 3 operations: 1. add the new value to the sum 2. increment the count 3. mean = new sum divided by the new count.
Of course this does not retain a complete history of all values, but that is a simple matter of adding each new entry to an array, should one need it for deeper analysis.
Alternatively if one chooses to keep an incremental history array, just use ArraySize() instead of having a count variable, all of this would occur in microsecs anyway