In MQL the code is something like this :



// variables
double a,b,c,
sumy=0.0,
sumx=0.0,
sumxy=0.0,
sumx2=0.0,
h=0.0,l=0.0;
int x;

// calculate linear regression

for(int i=0; i<barsToCount; i++)
{
sumy+=Close[i];
sumxy+=Close[i]*i;
sumx+=i;
sumx2+=i*i;
}

c=sumx2*barsToCount-sumx*sumx;

if(c==0.0)
{
Alert("Error in linear regression!");
return;
}


// Line equation
b=(sumxy*barsToCount-sumx*sumy)/c;
a=(sumy-sumx*b)/barsToCount;

// Linear regression line in buffer
for(x=0;x<barsToCount;x++)
LR_line[x]=a+b*x;


but I'm not able to translate in Zorro code.
"barsToCount" is the number of bars displayed in the graph.

May be also R has similar calculation but it's too difficult for me.
Any help ?

Last edited by Andrea66; 02/15/17 11:08.