problem when trying to draw some MA

 
hello

please anyone could explain me why this code dosen't work correctly
instead drawing 8 MA lines on chart it draws only first two i.e 5 and 8 periods moving averages

#property indicator_chart_window // Indicator is drawn in the main window
#property indicator_buffers 8 // Number of buffers
#property indicator_color1 Lime // Color of the 1st line
#property indicator_color2 Blue // Color of the 2nd line
#property indicator_color3 Red
#property indicator_color4 SeaGreen
#property indicator_color5 MediumVioletRed
#property indicator_color6 DeepSkyBlue
#property indicator_color7 OrangeRed
#property indicator_color8 Orange

extern int Aver5=5; // number of bars for calculation
extern int Aver8=8; // number of bars for calculation
extern int Aver21=21; // number of bars for calculation
extern int Aver55=55; // number of bars for calculation
extern int Aver89=89; // number of bars for calculation
extern int Aver144=144; // number of bars for calculation
extern int Aver233=233; // number of bars for calculation
extern int Aver377=377; // number of bars for calculation

double Buf_5[],Buf_8[],
Buf_21[],Buf_55[],
Buf_89[],Buf_144[],
Buf_233[],Buf_377[]; // Declaring indicator arrays
//--------------------------------------------------------------------
int init() // Special function init()
{
//--------------------------------------------------------------------
SetIndexBuffer(0,Buf_5); // Assigning an array to a buffer
SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(0,0);
//--------------------------------------------------------------------
SetIndexBuffer(1,Buf_8); // Assigning an array to a buffer
SetIndexStyle (1,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(1,0);
//--------------------------------------------------------------------
SetIndexBuffer(2,Buf_21); // Assigning an array to a buffer
SetIndexStyle (2,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(2,0);
//--------------------------------------------------------------------
SetIndexBuffer(3,Buf_55); // Assigning an array to a buffer
SetIndexStyle (3,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(3,0);
//--------------------------------------------------------------------
SetIndexBuffer(4,Buf_89); // Assigning an array to a buffer
SetIndexStyle (4,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(4,0);
//--------------------------------------------------------------------
SetIndexBuffer(5,Buf_144); // Assigning an array to a buffer
SetIndexStyle (5,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(5,0);
//--------------------------------------------------------------------
SetIndexBuffer(6,Buf_233); // Assigning an array to a buffer
SetIndexStyle (6,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(6,0);
//--------------------------------------------------------------------
SetIndexBuffer(7,Buf_377); // Assigning an array to a buffer
SetIndexStyle (7,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(7,0);
//--------------------------------------------------------------------
return;
}
//--------------------------------------------------------------------
int start()
{
ma(Aver5,Buf_5);
ma(Aver8,Buf_8);
ma(Aver21,Buf_21);
ma(Aver55,Buf_55);
ma(Aver89,Buf_89);
ma(Aver144,Buf_144);
ma(Aver233,Buf_233);
ma(Aver377,Buf_377);

return;
}
//--------------------------------------------------------------------

void ma(int& average,double& buffer[])
{
int n,i;
int Counted_bars;
double Sum;
Counted_bars=IndicatorCounted(); // Number of counted bars
i=Bars-Counted_bars-1; // Index of the first uncounted
while(i>=0) // Loop for uncounted bars
{
Sum=0; // Nulling at loop beginning
for(n=i;n<=i+average-1;n++) // Loop of summing values
{
Sum=Sum + Close[n]; // Accumulating maximal values sum
}
buffer[i]=Sum/average; // Value of buffer on i bar
i--; // Calculating index of the next bar
}
}

thanks
 

It works fine for me.


Cheers

Jellybean

 
same here, it works
Reason: