I tried with the following code without success, sorry I'm a newbie:
#define N 10 // Number of bars
function run()
{
var myClose[10] = { 1,3,9,4,12,6,5,10,15,5};
var LR_line[10];
// variables
var a,b,c,sumy=0.0,sumx=0.0,sumxy=0.0,sumx2=0.0,h=0.0,l=0.0;
int x,i;
int barsToCount=50;
for( i=0; i<N; i++)
{
sumy+=myClose[i];
sumxy+=myClose[i]*i;
sumx+=i;
sumx2+=i*i;
}
c=sumx2*N-sumx*sumx;
// Line equation
b=(sumxy*barsToCount-sumx*sumy)/c;
a=(sumy-sumx*b)/N;
for(x=0;x<N;x++)
{ LR_line[x]=a+b*x;
plot("NEW_linreg", LR_line[x],MAIN, RED);
}
}
The calculation should be correct; the issue is related how to plot the straight line in a time chart.
Last edited by Andrea66; 02/15/17 17:10.