Problem with Summation of the 5 last Closes

Back to topics list To post a new topic, please log in or register
avatar
12
insub 2016.03.05 18: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.
avatar
12985
WHRoeder 2016.03.05 20:42 #
 
  1. Sum of 1+2+3+4+5 will never equal 5.
  2. Are those variables global? Not local?
avatar
12
insub 2016.03.06 00: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.

avatar
12985
WHRoeder 2016.03.06 02:40 #
 
insub: Variables are global.
Then they are not being reset to zero.
avatar
872
eevviill 2016.03.06 11:01 #
 
sum_x += 1;
avatar
12
insub 2016.03.06 11:37 #
 
WHRoeder:
Then they are not being reset to zero.
I changed it and it works now!! thx WHRoeder.
Back to topics list  

To add comments, please log in or register