MA different to self calculated MA

 
double Array_MA10[];


int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ShiftedMABuffer,INDICATOR_DATA);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   for(int i=0;i<rates_total;i++)
     {
      double a=close[i];
      double b=close[i-1];
      double c=close[i-2];
      double d=close[i-3];
      double e=close[i-4];
      double f=close[i-5];
      double g=close[i-6];
      double h=close[i-7];
      double j=close[i-8];
      double k=close[i-9];
      Array_MA10[i]= (a+b+c+d+e+f+g+h+j+k)/10;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Hi, 

Found something strang, I'm just trying out MQL5. I thought I would start off with something simple, a moving average.

I don't see anything wrong with it but when compared to the MT5 provided "moving Average" indicator set to period of 10 they are different, see the image attached.

Does anyone have any idea why?

Moving Average - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
Moving Average - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
  • www.metatrader5.com
The Moving Average Technical Indicator shows the mean instrument price value for a certain period of time. When one calculates the moving average...
Files:
MA_issue.png  42 kb
 

Fix your program as follows and try it again.

SetIndexBuffer(0,Array_MA10,INDICATOR_DATA);
for(int i=9;i<rates_total;i++)



 
Nagisa Unada #:

Fix your program as follows and try it again.



And they say wizards don't exist, thanks that worked perfectly!!!


Thank you