I need this AFL. Please help me !

#3
Could you please elaborate?
I need color Linear Regression Channel

_SECTION_BEGIN("Linear Regression Channel");
//CyberMan's Linear Regression Channel.

//Linear Regression Line with 2 Standard Deviation Channels Plotted Above and Below
//The original was written by Patrick Hargus, with critical hints from Marcin Gorzynski, Amibroker.com Technical Support
//Wysiwyg coded the angle in degrees part
//I modified the original Linear Regression code so that the line will change color based on the degree of the Linear Regression slope.
//I combine this with my trading system.
//When my system gives an entry signal I look at the Linear Regression Line and I will only take long positions if the Linear Regression line is green and the entry price is below the LR line.
//When my system gives an entry signal I look at the Linear Regression Line and I will only take short positions if the Linear Regression line is red and the entry price is above the LR line.
//It is usefull for filtering out lower probability trades.

//====================================Start of Linear Regression Code==================================================================================

P = ParamField("Price field",-1);

Length = 150;

Daysback = Param("Period for Liner Regression Line",Length,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 );

LRStyle = ParamStyle("LR Style");
Angle = Param("Angle", 0.05, 0, 1.5, 0.01);// A slope higher than 0.05 radians will turn green, less than -0.05 will turn red and anything in between will be white.

LRLine = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );

Pi = 3.14159265 * atan(1); // Pi
SlopeAngle = atan(bb)*(180/Pi);

LineUp = SlopeAngle > Angle;
LineDn = SlopeAngle < - Angle;

if(LineUp)
{
Plot(LRLine, "Lin. Reg. Line Up", IIf(LineUp, colorBrightGreen, colorWhite), LRStyle);
}
else
{
Plot(LRLine, "Lin. Reg. Line Down", IIf(LineDn, colorDarkRed, colorWhite), LRStyle);
}

//========================== 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) ); //Set width of inside chanels here.
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", colorWhite,SDStyle ); //Inside Regression Lines
Plot( SDL , "Lower Lin Reg", colorWhite,SDStyle ); //Inside Regression Lines

//========================== 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) ); //Set width of outside chanels here.
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", colorWhite,SDStyle2 ); //OutSide Regression Lines
Plot( SDL2 , "Lower Lin Reg", colorWhite,SDStyle2 ); //OutSide Regression Lines

Trend = IIf(LRLine > Ref(LRLine,-1),colorGreen,colorRed);//Changes LR line to green if sloping up and red if sloping down.

Plot( LRLine , "LinReg", Trend, LRSTYLE );

//===================== End Indicator Code
 
#4
_SECTION_BEGIN("Trend Lines");
p1 = Param("TL 1 Periods", 20, 5, 50, 1);
p2 = Param("TL 2 Periods", 5, 3, 25, 1);
TL1 = LinearReg(C, p1);
TL2 = EMA(TL1, p2);
Col1 = IIf(TL1 > TL2, ParamColor("TL Up Colour", colorGreen), ParamColor("TL Dn Colour", colorRed));
Plot(TL1, "TriggerLine 1", Col1, styleLine|styleThick|styleNoLabel);
Plot(TL2, "TriggerLine 2", Col1, styleLine|styleThick|styleNoLabel);
_SECTION_END();

_SECTION_BEGIN("Linear Regression Channel");
//CyberMan's Linear Regression Channel.

//Linear Regression Line with 2 Standard Deviation Channels Plotted Above and Below
//The original was written by Patrick Hargus, with critical hints from Marcin Gorzynski, Amibroker.com Technical Support
//Wysiwyg coded the angle in degrees part
//I modified the original Linear Regression code so that the line will change color based on the degree of the Linear Regression slope.
//I combine this with my trading system.
//When my system gives an entry signal I look at the Linear Regression Line and I will only take long positions if the Linear Regression line is green and the entry price is below the LR line.
//When my system gives an entry signal I look at the Linear Regression Line and I will only take short positions if the Linear Regression line is red and the entry price is above the LR line.
//It is usefull for filtering out lower probability trades.


//================================================Start Chart Configuration============================================================================

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
SetChartBkGradientFill(ParamColor("Top", colorTeal), ParamColor("Bottom", colorLightGrey), ParamColor("Title", colorTeal));
SetChartBkColor(colorTeal);


Plot( C, "Close", colorWhite, styleCandle, Zorder = 1);
SetChartOptions(0,chartShowArrows | chartShowDates);

//================================================End Chart Configuration===============================================================================


//====================================Start of Linear Regression Code==================================================================================

P = ParamField("Price field",-1);

Length = 150;

Daysback = Param("Period for Liner Regression Line",Length,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 );

LRStyle = ParamStyle("LR Style");
Angle = Param("Angle", 0.05, 0, 1.5, 0.01);// A slope higher than 0.05 radians will turn green, less than -0.05 will turn red and anything in between will be white.

LRLine = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );

Pi = 3.14159265 * atan(1); // Pi
SlopeAngle = atan(bb)*(180/Pi);

LineUp = SlopeAngle > Angle;
LineDn = SlopeAngle < - Angle;

if(LineUp)
{
Plot(LRLine, "Lin. Reg. Line Up", IIf(LineUp, colorBrightGreen, colorWhite), LRStyle);
}
else
{
Plot(LRLine, "Lin. Reg. Line Down", IIf(LineDn, colorDarkRed, colorWhite), LRStyle);
}

//========================== 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) ); //Set width of inside chanels here.
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", colorWhite,SDStyle ); //Inside Regression Lines
Plot( SDL , "Lower Lin Reg", colorWhite,SDStyle ); //Inside Regression Lines

//========================== 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) ); //Set width of outside chanels here.
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", colorWhite,SDStyle2 ); //OutSide Regression Lines
Plot( SDL2 , "Lower Lin Reg", colorWhite,SDStyle2 ); //OutSide Regression Lines

Trend = IIf(LRLine > Ref(LRLine,-1),colorGreen,colorRed);//Changes LR line to green if sloping up and red if sloping down.

Plot( LRLine , "LinReg", Trend, LRSTYLE );

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

a1b1trader

Well-Known Member
#5
Are you looking for this
I hope this will serve your purpose

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g,
//Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
//Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("Heiken Ashi Smoothed");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorLightGrey ));
SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace=5;
p=Param("Period",6,2,30,1);
Om=MA(O,p);
hm=MA(H,p);
lm=MA(L,p);
Cm=MA(C,p);
HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "" + Name(), colorWhite, styleCandle | styleNoLabel );
_SECTION_END();
Line=ParamToggle("Show Line chart also","Hide|Show",0);
if(Line==1) {
Plot(C,"Close",colorWhite,styleLine);
}


a=LinearReg(HaClose, 5 ) ;
b=LinearReg( HaClose, 5 ) ;

Plot( IIf(HaHigh>HaOpen,a,b), _DEFAULT_NAME(), colorRed, ParamStyle("Style") );

Plot( LinearReg( HaOpen, 5 ), _DEFAULT_NAME(), colorWhite, ParamStyle("Style") );


_SECTION_BEGIN("MA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();



_SECTION_BEGIN("Magnified Market Price");
//by Vidyasagar, [email protected]//
FS=Param("Font Size",30,30,100,1);
GfxSelectFont("Arial", FS, 900, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorYellow) );
//Hor=Param("Horizontal Position",800,800,800,800);

Hor=Param("Horizontal Position",500,500,200,20);




Ver=Param("Vertical Position",50,50,250,50);
GfxTextOut(""+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor+5, Ver+45 );
_SECTION_END();




_SECTION_BEGIN("Price Line");

PriceLineColor=ParamColor("PriceLineColor",ColorRGB(82,82,82));
PriceLevel = ParamField("PriceField", field = 3 );

Daysback = Param("Bars Back",100,10,500,1);
FirstBar = BarCount - DaysBack;
YY = IIf(BarIndex() >= Firstbar,EndValue(PriceLevel),Null);

Plot(YY,"Current Price",PriceLineColor,ParamStyle("LineStyle",styleLine|styleDashed|styleNoTitle|styleNoLabel|styleThick,maskAll));


side = Param("side",1,0,1000,1);

dist = 0;

for( i = 0; i < BarCount; i++ )
{
if(i+side== BarCount) PlotText( "\n " + PriceLevel[ i ], i, YY[ i ]-dist, colorLightBlue );
}


_SECTION_END();


/*
_SECTION_BEGIN("Linear Regression");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( LinearReg( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("Linear Regression1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( LinearReg( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

*/





_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

//Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
//(Title = StrFormat(" - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C ));

(Title = StrFormat("{{DATE}} O %g, H %g, L %g,
C %g (%.1f%%) ", O, H, L, C ) )
//+"\n"+EncodeColor(colorPink)+"-----------------------------------------"
//+"\n"+EncodeColor(colorOrange)+"The Sultan Foundation v 13.01 Int"
//+"\n"+EncodeColor(colorLightOrange)+"by Sultanji "
//+"\n"+EncodeColor(colorPink)+"-----------------------------------------"


//+"\n"+EncodeColor(colorOrange)+"If bright green candle BUY and If red candle SELL" )
//+"\n"+EncodeColor(colorLightOrange)+"by Sultanji "
;

_SECTION_END();
 

a1b1trader

Well-Known Member
#8
@ prabhsingh
No, I am not using this AFL on a regular basis.
I do not know whether it is worth or not.

@ colorafl
Sorry, I do not have any other than this.
 

Similar threads