Hi all,
I've been really struggling with this, any ideas greatly appreciated.
The code below displays a linear regression line and scrolls it with the window
however, I haven't been able to get it to work when used as exploration on
previous dates. The aa, bb & y values don't change.
I presume it has got something to do with LastValue() function but I haven't
been able to sort it out.
Cheers :-)
//Initialise variables
x = Cum(1); //Bar
Daysback = 10; //Period for Liner Regression Line
P = C; //Price field
if(Status("action") ==4) { //If in "exploration" mode
shift = LastValue(x) - x + 1; //Shift reg channel back
}else{ //Not in "exploration" mode
shift = LastValue(x) - Status("lastvisiblebar"); //Shift reg
channel 1 bar back from last visible bar
}
lastx = LastValue(x) - shift;
//Linear Regression Line
aa = LastValue(Ref(LinRegIntercept(p, Daysback), -shift));
bb = LastValue(Ref(LinRegSlope(p, Daysback), -shift));
y = Aa + bb * (x - (Lastx - DaysBack + 1));
LRLine = IIf( x > (lastx - Daysback) AND x <= Lastx, y, Null );
Plot( LRLine , "LinReg", colorRed);
//Exploration
Filter = 1;
AddColumn(x, "x");
AddColumn(Lastx, "Lastx");
AddColumn(shift, "shift");
AddColumn(aa, "aa");
AddColumn(bb, "bb");
AddColumn(y, "y");