Buffers are series arrays; zero is the latest value. so you get (MA[2]+MA[1]+MA[0])/3
Your array isn't. So you get (array[-2] + array[-1] + array[0])/3 first 2 are garbage.
Buffers are series arrays; zero is the latest value. so you get (MA[2]+MA[1]+MA[0])/3
Your array isn't. So you get (array[-2] + array[-1] + array[0])/3 first 2 are garbage.
ArraySetAsSeries - MQL4 Documentation
But the problem is that iMAOnArray with a series array returns a different value from (MA[2]+MA[1]+MA[0])/3, but iMAOnArray with a static array returns correct one (the one that can be simply calculated as (MA[2]+MA[1]+MA[0])/3).
I also noticed that the result that iMAOnArray returns depends on the order or elements, however it shouldn't as Simple MA is used.
When I tried to place 3 same values in different ways I got 3 different results (but none of them was correct):
BufferArrayMA 3 1.0830667461140955 BufferArrayMA 2 1.0830667464531798 BufferArrayMA 1 1.0830667368231886
I also tested iMAOnArrayMQL4 function that is suggested as a replacement for iMAOnArray in MQL5 (https://www.mql5.com/en/articles/81) and its calculation on series array gave the same results as iMAOnArray for static array (1.0830666666666682, correct value).
Any ideas why iMAOnArray works in a different way and why the order of elements influences the final result?
Hi,
i want to get iMAOnArray() from another smaller MA, it seems simple but i dont understand where is my mistake, the iMAOnArray (which called BiggerMA here) get me wrong values in compare to what we have on chart
can someone help me.
//+------------------------------------------------------------------+ double MAonArry(string symbol,int timeframe, int candle) { double SmallerMABuffer[]; ArrayResize(SmallerMABuffer,(BiggerMA_period+2)); for(int i=BiggerMA_period+1 ; i>=0 ; i--) { SmallerMABuffer[i]=iMA(symbol,timeframe,SmallerMA_period,SmallerMA_Shift,SmallerMA_method,SmallerApplied_Price,i); } return iMAOnArray(firstMABuffer,0,BiggerMA_period,BiggerMA_Shift,BiggerMA_method,candle); } //+------------------------------------------------------------------+
- Set your array as series (before filling) so the function knows how to process it.
- For SMA(n) or WMA(n) you need n values. Exponential requires 3.45×(Length+1) bars to converge to 1/10 percent. (EMA Period 5 requires 21 initial bars.)
Moving average - Wikipedia
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys,
Investigating the logic of one indicator I noticed that iMAOnArray() function returns different results for the same values depending on whether they are represented as indicator buffer or static array. I created a simple test that calculates Simple MA of 3 values with the period of 3.
I was expected that both results would be absolutely identical, but they were not:
As you can see the difference is quite small (starting from the seventh digit), but still it's quite strange.
Does anybody have a clue what can cause this? Any help is appreciated.
The source code of the test is attached to this message.
Thanks, Anton