OnInit() loops Indefinitely

 

I have written a simple code to calculate the average of the past ten days, weeks, and months and placed it in OnInit(), however, when run, it loops indefinitely. Can someone please tell me what I did wrong...

 

Here's the code:

 

int OnInit()

  {

    double Avg=0.0;

    printf("I'm going to find the average for the past day, week and month");

   

   // day

   ChartSetSymbolPeriod(0,NULL,60*24);

   Avg=FindAverage(10);

   printf("Average for ten days = %f",Avg);

   

   // Wait for less than a second

   for(int z=0; z<100000000; z++);

   

   // week

   ChartSetSymbolPeriod(0,NULL,60*24*7);

   Avg=FindAverage(10);

   printf("Average for ten weeks = %f",Avg);   

   

   // Wait for less than a second

   for(int z=0; z<100000000; z++);   

      

   // month

   ChartSetSymbolPeriod(0,NULL,60*24*30);

   Avg=FindAverage(10);

   printf("Average for ten months = %f",Avg);

      

   return(INIT_SUCCEEDED);

  }


 

double FindAverage(int min)

{

   double Tot=0; 

   

   for (int a=0; a<min; a++)

      Tot=Tot+( ( (High[a]+Low[a]) /2) );

      

   Tot=Tot/min;

   

   return Tot;



 

Do read what the manual says about ChartSetSymbolPeriod.

 

And then check if you can do better with iHigh ( ) and iLow ( ).