Pair Ratio
Pair Ratio
Pair Ratio
_SECTION_BEGIN("Linear_Regression_Line_w__Std_Deviation_Channels");
// Linear Regression Line with 2 Standard Deviation Channels Plotted Above and
Below
// Written by Patrick Hargus, with critical hints from Marcin Gorzynski,
Amibroker.com Technical Support
// Designed for use with AB 4.63 beta and above, using drag and drop feature.
// Permits plotting a linear regression line of any price field available on the
chart for a period determined by the user.
// 2 Channels, based on a standard deviation each determined by the user, are
plotted above and below the linear regression line.
// A look back feature is also provided for examining how the indicator would
have appeared on a chart X periods in the past.
P = ParamField("Price field",-1);
Daysback = Param("Period for Liner Regression Line",21,1,360,1);
shift = Param("Look back period",0,0,360,1);
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 ) );
LRLine = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );
Plot( LRLine , "LinReg", LRCOLOR, LRSTYLE ); // styleDots );