Download MetaTrader 5

calculate the average Closing 10,000 candles

To add comments, please log in or register
jeef_1985
63
jeef_1985  

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 ... 

Fernando Carreiro
2201
Fernando Carreiro  

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 ) );
}  
jeef_1985
63
jeef_1985  

    

     Yes ...

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

                       thank you it s work .....

Fernando Carreiro
2201
Fernando Carreiro  
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 ) )
jeef_1985
63
jeef_1985  
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
To add comments, please log in or register