

anikulin: Does anybody have a clue what can cause this? Any help is appreciated. 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 

WHRoeder: 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).
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 

anikulin: 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 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
test.mq4 (0.75 KB)