Download MetaTrader 5

OnInit() loops Indefinitely

To add comments, please log in or register
Do you need private account monitoring? The Signals will provide you one!
ahdad
8
ahdad 2016.10.31 14:57 

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;



peter.MT4Web
158
peter.MT4Web 2016.10.31 16:47  

Do read what the manual says about ChartSetSymbolPeriod.

peter.MT4Web
158
peter.MT4Web 2016.10.31 16:51  

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

To add comments, please log in or register