{ Downloaded From https://www.WiseStockTrader.com }
* Fibonacci Internal & External Retracements */
// This is a Modified Version that shows Fibonacci 00% & 100% instead of WRONG Sup & Res

_SECTION_BEGIN("Background");
	SetChartOptions(0,chartShowArrows|chartShowDates);
	SetChartBkColor(ParamColor("Outer panel",colorTan)); // color of outer border 
	SetChartBkGradientFill( ParamColor("Inner panel upper",colorBlack),ParamColor("Inner panel lower",colorBlack));
	tchoice=Param("Title Selection ",2,1,2,1);

Plot(C, "", IIf(O>=C, colorRed, colorGreen), ParamStyle("Price Style",styleCandle,maskPrice));
//////////////////////////////////////////////////////////////////
_SECTION_BEGIN("Fib Retracements");
	fibs = ParamToggle("Plot Fibs","Off|On",1);
	pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
	HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
	pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
	LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
	Back = Param ("Extend Left = 2",1,1,500,1);
	Fwd  = Param("Plot Forward", 0, 0, 500, 1);
	text = ParamToggle("Plot Text","Off|On",1);
	hts  = Param ("Text Shift", -33.5,-50,50,0.10);
	style =ParamStyle("Line Style",styleLine,styleNoLabel);
x = BarIndex();
pRp  = PeakBars( H, pctH, 1) == 0;
yRp0 = SelectedValue(ValueWhen( pRp, H, HiLB));
xRp0 = SelectedValue(ValueWhen( pRp, x, HiLB));
pSp  = TroughBars( L, pctL, 1) == 0;
ySp0 = SelectedValue(ValueWhen( pSp, L, LoLB));
xSp0 = SelectedValue(ValueWhen( pSp, x, LoLB));
Delta = yRp0 - ySp0;

function fib(ret)
{
retval = (Delta * ret);
Fibval = IIf(ret < 1.0 
AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0 
AND xSp0 > xRp0, ySp0 + retval,IIf(ret > 1.0 
AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0 
AND xSp0 > xRp0, ySp0 + retval, Null)))); 
return FibVal;
}

x0 = Min(xSp0,xRp0)-Back;
x1 = (BarCount -1);
//////////////////////////////////////////////////////////////////
r236 = fib(0.236);	r236I = LastValue (r236,1);
r382 = fib(0.382);	r382I = LastValue (r382,1);
r050 = fib(0.50);		r050I = LastValue (r050,1);
r618 = fib(0.618);	r618I = LastValue (r618,1);
r786 = fib(0.786);	r786I = LastValue (r786,1);
e127 = fib(1.27);		e127I = LastValue (e127,1);
e162 = fib(1.62);		e162I = LastValue (e162,1);
e200 = fib(2.00);		e200I = LastValue (e200,1);
e262 = fib(2.62);		e262I = LastValue (e262,1);
e424 = fib(4.24);		e424I = LastValue (e424,1);
//////////////////////////////////////////////////////////////////
p00 = IIf(xSp0 > xRp0,ySp0,yRp0); 	p00I = LastValue (p00,1);
p100 = IIf(xSp0 < xRp0,ySp0,yRp0); 	p100I = LastValue (p100,1);
color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
color100 =IIf(xSp0 < xRp0,colorLime,colorRed);
//////////////////////////////////////////////////////////////////
numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
//////////////////////////////////////////////////////////////////
if(fibs==1)
{
Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,8|styleNoRescale,Null,
Null,Fwd);
Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27,8|styleNoRescale,Null,
Null,Fwd);
Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",45,style|styleNoRescale,Null,
Null,Fwd);
Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",44,style|styleNoRescale,Null,
Null,Fwd);
Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",41,style|styleNoRescale,Null,
Null,Fwd);
Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",43,style|styleNoRescale,Null,
Null,Fwd);
Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",42,style|styleNoRescale,Null,
Null,Fwd);
Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",47,style|styleNoRescale,Null,
Null,Fwd);
Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",47,style|styleNoRescale,Null,
Null,Fwd);
Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",47,style|styleNoRescale,Null,
Null,Fwd);
Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",47,style|styleNoRescale,Null,
Null,Fwd);
Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",25,style|styleNoRescale,Null,
Null,Fwd);
}
//////////////////////////////////////////////////////////////////
if(text==1)
{ 
PlotText(" 0% = " + WriteVal(p00,fraction),
	LastValue(BarIndex())-(numbars/hts), p00I  + 0.05, color00);
PlotText("23% = " + WriteVal(r236,fraction),
LastValue(BarIndex())-(numbars/hts), r236I + 0.05, 45);
PlotText("38% = " + WriteVal(r382,fraction),
LastValue(BarIndex())-(numbars/hts), r382I + 0.05, 44);
PlotText("50% = " + WriteVal(r050,fraction),
LastValue(BarIndex())-(numbars/hts), r050I + 0.05, 41);
PlotText("62% = " + WriteVal(r618,fraction),
LastValue(BarIndex())-(numbars/hts), r618I + 0.05, 43);
PlotText("78% = " + WriteVal(r786,fraction),
LastValue(BarIndex())-(numbars/hts), r786I + 0.05, 42);
PlotText("100% = " + WriteVal(p100,fraction),
LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
PlotText("127% = " + WriteVal(e127,fraction),
LastValue(BarIndex())-(numbars/hts),e127I + 0.05, 47);
PlotText("162% = " + WriteVal(e162,fraction),
LastValue(BarIndex())-(numbars/hts),e162I + 0.05, 47);
PlotText("200% = " + WriteVal(e200,fraction),
LastValue(BarIndex())-(numbars/hts),e200I + 0.05, 47);
PlotText("262% = " + WriteVal(e262,fraction),
LastValue(BarIndex())-(numbars/hts),e262I + 0.05, 47);
PlotText("424% = " + WriteVal(e424,fraction),
LastValue(BarIndex())-(numbars/hts),e424I + 0.05, 25);
}
_SECTION_END();
//////////////////////////////////////////////////////////////////
if (tchoice==1 ) 
{
_N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} -   {{INTERVAL}}     
{{Date}}    Open:  %g,    High:  %g,     Low:  %g,     Close:  %g    
{{VALUES}}",O, H, L, C, SelectedValue( ROC( C, 1   ) ) ));
}
//////////////////////////////////////////////////////////////////
if (tchoice==2 ) 
{
Title = EncodeColor(colorYellow) + "Fibonacci Internal & External Retracements  " +  EncodeColor(colorWhite) + Name() + "  " + EncodeColor(colorWhite)+  Date() + "   Tick = " + EncodeColor(5) +
Interval()+
EncodeColor(colorWhite) + "     Open = " + EncodeColor(colorWhite) + O + 
EncodeColor(colorWhite) + "     High = " + EncodeColor(5) + H +
EncodeColor(colorWhite) + "      Low = " + EncodeColor(colorRed) + L + 
EncodeColor(colorWhite) + "     Close = " + EncodeColor(colorWhite) + C + "\n"
+
EncodeColor( colorWhite) +"_______________"+"\n"+
EncodeColor( colorWhite)  + "424%   =  "	+ 	EncodeColor(25)+ e424 + " " +"\n"+
EncodeColor( colorWhite)  + "262%   =  "	+ 	EncodeColor(47)+ e262 + " " +"\n"+
EncodeColor( colorWhite)  + "200%   =  "	+ 	EncodeColor(47)+ e200 + " " +"\n"+
EncodeColor( colorWhite)  + "162%   =  "	+ 	EncodeColor(47)+ e162 + " " +"\n"+
EncodeColor( colorWhite)  + "127%   =  "	+ 	EncodeColor(47)+ e127 + " " +"\n"+
EncodeColor( Color100)  + "100%   =  "	+ EncodeColor(Color100) + p100 + " "+"\n"+
EncodeColor( colorWhite)  + "78.6%  =  "	+	EncodeColor(42)+ r786 + " " +"\n"+
EncodeColor( colorWhite)  + "61.8%  =  "	+ 	EncodeColor(43)+ r618 + " "+"\n"+
EncodeColor( colorWhite)  + "50%     =  "	+ 	EncodeColor(41)+ r050 + " "+"\n"+
EncodeColor( colorWhite)  + "38.2%  =  "	+ 	EncodeColor(44)+ r382 + " "+"\n"+
EncodeColor( colorWhite)  + "23.6%  =  "	+ 	EncodeColor(45)+ r236+ " " +"\n"+
EncodeColor( Color00)  + "00%    =  " + 	EncodeColor(Color00) + p00 + " " ;
}
GraphXSpace=5;

////////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("MOB simulation shiree"); 
  
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", colorPink ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );  
PlotOHLC(O,H,L,C,"Price",IIf(C>O,colorGreen,colorRed),styleCandle); 
  
  
//Date: 12-January 2002 by Thomas Zmuck 
//thomas.zm@ aon.at 
Offset = 5; //use two sheets: one with 5 and another with 7, or maybe other offset value 
Avgmov = Offset*MA(abs( ROC(C,1)) ,20); 
per = LastValue(Avgmov) ;  
x=Cum(1);  
Range = 0.01; 
PS = TroughBars(L, per,1) == 0; 
xa = LastValue(ValueWhen (PS,x,1)) ;//x from last trough 
Ya = LastValue(ValueWhen (PS,L,1)) ;//y (Low) last trough 
PR = PeakBars(H,per, 1) == 0; 
xb = LastValue(ValueWhen (PR,x,1)) ;//x from last peak 
Yb = LastValue(ValueWhen (PR,H,1)) ;//y (High) last peak 
Trough_ReTest = abs((L/ya)-1) <Range; 
Peak_ReTest = abs((H/yb)-1) <Range; 
Trough_Cross = Cross(ya,C); 
Peak_Cross = Cross(C,yb); 
//UP = upSwing DN = downSwing 
UP = xb>xa;//upSwing 
DN = xa>xb;//DownSwing 
RT23_6 = IIf(UP,yb-(yb- ya)*0.236, IIf(DN,ya+ (yb-ya)*0.236,-1e10) ); 
RT38_2 = IIf(UP,yb-(yb- ya)*0.382, IIf(DN,ya+ (yb-ya)*0.382,-1e10) ); 
RT50_0 = IIf(UP,yb-(yb- ya)*0.500, IIf(DN,ya+ (yb-ya)*0.500,-1e10) ); 
RT61_8 = IIf(UP,yb-(yb- ya)*0.618, IIf(DN,ya+ (yb-ya)*0.618,-1e10) ); 
RT78_6 = IIf(UP,yb-(yb- ya)*0.786, IIf(DN,ya+ (yb-ya)*0.786,-1e10) ); 
  
RT12_7 = IIf(UP,yb-(yb- ya)*1.27, IIf(DN,ya+ (yb-ya)*1.27,-1e10) ); 
RT16_1 = IIf(UP,yb-(yb- ya)*1.61, IIf(DN,ya+ (yb-ya)*1.61,-1e10) ); 
  
RT=  
IIf(UP,-100* (yb-L)/(yb- ya), 
100*(H-ya)/( yb-ya));//Retracement_ Value 
InZone = C<yb & C>ya;//use it for filter to receive only signals that are in in the Retracement zone. 
Buy = Trough_ReTest OR peak_Cross; 
Sell = Peak_ReTest OR trough_Cross; 
Filter = 1; 
AddColumn(RT, "RT%"); 
AddColumn(Trough_ReTest,"TR- Test",1.0) ; 
AddColumn(Peak_ReTest,"PK-Test",1.0) ; 
AddColumn(Trough_Cross,"TR-Cross",1.0); 
AddColumn(Peak_Cross,"PK-Cross",1.0); 
//AddColumn(CdDoji( )OR CHammer(),"Candle" ,1.0); 
Plot(C,"C",1, 64); 
Plot(IIf(x>xa, ya,-1e10) ,"Bottom" ,colorBrown, 1+8); 
Plot(IIf(x>xb, yb,-1e10) ,"Top",colorBrown,1+8); 
xab = IIf(xb>xa,xb, xa); 
//Retracements 
Plot(IIf(x>= xab+1,RT23_6,-1e10), "23,6% Retr.",5,1); 
Plot(IIf(x>= xab+1,RT38_2,-1e10), "38,2% Retr.",5,1); 
Plot(IIf(x>= xab+1,RT50_0,-1e10), "50,0% Retr.",colorBlue, 1); 
Plot(IIf(x>= xab+1,RT61_8,-1e10), "61,8% Retr.",colorYellow, 1); 
Plot(IIf(x>= xab+1,RT78_6,-1e10), "78,6% Retr.",colorYellow, 1); 
  
Plot(IIf(x>= xab+1,RT12_7,-1e10), "127% ext.",colorBrightGreen, styleDots); 
Plot(IIf(x>= xab+1,RT16_1,-1e10), "161% ext.",colorBrightGreen, styleDots); 
CondA=IIf(x>= xab+1,RT12_7,-1e10); 
CondB=IIf(x>= xab+1,RT16_1,-1e10); 
PlotOHLC(Condb,Condb,Conda,Conda,"",ColorRGB(30,130,30),styleCloud,styleNoLabel); 
  
  
GraphXSpace = 0.5; 
  
  
  
  
//Plot(Gauss2ord(C,5),"M5",4,1); 
//GraphXSpace = 1.5; 
//Title = Name()+" per = "+WriteVal(per, 1.0) +" Close = "+WriteVal(C, 1.2)+ " ("+WriteVal( ROC(C,1), 1.2)+"%)" +" Current Correction = "+WriteVal(RT, 1.0)+"%"; 
  
//Plot( Volume,"V", ParamColor("Color", colorBlueGrey ), ParamStyle( "Style", stylehidden| styleOwnScale | styleThick, maskHistogram  ), 2 ); 
  
  
_SECTION_END( );



//---- Ramesh.S.R
HaClose = (O+H+L+C)/4; 
HaOpen = AMA( Ref( HaClose, -1 ), .40); 
HaHigh = Max( H, Max( HaClose, HaOpen ) ); 
HaLow = Min( L, Min( HaClose, HaOpen ) ); 
xDiff = (HaHigh - Halow) * IIf(StrFind(Name(),"JPY"),100,10000);
barcolor = IIf(HaClose >= HaOpen,colorGreen,colorRed);
// ****PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", barcolor, styleCandle ); 
// Plot(EMA(HaClose,9),"",colorWhite, styleLine);
// Plot(EMA(HaClose,18),"",colorBlack, styleLine);




_SECTION_BEGIN("Ramesh Swing1");
no=Param( "Swing", 10, 1, 55 );
tsl_col=ParamColor( "Color", colorDarkRed );

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

// line code
Plot(tsl, _DEFAULT_NAME(), colorDarkRed, styleStaircase); 

// ribbon code
//  Plot( 2, "Ribbon",IIf(C>tsl,colorBlue,colorRed),styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

// arrows code
Buy=Cross(C,Ref(res,-1));
Sell=Cross(Ref(sup,-1),C);
shape=Buy*shapeUpArrow + Sell*shapeDownArrow;
PlotShapes(shape,colorBlack,0,IIf(Buy,Low,High));

// scanner code
Buy=Cross(C,tsl);
Sell=Cross(tsl,C);

_SECTION_END();



_SECTION_BEGIN("Ramesh Swing2");
no=Param( "Swing", 20, 1, 55 );
tsl_col=ParamColor( "Color", colorBlue );

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

Plot(tsl, _DEFAULT_NAME(), tsl_col, styleStaircase); // or styleaArea

Buy=Cross(C,tsl);
Sell=Cross(tsl,C);
shape=Buy*shapeUpArrow + Sell*shapeDownArrow;
PlotShapes(shape,IIf(Buy,tsl_col,tsl_col),0,IIf(Buy,Low,High));
_SECTION_END();




_SECTION_BEGIN("Ramesh Swing3");
no=Param( "Swing", 30, 1, 55 );
tsl_col=ParamColor( "Color", colorGreen );

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

Plot(tsl, _DEFAULT_NAME(), tsl_col, styleStaircase); // or styleaArea

Buy=Cross(C,tsl);
Sell=Cross(tsl,C);
shape=Buy*shapeUpArrow + Sell*shapeDownArrow;
PlotShapes(shape,IIf(Buy,tsl_col,tsl_col),0,IIf(Buy,Low,High));
_SECTION_END();




_SECTION_BEGIN("Time Left");

function GetSecondNum()

{

Time = Now( 4 );

Seconds = int( Time % 100 );

Minutes = int( Time / 100 % 100 );

Hours = int( Time / 10000 % 100 );

SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );

return SecondNum;

}

RequestTimedRefresh( 1 );

TimeFrame = Interval();

SecNumber = GetSecondNum();

Newperiod = SecNumber % TimeFrame == 0;

SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;

SecsToGo = TimeFrame - SecsLeft;

 

x=Param("xposn",300,0,1000,1);

y=Param("yposn",50,0,1000,1);

 

GfxSelectSolidBrush( ColorRGB( 230, 230, 230 ) );

GfxSelectPen( ColorRGB( 230, 230, 230 ), 2 );

if ( NewPeriod )

{

GfxSelectSolidBrush( colorYellow );

GfxSelectPen( colorYellow, 2 );

Say( "New period" );

}

GfxRoundRect( x+45, y+17, x-3, y-2, 0, 0 );

GfxSetBkMode(1);

GfxSelectFont( "Arial", 12, 700, False );

GfxSetTextColor( colorBlack );

GfxTextOut( ""+SecsToGo+" / "+NumToStr( TimeFrame, 1.0 ), x, y );

_SECTION_END();

_SECTION_BEGIN("Price2");
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("Pop-Up");


//  function GetSecondNum()
{
    Time = Now( 4 );
    Seconds = int( Time % 100 );
    Minutes = int( Time / 100 % 100 );
    Hours = int( Time / 10000 % 100 );
    SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
//    return SecondNum;
}
 
function PopupWindowEx( popupID, bodytext, captiontext, timeout, left, top )
{
    displayText = bodytext + captiontext;
    if ( ( StaticVarGetText( "prevPopup" + popupID ) != displayText) OR ( StaticVarGet( "prevPopupTime" + popupID ) < GetSecondNum() ) )
    {
        StaticVarSetText( "prevPopup" + popupID, displayText);
        StaticVarSet( "prevPopupTime" + popupID, GetSecondNum() + timeout );
        PopupWindow( bodytext, Captiontext + popupID, timeout, Left, top );
    }
}
 
//PopupWindowEx( "ID:1", "BUY", "test alert ", 5, -1, -1 );
//PopupWindowEx( "ID:2", "testing", "test alert ", 5, 0, 0 );


_SECTION_END();