calculate the average Closing 10,000 candles

Back to topics list To post a new topic, please log in or register
avatar
17
jeef_1985 2016.04.17 14: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 ... 

 

 

avatar
1200
FMIC 2016.04.17 16: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 ) );
}  


avatar
17
jeef_1985 2016.04.17 19:20 #
 

    

     Yes ...

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

                       thank you it s work .....

 

avatar
1200
FMIC 2016.04.17 20: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 ) )
avatar
17
jeef_1985 2016.04.18 00: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
Back to topics list  

To add comments, please log in or register