// Downloaded From https://www.WiseStockTrader.com
_SECTION_BEGIN("grafik");
UpTrend = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) ) AND EMA( Close, 5 ) > EMA( Close, 20 );
DnTrend = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) ) AND EMA( Close, 5 ) < EMA( Close, 20 );
Color = IIf( UpTrend, colorGreen, IIf( DnTrend, colorRed, colorYellow ) );
Plot( C, "Price", Color, styleBar );
_SECTION_END();

_SECTION_BEGIN("emabeşyirmi");
p1 = Param("TL 1 Periods", 5, 5, 50, 1);
p2 = Param("TL 2 Periods", 20, 3, 25, 1);
x=(H+L+C)/3;
TL1 = EMA(x,p1);
TL2 = EMA(x,p2);
Col1 = IIf(TL1 > TL2, ParamColor("TL Up Colour", colorBrightGreen), ParamColor("TL Dn Colour", colorCustom12));
Plot(TL1, "ema5", Col1, styleLine|styleNoLabel);
Plot(TL2, "ema20", Col1, styleLine|styleNoLabel);
_SECTION_END();


_SECTION_BEGIN("Rashedbgd");

SetChartOptions(0,chartShowArrows|chartShowDates);


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

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


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);
} 

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


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 ); 
Plot( SDL2 , "Lower Lin Reg", colorWhite,SDStyle2 ); 

Trend = IIf(LRLine > Ref(LRLine,-1),colorGreen,colorRed);

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