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

Re: [amibroker] Linear Regression Channel



PureBytes Links

Trading Reference Links

So, have you looked at 23, 115, and 690 on a daily basis?
Exactly are you trying to accomplish with this?
 
----- Original Message -----
From: Tony Lei
Sent: Saturday, July 23, 2005 5:13 PM
Subject: Re: [amibroker] Linear Regression Channel

Thanks Mr Valley.

It was close.  But there are some timeframes where the plot was zoomed out too much for my taste.  E.g. Weekly. 

If it is possible, I would like to see just the last 24 bars in the chart or something I can customize.

I have it set like this:

Month/Week/Daily

Thanks again,

Tony
qitrader

On 7/23/05, Mr Valley <valleymj@xxxxxxxxxxx> wrote:
Try this - and right click and set time frameif you want something different
 
/* Linear Regression test */
 
P = ParamField("Price field",-1);
 
Daysback = Param("Period for Liner Regression Line",23,1,500,1);
 
shift = Param("Look back period",0,0,500,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 1st SD Channel ===============================================================
 
 
 
SDP = Param("Standard Deviation", 1.5, 0, 6, 0.1);
 
SD = SDP/2;
 
 
 
width = LastValue( Ref(SD*StDev(p, Daysback),-shift) );   // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET 
 
SDU = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width , Null ) ;
 
SDL = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width , Null ) ;
 
 
 
SDColor = ParamColor("SD Color", colorCycle );
 
SDStyle = ParamStyle("SD Style");
 
 
 
Plot( SDU , "Upper Lin Reg", SDColor,SDStyle | styleNoRescale);
 
Plot( SDL , "Lower Lin Reg", SDColor,SDStyle | styleNoRescale);
 
 
 
//  ==========================  Plot 2d SD Channel ===============================================================
 
 
 
SDP2 = Param("2d Standard Deviation", 2.0, 0, 6, 0.1);
 
SD2 = SDP2/2;
 
 
 
width2 = LastValue( Ref(SD2*StDev(p, Daysback),-shift) );   // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET 
 
SDU2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width2 , Null ) ;
 
SDL2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width2 , Null ) ;
 
 
 
SDColor2 = ParamColor("2 SD Color", colorCycle );
 
SDStyle2 = ParamStyle("2 SD Style");
 
 
 
Plot( SDU2 , "Upper Lin Reg", SDColor2,SDStyle2 | styleNoRescale);
 
Plot( SDL2 , "Lower Lin Reg", SDColor2,SDStyle2 | styleNoRescale);


Plot(Close,"Close",1,4);
 
// ============================ End Indicator Code
 
 
 
 
 
 
 
 
 
 
 
 
 
----- Original Message -----
From: Tony Lei
Sent: Saturday, July 23, 2005 2:08 PM
Subject: Re: [amibroker] Linear Regression Channel

Great

But where do I put that into.  The code is provided below.

Thanks

tony

P = ParamField("Price field",-1);
Daysback = Param("Period for Liner Regression Line",23,1,500,1);
shift = Param("Look back period",0,0,500,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 1st SD Channel ===============================================================

SDP = Param("Standard Deviation", 1, 0, 6, 0.1);
SD = SDP;

width = LastValue( Ref(SD*StDev(p, Daysback),-shift) );   // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET 
SDU = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width , Null ) ;
SDL = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width , Null ) ;

SDColor = ParamColor("SD Color", colorCycle );
SDStyle = ParamStyle("SD Style");

Plot( SDU , "Upper Lin Reg", SDColor,SDStyle );
Plot( SDL , "Lower Lin Reg", SDColor,SDStyle );

//  ==========================  Plot 2d SD Channel ===============================================================

SDP2 = Param("2d Standard Deviation", 2, 0, 6, 0.1);
SD2 = SDP2;

width2 = LastValue( Ref(SD2*StDev(p, Daysback),-shift) );   // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET 
SDU2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width2 , Null ) ;
SDL2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width2 , Null ) ;

SDColor2 = ParamColor("2 SD Color", colorCycle );
SDStyle2 = ParamStyle("2 SD Style");

Plot( SDU2 , "Upper Lin Reg", SDColor2,SDStyle2 );
Plot( SDL2 , "Lower Lin Reg", SDColor2,SDStyle2 );

// ============================ End Indicator Code ==============================================================






Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html





YAHOO! GROUPS LINKS






Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html





YAHOO! GROUPS LINKS