You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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;
}