calculate the average Closing 10,000 candles

 

I want to calculate the average Closing 10,000 candles is my thank you trying to fix me I'm a beginner can

 

 for(i=1; i<10000; i++)

   {

   sum +=iClose(Symbol(),NULL,i) ; Num++ ;

   Average = NormalizeDouble(sum/Num,5) ;

   Print(" Average  ----->  " , Average  ) ;

   }

 

thanks ... 

 

You can also use the "iMA()" function to get an average, but make sure to check if your history has 10000 bars by checking the "Bars" variable, or the "iBars()" function or the more modern "Bars()" function!

int
   BarCount = 10000,
   BarShift = 1;

double
   BarAverage = 0;

if( Bars >= ( BarCount + BarShift ) )
{
   BarAverage = iMA( NULL, 0, BarCount, 0, MODE_SMA, PRICE_CLOSE, BarShift );
   Print( "Average for ", BarCount, " is ", DoubleToString( BarAverage, _Digits ) );
}  
 

    

     Yes ...

             if (Bars < BarCount) { Print("Not enough bars"); 

                       thank you it s work .....

 
jeef_1985:

    

     Yes ...

             if (Bars < BarCount) { Print("Not enough bars"); 

                       thank you it s work .....

 

Actually, there was a bug in my initial post. I have revised it to be:

if( Bars >= ( BarCount + BarShift ) )
 
I have try with a lower number of bars to test
normally the average is the sum of two terminals it works now thank you
Reason: