# sma on MT5 random result

61

Hi, I'm developing an indicator based on sma of a limited set of bars.

Trying different way to calculate sma I obtain different result for the same bar.

I use 4 different way to calculate the sma:

1) using SimpleMAOnBuffer on all available bars (rates_total)

2) using SimpleMA on a limited set of bar (Nbar)

3) using iMA handle over all bars available (rates_total)

4) using SimpleMAOnBuffer on a limited set of bar (Nbar)

Here the result for EURJPY,M1 on a particular bar (2016.11.15 04:31) of the three calculated SMA  with period 420 :

SMA1=116.3047904761912
SMA2=116.3047904761905
SMA3=116.3047904761905
SMA4=116.3047904761901

As you can see there are differences.

My question is why?

Wouldn't be sma always the same indipendently from number of bar and the way you use to calculate it?

Which is the most reliable way to calculate a sma?

I attach the code I wrote.

Files:
Moderator
8419

Of course not.

MA is calculated over a number of bars, not one bar, so of course it matters how many bars you pull.

So not ontly the Period (timeframe) but also the MA_Period.

61

Marco vd Heijden:

Of course not.

MA is calculated over a number of bars, not one bar, so of course it matters how many bars you pull.

So not ontly the Period (timeframe) but also the MA_Period.

The ma_period is the same in all the different sma calculation. So why it's not equal?