// Downloaded From https://www.WiseStockTrader.com
//SAM-JN-AFL V1.0 .. Made by SAM(Admin and Founder of Traderadda.com)
//This AFL is made with help of various codes available freely. I have made many alterations and Some my design in it. 
//If you have any suggestions please visit http://traderadda.com 

_SECTION_BEGIN("Background Color Switcher");
if (NOT ParamToggle("Background switch","On,Off",defaultval=1))
{
bckg1=ParamColor("Background level 1",colorBlack);
bckg2=ParamColor("Background level 2",colorBlack);
bckg3=ParamColor("Background level 3",ColorRGB(25,0,0));
bckg4=ParamColor("Background level 4",ColorRGB(40,0,0));
stockname=ParamColor("Stock name color",ColorRGB(44,44,37));


GfxGradientRect(0,0,Status("pxwidth"),Status("pxhe ight")*2/5,bckg1,bckg2);
GfxGradientRect(0,Status("pxheight")*2/5,Status("pxwidth"),Status("pxheight")*4/5,bckg2,bckg3);
GfxGradientRect(0,Status("pxheight")*4/5,Status("pxwidth"),Status("pxheight"),bckg3,bckg4 );

if (NOT ParamToggle("StockName Switch","On,Off"))
{
GfxSelectFont("Time news roman", Status("pxheight")/7 );
GfxSetTextAlign(6 );
GfxSetOverlayMode(1);
GfxSetTextColor(stockname);

GfxSetBkMode(0);
GfxTextOut(Name(),Status("pxwidth")/2, Status("pxheight")/18 );

GfxSelectFont("Time news roman", Status("pxheight")/26 );
GfxTextOut(FullName(), Status("pxwidth")/2, Status("pxheight")/3.9 );

GfxSelectFont("Time news roman", Status("pxheight")/25 );
GfxTextOut("Market: " + MarketID(1), Status("pxwidth")/2, Status("pxheight")/3 );
}
}
_SECTION_END();

_SECTION_BEGIN("Background text");
//C11=ParamColor("up panel",colorBlack );
//C12=ParamColor("dn panel",colorBlack );
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode( 0 );
GfxSetOverlayMode(1);
//GfxGradientRect(0,0,pxwidth, pxheight, C11, C12 );
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxTextOut( "SAM-JN V1.0", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxTextOut( "TraderAdda.Com", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);
GfxSelectFont("Ariel",9, 700, False, False, 0);
GfxSetTextColor(colorYellow);
//axisarea = 56; // may need adjustment if you are using non-default font for axis


_SECTION_BEGIN(" J10SARbySAM ");
TimeFrameSet( inDaily   );
FS=Param("Font Size",20,11,100,1);
GfxSelectFont("Arial", FS, 700, True ); 
GfxSetBkMode( colorWhite );  
GfxSetTextColor( ParamColor("Color",colorYellow) ); 
Hor=Param("Horizontal Position",373,1,1200,1);
Ver=Param("Vertical Position",16,1,830,1); 
//SAR1=Prec((C+YC+DFYC+DFYC1+DFYC2)/5,5);
SAR1=EMA( Close, 10 );
GfxTextOut("J10SAR="+SAR1, Hor , Ver );
TimeFrameRestore();

_SECTION_END();

_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",30,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True ); 
GfxSetBkMode( colorWhite );  
GfxSetTextColor( ParamColor("Color",colorLightOrange) ); 
Hor=Param("Horizontal Position",373,1,1200,1);
Ver=Param("Vertical Position",45,1,830,1); 
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 11, 700, True ); 
GfxSetBkMode( colorWhite );  
GfxSetTextColor(ParamColor("Color",colorBlack) ); 
GfxTextOut(""+DD+"  ("+xx+"%)", Hor , Ver+45 );

_SECTION_END();

_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator ) 
(
Title = EncodeColor(colorWhite)+ "SAM(TraderAdda.Com)JN AFL V1.0 " + " - " +  Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
 "  - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+"  "+"Hi-"+H+"  "+"Lo-"+L+"  "+
"Cl-"+C+"  "+ "Vol= "+ WriteVal(V)+"\n"+ 
EncodeColor(colorLime));
//WriteIf (Buy , " GO LONG / Reverse Signal at "+C+"  ","")+
//WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+"  ","")+"\n"+EncodeColor(colorWhite)+
//WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
//WriteIf(Buy  , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","")+
//WriteIf(Long AND NOT Buy, "Trade : Long - Entry price Rs."+(BuyPrice),"")+
//WriteIf(shrt AND NOT Sell, "Trade : Short - Entry price Rs."+(SellPrice),"")+"\n"+ 
//WriteIf(Long AND NOT Buy, "Current Profit/Loss Rs."+(C-BuyPrice)+"","")+
//WriteIf(shrt AND NOT Sell, "Current Profit/Loss Rs."+(SellPrice-C)+"",""));
_SECTION_END();

_SECTION_BEGIN("Price1");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", ParamColor("Color", colorRed ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();
//_SECTION_BEGIN("Pivot")
	YH = TimeFrameGetPrice("H", inDaily, -1);		// yesterdays high
	YL = TimeFrameGetPrice("L", inDaily, -1);		//				low
	YC = TimeFrameGetPrice("C", inDaily, -1);		//				close
	YO = TimeFrameGetPrice("O", inDaily);			// current day open

	//Normal Pivot
	PP = (YH + YL + YC) / 3;
	R1 = (2 * PP) - YL;
	R2 = PP + (YH - YL);
	R3 = YH + 2*(PP-YL);
	S1 = (2 * PP) - YH;
	S2 = PP - (YH - YL);
	S3 = YL - 2*(YH - PP) ;


GfxSetOverlayMode( mode = 0 );  
GfxSelectPen( colorYellow, 3 );  
GfxSelectSolidBrush( colorBlack  );  
GfxRoundRect( 20, 72, 117, 205, 100, 25 );  
GfxSetBkMode(1);  
GfxSelectFont( "Arial", 10, 900, False ); 
GfxSetTextColor( colorWhite  ); 
GfxSetTextAlign(0); 
GfxTextOut( WriteIf(YH, "D.Piv.: "+(PP),""), 25, 85);
GfxSetTextColor( colorRed  ); 
GfxTextOut( WriteIf(R1, "R1: "+(R1),""), 30, 105); 
GfxTextOut( WriteIf(R2, "R2: "+(R2),""), 30, 120); 
GfxTextOut( WriteIf(R3, "R3: "+(R3),""), 30, 135); 
GfxSetTextColor( colorLime   );  
GfxTextOut( WriteIf(S1, "S1: "+(S1),""), 30, 150); 
GfxTextOut( WriteIf(S2, "S2: "+(S2),""), 30, 165); 
GfxTextOut( WriteIf(S3, "S3: "+(S3),""), 30, 180); 

	WYH = TimeFrameGetPrice("H", inWeekly, -1);		
	WYL = TimeFrameGetPrice("L", inWeekly, -1);		
	WYC = TimeFrameGetPrice("C", inWeekly, -1);		
	WYO = TimeFrameGetPrice("O", inWeekly);			

	//Week Pivot
	WPP = (WYH + WYL + WYC) / 3;
	WR1 = (2 * WPP) - WYL;
	WR2 = WPP + (WYH - WYL);
	WR3 = WYH + 2*(WPP-WYL);
	WS1 = (2 * WPP) - WYH;
	WS2 = WPP - (WYH - WYL);
	WS3 = WYL - 2*(WYH - WPP) ;



GfxSetOverlayMode( mode = 0 );  
GfxSelectPen( colorYellow, 3 );  
GfxSelectSolidBrush( colorBlack  );  
GfxRoundRect( 130, 72, 232, 205, 100, 25 );
GfxSetBkMode(1);  
GfxSelectFont( "Arial", 10, 900, False ); 
GfxSetTextColor( colorWhite  ); 
GfxSetTextAlign(0); 
 
GfxTextOut( WriteIf(YH, "W.Piv.: "+(WPP),""), 135, 85);
GfxSetTextColor( colorRed  ); 
GfxTextOut( WriteIf(R1, "R1: "+(WR1),""), 140, 105); 
GfxTextOut( WriteIf(R2, "R2: "+(WR2),""), 140, 120); 
GfxTextOut( WriteIf(R3, "R3: "+(WR3),""), 140, 135); 
GfxSetTextColor( colorLime   );  

GfxTextOut( WriteIf(S1, "S1: "+(WS1),""), 140, 150); 
GfxTextOut( WriteIf(S2, "S2: "+(WS2),""), 140, 165); 
GfxTextOut( WriteIf(S3, "S3: "+(WS3),""), 140, 180);  



GfxSetOverlayMode( mode = 0 );  
GfxSelectPen( colorYellow, 3 );  
GfxSelectSolidBrush( colorBlack  );  
GfxRoundRect( 20, 480, 160, 230, 100, 25 );  
GfxSetBkMode(1);  
GfxSelectFont( "Arial", 10, 900, False ); 
GfxSetTextColor( colorWhite  ); 
GfxSetTextAlign(0); 


TimeFrameSet( inDaily   );
EMADH = EMA(H,   5);
TimeFrameExpand( EMADH , inDaily ); 
EMADL = EMA(L,   5);
TimeFrameExpand( EMADL , inDaily );
EMADC = EMA(C,   5);
TimeFrameExpand( EMADC , inDaily );
TimeFrameRestore();


TimeFrameSet( inHourly   );
EMAHH = EMA(H,   5);
TimeFrameExpand( EMAHH , inHourly ); 
EMAHL = EMA(L,   5);
TimeFrameExpand( EMAHL , inHourly );
EMAHC = EMA(C,   5);
TimeFrameExpand( EMAHC , inHourly );
TimeFrameRestore();


GfxSetTextColor( colorRed);
GfxTextOut( WriteIf(S3 , "Hour High : "+EMAHH,""), 30, 250); 
GfxSetTextColor( colorGreen );
GfxTextOut( WriteIf(S3 , "Hour Low: "+EMAHL,""), 30, 270);
GfxSetTextColor( colorWhite );
GfxTextOut( WriteIf(S3 , "Hour Close: "+EMAHC,""), 30, 290);


GfxSetTextColor( colorRed);
GfxTextOut( WriteIf(S3 , "Day High : "+EMADH,""), 30, 320); 
GfxSetTextColor( colorGreen );
GfxTextOut( WriteIf(S3 , "Day Low : "+EMADL,""), 30, 340);
GfxSetTextColor( colorWhite );
GfxTextOut( WriteIf(S3 , "Day Close : "+EMADc,""), 30, 360);

TimeFrameSet( inWeekly );
WEEKH = EMA(H,   5);
TimeFrameExpand( WEEKH , inWeekly ); 
WEEKL = EMA(L,   5);
TimeFrameExpand( WEEKL , inWeekly );
WEEKC = EMA(C,   5);
TimeFrameExpand( WEEKC , inWeekly );
TimeFrameRestore();

GfxSetTextColor( colorRed);
GfxTextOut( WriteIf(S3 , "Week High : "+WEEKH ,""), 30, 390); 
GfxSetTextColor( colorGreen );
GfxTextOut( WriteIf(S3 , "Week Low : "+WEEKL ,""), 30, 410);
GfxSetTextColor( colorWhite );
GfxTextOut( WriteIf(S3 , "Week Clo. : "+WEEKC ,""), 30, 430);

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

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

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

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