// Downloaded From https://www.WiseStockTrader.com
NormalCandle=ParamToggle("Plot Normal Candle", "No,Yes", 1 );
_SECTION_BEGIN("Linear Regression Channel");
//CyberMan's Linear Regression Channel.
font = ParamToggle("font","Show|Hide",1);
plus= Param("plus", 2,0,52,1);
Minus = Param("Minus", -2,-15,-1,-20);
//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 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);


//SetForeign(Vr);

p = Param("p",5,2,100,1);

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

Om=DEMA(O,p);
hm=DEMA(H,p);
lm=DEMA(L,p);
Cm=DEMA(C,p);
HAC=(Om+Hm+Lm+Cm)/4;
//HaC =(O+H+L+C)/4;
HaO = AMA( Ref( HaC, -1 ), 0.5 );
HaH = Max( H, Max( HaC, HaO) );
HaL = Min( L, Min( HaC, HaO) );
HAClose=(Om+Hm+Lm+Cm)/4;
//HaC =(O+H+L+C)/4;
HaOpen = AMA( Ref( HaC, -1 ), 0.5 );
HaHigh = Max( H, Max( HaC, HaO) );
HaLow = Min( L, Min( HaC, HaO) );
BG3=HHV(LLV(HaL,4)+ATR(4),8);
BR3=LLV(HHV(HaH ,4)-ATR(4),8);

co = IIf(Hac>BG3 ,colorBrightGreen,IIf(Hac < BR3,colorRed,colorGrey50));
Plot(4, "", Co,styleArea+styleOwnScale | styleNoLabel, -1, 100);
RestorePriceArrays();
if(NormalCandle==1  )
{
  PlotOHLC( Hac, Hao, Hah, Hal, " " , co, styleCandle | styleThick );
}
else
{
PlotOHLC( Open, High, Low, Close, " " ,co, styleCandle | styleThick );

}

//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);
//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 =========
_SECTION_BEGIN("Unnamed 1");


threshold = 5;
uptrend = StochK(39,3) > StochD(39,3,3);
downtrend =StochK(39,3) < StochD(39,3,3);

Buy = uptrend AND H >= Ref(H,-1) + threshold; BuyPrice = Max(O,Ref(H,-1) + threshold);
Sell = downtrend AND L <= Ref(L,-1) - threshold; SellPrice = Min(O,Ref(L,-1) - threshold);




Short=Sell;
Cover=Buy;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
//Buy=Cross(Avg,MA(C,30));
//Sell=Cross(MA(C,30),Avg);
prch = (C- TimeFrameGetPrice( "C", inDaily, -1 ))/ TimeFrameGetPrice( "C", inDaily, -1 )*100 ;
prcha= (C-Ref(C,-6))/Ref(C,-6)*100;
prche= (C-Ref(C,-2))/Ref(C,-1)*100;
prch5=(prche-prch);
prch6= (C-Ref(C,-5))/Ref(C,-5)*100;
prch7= (C-Ref(C,-29))/Ref(C,-29)*100;
prch8= (C-Ref(C,-87))/Ref(C,-87)*100;
prch9= (C-Ref(C,-150))/Ref(C,-150)*100;
prch10= (C-Ref(C,-245))/Ref(C,-245)*100;
prch11= (C-Ref(C,-490))/Ref(C,-490)*100;
prch12= (C-Ref(C,-735))/Ref(C,-735)*100;
prch13= (C-Ref(C,-1225))/Ref(C,-1225)*100;

col=IIf ((Volume > 1.25 * EMA( Volume, 34 )),colorRed,colorLime);

Filter = prch > plus OR prch  < Minus  ;
//Filter = prch6 <3 OR prch6  <-3 ;
AddColumn(Close,"Close",1.2,colorDefault, Col);
AddColumn(prch5,"prviday", 1.2,colorDefault, Col);	
AddColumn(prch,"daily", 1.2,colorDefault, Col); 
AddColumn(Volume,"Volume",1.0, colorDefault, IIf ((Volume > 1.25 * EMA( Volume, 34 )),colorLightBlue,colorLime));
AddColumn( IIf( Buy, 66 , 83 ), "Signal", formatChar, colorDefault, IIf( Buy , colorGreen, colorRed ) );

AddColumn(prch6,"weekly", 1.2,colorDefault, Col);
AddColumn(prch7,"monthly", 1.2,colorDefault, Col);
AddColumn(prch8,"qutrly", 1.2,colorDefault, Col);
AddColumn(prch9,"halfyly", 1.2,colorDefault, Col);
AddColumn(prch10,"yearly", 1.2,colorDefault, Col); 
AddColumn(prch11,"twoyrly", 1.2,colorDefault, Col); 
AddColumn(prch12,"thirdyrly", 1.2,colorDefault, Col); 
AddColumn(prch13,"fiveyrly", 1.2,colorDefault, Col); 


PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorWhite, colorYellow ) );

for( i = 0; i < BarCount; i++ )
{
 if( Buy[i] )
 {

OUTcolor = ParamColor("Outer Panel Color",colorTeal);
INUPcolor = ParamColor("Inner Panel Upper",colorDarkGrey);
INDNcolor = ParamColor("Inner Panel Lower",colorDarkOliveGreen);
TitleColor = ParamColor("Title Color ",colorBlack);
SetChartBkColor(OUTcolor); // color of outer border
SetChartBkGradientFill(INUPcolor,INDNcolor,TitleColor); // color of inner panel
}
if( Sell[i] )
{
OUTcolor = ParamColor("Outer Panel Color",colorTeal);
INUPcolor = ParamColor("Inner Panel Upper2",colorDarkTeal);
INDNcolor = ParamColor("Inner Panel Lower2",colorPlum);
TitleColor = ParamColor("Title Color ",colorBlack);
SetChartBkColor(OUTcolor); // color of outer border
SetChartBkGradientFill(INUPcolor,INDNcolor,TitleColor); // color of inner panel
}
}

if(font==0)
{
_SECTION_BEGIN("Name");
GfxSetOverlayMode(0);
GfxSelectFont("Tahoma", Status("pxheight")/8 );
GfxSetTextAlign( 6 );// center alignment
GfxSetTextColor( ColorHSB( 42, 42, 42 ) );
GfxSetBkMode(0); // transparent
GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/12 );
GfxSelectFont("Tahoma", Status("pxheight")/18 );
GfxTextOut("" , Status("pxwidth")/2, Status("pxheight")/4 );
GfxSelectFont("Tahoma", Status("pxheight")/18 );
GfxSelectFont("Tahoma", Status("pxheight")/36 );
GfxTextOut( "", Status("pxwidth")/2, Status("pxheight")/3 );
_SECTION_END();

//Magfied Market Price
FS=Param("Font Size",72,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True ); 
GfxSetBkMode(0); // transparent 
GfxSetTextColor( ColorHSB( 42, 42, 42 ) );
Hor=Param("Horizonta Position",615,1,1200,1);
Ver=Param("Vertica Position",152,1,830,1); 
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
FS2=Param("Font Size2",35,11,100,1);
GfxSelectFont("Times New Roman", FS2,11, 700, True ); 
GfxSetBkMode( colorBlack );
Hor1=Param("Horizontal Position",615,1,1200,1);
Ver1=Param("Vertical Position",188,1,830,1);   
GfxSetTextColor( ColorHSB( 42, 42, 42 ) ); 
GfxTextOut(""+DD+"  ("+xx+"%)", Hor1 , Ver1+45 );
}
else
{{
//Magfied Market Price
fse=Param("Font Sizee",35,11,100,1);
GfxSelectFont("Times New Roman", fse, 700, True ); 
GfxSetBkMode( colorGold );  
GfxSetTextColor( ParamColor("Color",colorGold) ); 
Hora=Param("Horizontal Positiona",525,1,1200,1);
Vera=Param("Vertical Positiona",17,1,830,1); 
GfxTextOut(""+C, Hora , Vera );
YCa=TimeFrameGetPrice("C",inDaily,-1);
DDa=Prec(C-YCa,2);
xxa=Prec((DDa/YCa)*100,2);
FSb=Param("Font Sizeb",16,11,100,1);
GfxSelectFont("Times New Roman",fsb, 700, True ); 
GfxSetBkMode( colorBlack );  
GfxSetTextColor(ParamColor("Color",colorYellow) ); 
GfxTextOut(""+DDa+"  ("+xxa+"%)", Hora , Vera+45 );
 _SECTION_END();
}}



SellPrice=ValueWhen(Sell,C,1);
BuyPrice=ValueWhen(Buy,C,1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );
Edc=(
WriteIf (Buy AND Ref(shrt,-1), " BUY @ "+C+"  ","")+ 
WriteIf (Sell AND Ref(Long,-1), " SEll @ "+C+"  ","")+
WriteIf(Sell , "Last Trade Profit Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy  , "Last Trade Profit Rs."+(SellPrice-C)+"",""));

//============== TITLE ==============



_SECTION_BEGIN("Tops and bottom");

pd = Param("Periods",13,5,144,1); 
pds = 2*pd-1;//     (Adjustment for Wilders MA) 
aa = Close-Ref(Close,-1); 
uu = EMA(Max(0,aa),pds); 
dd=  EMA((Max(0,0-aa)),pds); 

rf = IIf(C>2,1000,10000); 

c1 = Param("Upper Level",70,50,90,1); 
qq1 =100/(100-c1)-1; 
ff1 = qq1*dd-uu; 
ff2 = ff1/qq1; 
f1 = Max(ff1,ff2); 
UL = Close + f1*(pds-1)/2; 
UL = IIf(UL>C,floor(UL*rf),ceil(UL*rf))/rf; 

c2 = Param("Equilibrium",50,50,50,0);  
qq2 =100/(100-c2)-1;// [=1] 
ff = dd-uu; 
MM = Close + ff*(pds-1)/2; 
MM = IIf(MM>C,floor(MM*rf),ceil(MM*rf))/rf; 

c3 = Param("Lower Level",30,10,50,1); 
qq3 =100/(100-c3)-1; 
ff1 = qq3*dd-uu; 
ff2 = ff1/qq3; 
f3 = Min(ff1,ff2); 
LL = Close + f3*(pds-1)/2; 
LL = IIf(LL>C,floor(LL*rf),ceil(LL*rf))/rf; 

band = Param("band width",4,0,15,0.25);
mmu = MM+band;
mmd = MM-band;

_SECTION_BEGIN("Pivot calc");

TimeFrameSet( in15Minute*2 ); 
DH=Ref(H,-1); 
DL=Ref(L,-1);
DC=Ref(C,-1);


pd = ( DH+ DL + DC )/3;
sd1 = (2*pd)-DH;
sd2 = pd -(DH - DL);
sd3 = Sd1 - (DH-DL); 
rd1 = (2*pd)-DL;
rd2 = pd +(DH -DL);
rd3 = rd1 +(DH-DL);



_SECTION_BEGIN("Title");
no=Param( "Swing", 6, 1, 55 );
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
tsl=IIf(avn==1,sup,res);
dec = (Param("Decimals",2,0,7,1)/10)+1;
if( Status("action") == actionIndicator ) 
(
Title = EncodeColor(55)+  Title = Name() + "     " + EncodeColor(32) + Date() +
"      " + EncodeColor(5) + "{{INTERVAL}}  " +
	EncodeColor(55)+ "     Open = "+ EncodeColor(52)+ WriteVal(O,dec) + 
	EncodeColor(55)+ "     High = "+ EncodeColor(5) + WriteVal(H,dec) +
	EncodeColor(55)+ "      Low = "+ EncodeColor(32)+ WriteVal(L,dec) + 
	EncodeColor(55)+ "    Close = "+ EncodeColor(52)+ WriteVal(C,dec)+
	EncodeColor(55)+ "    Volume = "+ EncodeColor(52)+ WriteVal (V ,1.25)




+"\n"+EncodeColor(colorBrightGreen)+

WriteIf (Buy , "Signal: Go Long - Entry Price: "+WriteVal(C)+" - Traget: "+WriteVal((BuyPrice-tsl)+BuyPrice)

+" - StopLoss:"+WriteVal(tsl)+"  "

,"")+

"\n"+EncodeColor(colorRed)+
WriteIf (Sell , "Signal: Go Short - Entry Price: "+WriteVal(C)+" - Target: "+WriteVal((tsl-SellPrice)-SellPrice)+" - StopLoss:"+WriteVal(tsl)+" ","")+
EncodeColor(colorTurquoise)+
WriteIf(Long AND NOT Buy, "Trade: Long - Entry Price: "+WriteVal((BuyPrice))+" - Profit: "+WriteVal((C-BuyPrice))+" "+EncodeColor(colorLime)+"Let your profit runs!","")+
EncodeColor(colorLightOrange)+
WriteIf(shrt AND NOT Sell, "Trade: Short - Entry Price: "+WriteVal((SellPrice))+" - Profit: "+WriteVal((SellPrice-C))+"  - "+EncodeColor(colorLime)+"Let your profit runs!","")+

EncodeColor(colorBrightGreen)+   "


\n R3 : "+ 
EncodeColor(colorWhite)+RD3+ 
EncodeColor(colorBrightGreen)+   "\n R2 : "+ 
EncodeColor(colorWhite)+RD2+ 
EncodeColor(colorBrightGreen)+   "\n R1 : " +
EncodeColor(colorWhite)+RD1 + 
EncodeColor(colorBrightGreen)+  "     UP TGT   : "+ 
EncodeColor(colorWhite)+UL+ 
EncodeColor(colorBlue)+   "\n Pivot : "+
EncodeColor(colorWhite)+pd+ 
EncodeColor(colorBlue)+   "    MIDPOINT : "+ 
EncodeColor(colorWhite)+MM+ 
EncodeColor(colorRed)+   "\n S1 : "+ 
EncodeColor(colorWhite)+SD1   + 
EncodeColor(colorRed)+    "     BOT TGT  : "+ 
EncodeColor(colorWhite)+LL+ 
EncodeColor(colorRed)+   "\n S2 : "+ 
EncodeColor(colorWhite)+SD2+ 
EncodeColor(colorRed)+   "\n S3 : "+ 
EncodeColor(colorWhite)+SD3



);
_SECTION_END();


PlotShapes(IIf(Sell, shapeStar, shapeNone),colorGold, 0, H, Offset=15);
PlotShapes(IIf(Buy, shapeStar, shapeNone),colorWhite, 0,L, Offset=-15);
/*
dist = 4.5*ATR(10); 

for( i = 0; i < BarCount; i++ ) 
{ 

if( Buy[i] ) PlotText( "Buy @ \n"+C[i] , i, L[ i ]-dist[i], colorBlack,colorGreen ); 
if( Sell[i] ) PlotText( "Sell@ \n"+C[i], i, H[ i ]+dist[i], colorBlack, colorRed ); 
//if( Buy[i] ) PlotText( "B" , i, L[ i ]-dist[i], colorBlack,colorGreen ); 
//if( Sell[i] ) PlotText( "S" , i, H[ i ]+dist[i], colorBlack, colorRed ); 
if( Buy[i]  ) PlotText( "Top" , i, C[ i ]+dist[i], colorGreen, colorBlack ); 
if( Sell[i] ) PlotText( "Bottom", i, C[ i ]-dist[i], colorRed, colorBlack ); 
 } 
*/

_SECTION_BEGIN("Multiple Ribbon ");
// You plot a Ribbon by calling the function as follows: MultiRibbon("Color", "Ribbon Number", "Name To Display");
// The "Ribbon Number" is simply the order of the ribbon, starting with 1 as the bottom Ribbon. You can add as many 
// ribbons as you want, until you run out of chart space. Just keep track of the 'Serial Number' (Ribbon Number). :-)


RibbonThickness	= Param("Ribbon Thickness", 4, 1, 15, 0.1);
Font				= ParamList("Font:","Arial|Calibri|Futura|Tahoma|Times New Roman");
"";
function GfxConvertBarToPixelX(Bar) 
{ 
 lvb = Status("lastvisiblebar"); fvb = Status("firstvisiblebar"); 
 pxchartleft = Status("pxchartleft"); pxchartwidth = Status("pxchartwidth"); 
 return pxchartleft + Bar  * pxchartwidth / (Lvb - fvb + 1); 
} 

procedure MultiRibbon(RibbonColor, Position, Label)
{
 LineColor	= colorLightGrey;
 Position	= RibbonThickness * Position;
 x2 = Status("pxchartright");
 y2 = Status("pxchartbottom");

 RibbonColor = IIf(GfxConvertBarToPixelX(BarIndex()-Status("firstvisiblebarindex")) > y2/1.5 * (RibbonThickness/100) * 18 , RibbonColor, colorYellow);

 Plot(0, "", LineColor, styleOwnScale | styleNoLabel, 0, 100);
 Plot(Position, "", LineColor, styleOwnScale | styleNoLabel, 0, 100);
 Plot(Position, "", RibbonColor, styleArea | styleOwnScale | styleNoLabel, 0, 100);

 GfxSetTextColor(colorBlack); 
 GfxSelectFont(Font, y2/1.5 * (RibbonThickness/100), 400); 
 GfxDrawText(Label, 8, y2 * 1.001 -(y2 * Position/100) , y2/1.5 * (RibbonThickness/100) * 17, y2, 2 + 32 + 256);
 
}

//============================================pl color=======================
PL = (H + C+ L)/3;
r1 = IIf (MA(pl,3) >Ref(MA(pl,3),-1),colorGreen,colorRed); 
//---------------------------------------------------------------------------




//==========================================RSI BB===========================
RSI21 = EMA(RSI(21),5);

r2 = IIf (RSI21 >BBandTop(RSI21,5,0.5),colorGreen,IIf (RSI21 <BBandBot(RSI21,5,0.5),colorRed,colorYellow)); 
//---------------------------------------------------------------------------




//========================================Macd BB ==============================

r3 = IIf (MACD(3,34) >BBandTop(MACD(3,34),5,0.5),colorGreen,IIf (MACD(3,34) <BBandBot(MACD(3,34),5,0.5),colorRed,colorYellow));
//---------------------------------------------------------------------------




//========================================ADX quick ==============================
r4 = IIf(Buy > Sell,colorGreen,colorRed); 

/* 
EMA21 = IIf (MACD(34,55) >Ref(MACD(34,55),-1),colorGreen,colorRed); 
EMA34 = IIf (MACD(55,89) >Ref(MACD(55,89),-1),colorGreen,colorRed); 
EMA55 = IIf (MACD(3,34) >Ref(MACD(3,34),-1),colorGreen,colorRed); 
*/
EMA21 = IIf(PDI(5) > MDI(5),colorGreen,colorRed); 
EMA34 = IIf(PDI(9) > MDI(9),colorGreen,colorRed); 

//========================================ADX trend ==============================

r6 = IIf(Buy > Sell,colorGreen,colorRed); 

//---------------------------------------------------------------------------


MultiRibbon(r6, 1, "adx")+ADX(7); 
MultiRibbon(EMA34, 2, "ema-34")+EMA(pl,34); 
MultiRibbon(EMA21, 3, "ema-21")+EMA(pl,21); 
MultiRibbon(r4, 4, "PDI-MDI"); 
MultiRibbon(r3, 5, "Macd - BB"); 
MultiRibbon(r2, 6, "RSI-BB"); 
MultiRibbon(r1, 7, "PL color"); 


//==================interpretation============================

WriteIf(EMA( Close,13)>EMA( Close,39),"EMA says : UP TREND \n EMA -50 SL of "+ WriteVal(EMA(Close,50)),"EMA says : DOWN TREND \n  EMA "+ WriteVal(EMA(Close,50)));
WriteIf (Trix( 9 ) > Ref( Trix( 9 ) , -1 ),"\n TRIX =" + WriteVal(Trix( 9 ))+ " : UP","\n TRIX =" + WriteVal(Trix( 9 ))+"   : DOWN");
WriteIf (MACD( 12, 26 ) > Ref( MACD( 12, 26 ) , -1 ), "MACD ="+ WriteVal(MACD( 12, 26 ))+ " : UP","MACD ="+ WriteVal(MACD( 12, 26 ))+ " : DOWN");
WriteIf(ADX( 9 ) > Ref( ADX( 9 ) , -1 ),"ADX ="+WriteVal (ADX(9))+"   :TREND-ING","ADX ="+WriteVal (ADX(9))+"   : ----");
WriteIf (RSI( 7 ) > Ref( RSI(7) , -1 ), "RSI ="+ WriteVal(RSI( 7))+ " : UP","RSI ="+ WriteVal(RSI( 7))+ " : DOWN");
WriteIf (CCI( 10 ) > Ref( CCI(10) , -1 ), "CCI ="+ WriteVal(CCI( 10))+ " : UP","CCI ="+ WriteVal(CCI( 10))+ " : DOWN");
WriteIf(StochK( 14)< Ref (StochK( 14),1) ,"stochastic ="+WriteVal (StochK(14))+" : UP " ,"stochastic ="+WriteVal (StochK( 14))+" : DOWN ");
"";
WriteIf (Close > SAR( 0.02, 0.2 ),"SAR says : go LONG at "+Close+" \n with a Stop-Loss = " + WriteVal(  SAR( 0.02, 0.2 )),"SAR says : go Short at "+Close+"\n with a Stop-Loss = " + WriteVal(  SAR( 0.02, 0.2 )));