Download MetaTrader 5
To add comments, please log in or register
Do you know that MQL5 can create custom graphical tools?
Tom
34
Tom 2016.03.05 17:32 

I want to code a linear regression of the 5 last Bars and i need the summation of the closes of the last 5 bars so i wrote this.

int i;
double sum_y = 0;
int sum_x = 0;

   for(i=1; i<=5; i++)
   {
   sum_y += Close[i];
   sum_x += i;
   }

So for example now sum_x should be always 5 but already after a few seconds there is 1000!! and with sum_y there is the same problem too.
whroeder1
13656
whroeder1 2016.03.05 19:42  
  1. Sum of 1+2+3+4+5 will never equal 5.
  2. Are those variables global? Not local?
Tom
34
Tom 2016.03.05 23:13  

I just want sum_y  = Close[1]+Close[2]+Close[3]+Close[4]+Close[5]

Ye you are right with sum_x. I dont need to calculate that for linear regression.

Variables are global.

whroeder1
13656
whroeder1 2016.03.06 01:40  
insub: Variables are global.
Then they are not being reset to zero.
Vasyl Nosal
18226
Vasyl Nosal 2016.03.06 10:01  
sum_x += 1;
Tom
34
Tom 2016.03.06 10:37  
WHRoeder:
Then they are not being reset to zero.
I changed it and it works now!! thx WHRoeder.
/
To add comments, please log in or register