[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Linear Regression Line Array not plotting, please help


  • Date: Mon, 01 Feb 2010 16:37:35 +0100
  • From: reinsley <reinsley@xxxxxxxx>
  • Subject: Re: [amibroker] Linear Regression Line Array not plotting, please help

PureBytes Links

Trading Reference Links

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
>
> 



------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    amibroker-digest@xxxxxxxxxxxxxxx 
    amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/