Reinsley - thanks but what you provided already exists in my code. I am trying to create a linearray (versus the standard line that your code creates). I believe a linearray is the cleanest way to project future values in the blank chart space.
Thanks, David K. --- In [email protected], reinsley <reins...@...> wrote: > > > This code may help you > > BR > > ////////////////// LINEAR REGRESSION /////////////////////////////////// > //http://www.amibroker.com/library/detail.php?id=438 > //OK > > P = H;//ParamField("Price field",-1); > Daysback = Param("Period for Liner Regression Line",21,1,240,1); > shift = Param("Look back period",0,0,240,1); > > > // =============================== Math > Formula===================================== > > x = Cum(1); > lastx = LastValue( x ) - shift; > aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) ); > bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) ); > y = Aa + bb * ( x - (Lastx - DaysBack +1 ) ); > > > // ==================Plot the Linear Regression > Line================================== > > > LRColor = ParamColor("LR Color", colorCycle ); > LRStyle = ParamStyle("LR Style"); > > LRLine = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null ); > Plot( LRLine , "LinReg", LRCOLOR, LRSTYLE ); // styleDots ); > > > Plot(C,"Close",colorBlack,styleBar); > _N(Title = "LINEAR REGRESSION - "+StrFormat("{{NAME}} - {{INTERVAL}} > {{DATE}} Open %g, Hi %g, Lo %g, Cl %g {{VALUES}}", O, H, L ,C )); > > > > > > Le 31/01/2010 20:11, wooziwog a écrit : > > > > > > The following formula plots the Linear Regression. I have created the > > start and ending points for the linearray as well as the starting and > > ending y values. When I press the "apply indicator" the line array > > appears for a moment and then disappears. Any help in identifying my > > coding error is appreciated. > > > > Thanks, > > > > David K. > > > > //Linear Regression Line Array > > > > GraphXSpace=5; > > Plot(C,"",29,128|4); > > > > pds=20; > > lbk=0; > > bi = BarIndex()+1; > > sb = SelectedValue(BarIndex()); > > sx = SelectedValue(bi)-lbk; > > aa = SelectedValue(Ref(LinRegIntercept(C,pds),-lbk)); > > bb = SelectedValue(Ref(LinRegSlope(C,pds),-lbk)); > > yy = aa + bb * (bi-(sx - pds+1)); > > xs = sb - pds - lbk;//Linearray starting point > > ys = SelectedValue(Ref(yy, -pds-lbk));//Linearray starting value > > xe = sb - lbk;//Linearray ending point > > ye = ys + bb *(xe - xs);//Linearray starting value > > LR = IIf(bi >= (sx - pds) AND bi <= sx, yy, Null);//standard LR line > > Plot(LR, "LR", 10, 1);//plot Linear Regression Line > > > > Plot(IIf(bi>xs,ys,Null),"",36,8);//Linearray starting Value from "xs" > > Plot(IIf(bi>xe,ye,Null),"",36,8);//Linearray ending Value from "xe" > > Plot(LineArray(xs,ys,xe,ye,1),"LR",25,1);//This line only plots for a > > moment when "apply indicator" is pressed and then disappears > > > > >
