Download MetaTrader 5
To add comments, please log in or register
Use MQL5 Cloud Network. It is secure!
jeef_1985
61
jeef_1985 2016.04.17 12:06 

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
1451
Fernando Carreiro 2016.04.17 14:23  

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
61
jeef_1985 2016.04.17 17:20  

    

     Yes ...

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

                       thank you it s work .....

Fernando Carreiro
1451
Fernando Carreiro 2016.04.17 18:09  
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
61
jeef_1985 2016.04.17 22:17  
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