I mailed to Tomasz about a AFL script I derived from one on AFL library I added some more lines @ fib distance to the original channel. works fine in day, 60 or 30 min, but with YM in 3 or 5 min my laptop is very, very slow // 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 AB slows to a crawl when using following AFL with YM in 3 min any hint? sincerely // Linear Regression Line with 2 Standard Deviation Channels Plotted Above and Below // Written by Patrick Hargus, with critical hints from Marcin Gorzynski, Amibroker.com <http://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", 233,1,21046,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 1st SD Channel =============================================================== SDP = Param("Standard Deviation", 1.3 , 0, 21, 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 ); Plot ( SDL , "Lower Lin Reg", SDColor,SDStyle ); // ========================== Plot 2d SD Channel =============================================================== SDP2 = Param("2d Standard Deviation", 2.1 , 0, 21, 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 ); Plot ( SDL2 , "Lower Lin Reg", SDColor2,SDStyle2 ); // ========================== Plot 3d SD Channel =============================================================== SDP3 = Param("3d Standard Deviation", 3.4 , 0, 21, 0.1); SD3 = SDP3/ 2; width3 = LastValue( Ref(SD3*StDev (p, Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET SDU3 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width3 , Null ) ; SDL3 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width3 , Null ) ; SDColor3 = ParamColor("3 SD Color", colorCycle ); SDStyle3 = ParamStyle("3 SD Style"); Plot ( SDU3 , "Upper Lin Reg", SDColor3,SDStyle3 ); Plot ( SDL3 , "Lower Lin Reg", SDColor3,SDStyle3 ); // ========================== Plot 4d SD Channel =============================================================== SDP4 = Param("4d Standard Deviation", 5.5 , 0, 21, 0.1); SD4 = SDP4/ 2; width3 = LastValue( Ref(SD4*StDev (p, Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET SDU4 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width3 , Null ) ; SDL4 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width3 , Null ) ; SDColor4 = ParamColor("4 SD Color", colorCycle ); SDStyle4 = ParamStyle("4 SD Style"); Plot ( SDU4 , "Upper Lin Reg", SDColor4,SDStyle4 ); Plot ( SDL4 , "Lower Lin Reg", SDColor4,SDStyle4 ); // ========================== Plot 5d SD Channel =============================================================== SDP5 = Param("5d Standard Deviation", 8.9 , 0, 21, 0.1); SD5 = SDP5/ 2; width5 = LastValue( Ref(SD5*StDev (p, Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET SDU5 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width5 , Null ) ; SDL5 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width5 , Null ) ; SDColor5 = ParamColor("5 SD Color", colorCycle ); SDStyle5 = ParamStyle("5 SD Style"); Plot ( SDU5 , "Upper Lin Reg", SDColor5,SDStyle5 ); Plot ( SDL5 , "Lower Lin Reg", SDColor5,SDStyle5 );
