NF Swing Trading using Fractal AFL

vikas2131

Well-Known Member
KPLswing

Code:
_SECTION_BEGIN("Trend Identifire"); 
Show_color = ParamToggle("Display CandleColor", "No|Yes", 1); 
r1 = Param( "ColorFast avg", 5, 2, 200, 1 ); 
r2 = Param( "ColorSlow avg", 10, 2, 200, 1 ); 
r3 = Param( "ColorSignal avg", 5, 2, 200, 1 ); 

Prd1=Param("ATR Period",4,1,20,1); 
Prd2=Param("Look Back",7,1,20,1); 
green = HHV(LLV(L,Prd1)+ATR(Prd1),Prd2); 
red = LLV(HHV(H,Prd1)-ATR(Prd1),Prd2); 
flowerClose = EMA((Open+High+Low+Close)/4,3) ; 
flowerOpen = EMA((Ref(Open,-1) + Ref(flowerClose,-1))/2,3); 
Temp = Max(High, flowerOpen); 
flowerHigh = EMA(Max(Temp, flowerClose),3); 
Temp = Min(Low,flowerOpen); 
flowerLow = EMA(Min(Temp, flowerClose),3); 

SetPositionSize (1, spsShares);

m1=MACD(r1,r2); 
s1=Signal(r1,r2,r3); 
mycolor=IIf(m1<0 AND m1>s1, colorBlue,IIf(m1>0 AND 

m1>s1,colorGreen,IIf(m1>0 AND m1<s1,colorPink,colorRed))); 
if(Show_color) 
{ 
ColorHighliter = myColor; 
SetBarFillColor( ColorHighliter ); 
} 

barColor=IIf(C>Green ,colorWhite,IIf(C < RED,colorRed,colorWhite)); 


PlotOHLC( IIf(flowerOpen<flowerClose, flowerOpen, 

flowerClose),flowerHigh,flowerLow,IIf(flowerOpen<f lowerClose, flowerClose, 

flowerOpen), "Close", barColor, styleNoTitle | styleCandle); 

_SECTION_END(); 







_SECTION_BEGIN("Bands"); 

SupResB =Param("Sup-Res Short",6,0,100,1); 
nn=SupResB; 



Bandlinecol=ParamColor("SupResLineColor",ColorRGB( 82,82,82)); 
ParmCloud = ParamToggle("Cloud", "No|Yes", 0); 
BoxCloudColor=ParamColor("BoxCloudColor",ColorRGB( 27,27,27)); 


Line2=Param("ResLineLength",100,2,500,0.1); 
Daysback1 = Line2; 
FirstBar1 = BarCount - DaysBack1; 
Hh=HHV(flowerHigh,nn); 
LL=LLV(flowerLow,nn); 

Res2=Hh; 
Sup2=LL; 

BandRes=IIf(BarIndex() >= Firstbar1,EndValue(Res2),Null); 
BandSup=IIf(BarIndex() >= Firstbar1,EndValue(Sup2),Null); 
Plot(BandRes,"",Bandlinecol,ParamStyle("ShortSupBa nd",styleLine|styleDashed|stylehidden|styleNoTitle |styleNoLabel|styleThick,maskAll)); 
Plot(BandSup,"",Bandlinecol,ParamStyle("ShortResBa nd",styleLine|styleDashed|stylehidden|styleNoTitle |styleNoLabel|styleThick,maskAll)); 




CS=BandRes; 
CR=BandSup; 


if(parmCloud == 1) 

PlotOHLC( CS, CS, CR,CR, "Band",BoxCloudColor, styleCloud | styleNoLabel|styleNoTitle); 

_SECTION_END(); 

_SECTION_BEGIN("Breakout"); 
Buyperiods=Param("Breakout periods best is usually 18",5,1,100,1,1); 
Sellperiods=Param("Exit Breakout",5,1,100,1,1); 

HaClose =EMA((O+H+L+C)/4,3); // Woodie 
//HaClose =(O+H+L+C)/4; 
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); 
HaHigh = Max( H, Max( HaClose, HaOpen ) ); 
HaLow = Min( L, Min( HaClose, HaOpen ) ); 
Buy= C>Ref(HHV(High,Buyperiods),-1) ; 
Sell= C<Ref(LLV(Low,Sellperiods),-1); 

/* exrem is one method to remove surplus strade signals. It removes excessive signals of arrow */ 
Buy = ExRem(Buy, Sell); 
Sell = ExRem(Sell, Buy); 

PlotShapes( IIf( Buy, shapeUpTriangle, shapeNone ), colorGreen, layer = 0,yposition = HaLow, offset = -30); 
//PlotShapes( IIf( Buy, shapeSmallCircle, shapeNone ), colorWhite, layer = 0,yposition = HaLow, offset = -8); 

PlotShapes( IIf( Sell, shapeDownTriangle, shapeNone ), colorRed, layer = 0, yposition = HaHigh, offset = -30); 
//PlotShapes( IIf( Sell, shapeSmallCircle, shapeNone ), colorRed, layer = 0, yposition = HaHigh, offset = -8); 

_SECTION_END(); 


_SECTION_BEGIN("PFE"); 

pds=10; 
x=sqrt((ROC(C,9)*ROC(C,9))+100); 
y=Sum(sqrt((ROC(C,1)* ROC(C,1))+1),pds); 
z=(x/y); 
pfe=EMA(IIf(C>Ref(C,-9),z,-z)*100,5); 

rsidn=pfe <-10 AND pfe<Ref(pfe,-1); 
rsiup=pfe >10 AND pfe>Ref(pfe,-1); 



rsiresult1 = WriteIf( rsiup,"cu", ""); 
rsiresult2 = WriteIf( rsidn,"cd", ""); 




RequestTimedRefresh( 0 ); 
GfxSelectFont( "Tahoma", 12, 120 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorWhite ); 

if ( rsiresult1 =="cu") 
{ 
GfxSelectSolidBrush( ColorRGB(0,90,0) ); 

} 
else 

if ( rsiresult2 =="cd") 

{ 
GfxSelectSolidBrush( ColorRGB(90,0,0)); 

} 

else 

if ( rsiresult2 =="") 

{ 
GfxSelectSolidBrush( colorDarkTeal ); 

} 

GfxSelectFont( "Arial", 10, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorBlue ); 




_SECTION_END(); 





GfxRoundRect( 400,570,210,415, 50, 50 ); 

_SECTION_END(); 




_SECTION_BEGIN("Schaff Trend Cycle"); 
MA1=23; 
MA2=50; 
TCLen=10; 
MA1=Param("ShortMACDLen",23,5,36); 
MA2=Param("LOngMACDLen",50,10,100); 
TCLen=Param("TCLen(StochPeriod)",10,5,20); 
Factor=.5; 

XMac = MACD(MA1,MA2) ; 

Value1 = LLV(XMac, TCLen); 
Value2 = HHV(XMac, TCLen) - Value1; 

frac1=0; 
for (i = 1; i < BarCount; i++) { 
if (Value2[i] > 0) { 
frac1[i] = ((XMac[i] - Value1[i])/Value2[i])*100; 
} 
else { 
frac1[i]= frac1[i-1]; 
} 
} 


PF[0]=frac1[0]; 
PF[1]=frac1[1]; 
for (i = 2; i < BarCount; i++) { 
PF[i]=PF[i-1]+(Factor*(frac1[i]-PF[i-1])); 
} 


Value3 = LLV(PF, TCLen); 
Value4 = HHV(PF, TCLen) - Value3; 

frac2[0]=0; 
for (i = 1; i < BarCount; i++) { 
if (Value4[i] > 0 ) { 
frac2[i]=((PF[i] - Value3[i])/Value4[i])*100; 
} 
else { 
frac2[i]=frac2[i-1]; 
} 
} 

PFF[0]=frac2[0]; 
PFF[1]=frac2[1]; 
for (i = 2; i < BarCount; i++) { 
PFF[i]=PFF[i-1]+(Factor*(frac2[i]-PFF[i-1])); 
} 


rsidn=pff <2; 
rsiup=pff >98; 


rsiresult1 = WriteIf( rsiup,"cu", ""); 
rsiresult2 = WriteIf( rsidn,"cd", ""); 




RequestTimedRefresh( 0 ); 
GfxSelectFont( "Tahoma", 12, 120 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorWhite ); 

if ( rsiresult1 =="cu") 
{ 
GfxSelectSolidBrush( ColorRGB(0,120,0) ); 

} 
else 

if ( rsiresult2 =="cd") 

{ 
GfxSelectSolidBrush( ColorRGB(120,0,0)); 

} 

else 

if ( rsiresult2 =="") 

{ 
GfxSelectSolidBrush( colorDarkTeal ); 

} 

GfxSelectFont( "Arial", 10, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorBlue ); 
GfxRoundRect( 390,560,220,425, 50, 50 ); 

_SECTION_END(); 


_SECTION_BEGIN("rsi"); 

//HT=ParamColor("HT", colorRed ); 

rsidn=RSI(7) <30; 
rsiup=RSI(7) >70; 


rsiresult1 = WriteIf( rsiup,"cu", ""); 
rsiresult2 = WriteIf( rsidn,"cd", ""); 




RequestTimedRefresh( 0 ); 
GfxSelectFont( "Tahoma", 12, 120 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorWhite ); 

if ( rsiresult1 =="cu") 
{ 
GfxSelectSolidBrush( ColorRGB(0,150,0) ); 

} 
else 

if ( rsiresult2 =="cd") 

{ 
GfxSelectSolidBrush( ColorRGB(150,0,0)); 

} 

else 

if ( rsiresult2 =="") 

{ 
GfxSelectSolidBrush( colorDarkTeal ); 

} 

GfxSelectFont( "Arial", 10, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorBlue ); 

GfxRoundRect( 380,550,230,435, 50, 50 ); 

_SECTION_END(); 








_SECTION_BEGIN("Rays"); 


Pp1=3; 
Pp2=2; 

CS33=HHV(LLV(flowerHigh,Pp1)-ATR(Pp2),4); 
CR33=HHV(LLV(flowerHigh,Pp1)-ATR(Pp2),5); 

AtrupTrendCond1 = flowerClose> CS33 ; 
AtrdnTrendCond1 =CS33>flowerClose ; 


ATRup = WriteIf(AtrupTrendCond1,"atrup", ""); 
ATRdown= WriteIf( AtrdnTrendCond1,"atrdn", ""); 

if ( ATRup =="atrup") 
{ 
GfxSelectSolidBrush( ColorRGB(0,180,0) ); 

} 
else 

if (ATRdown =="atrdn") 

{ 
GfxSelectSolidBrush( ColorRGB(180,0,0)); 

} 

else 

if ( ATRdown =="") 

{ 
GfxSelectSolidBrush( colorDarkTeal ); 

} 

GfxSelectFont( "Arial", 10, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorBlue ); 

GfxSelectPen( colorBlue, 1 ); // broader color 
GfxRoundRect( 370,540,240,445, 50, 50 ); 




_SECTION_END(); 


_SECTION_BEGIN("Exit_Beast-3"); 



EntrylookbackPeriod=10; 
EntryATRperiod=1.9; 
EntrySig = C > ( LLV( flowerLow, EntrylookbackPeriod ) + EntryATRperiod * ATR( 10 ) ); 
ExitSig = C < ( HHV( flowerHigh, EntrylookbackPeriod ) -EntryATRperiod * ATR( 10 ) ); 


RequestTimedRefresh( 0 ); 
GfxSelectFont( "Tahoma", 12, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorWhite ); 

EntryB = WriteIf( EntrySig,"eu", ""); 
ExitB = WriteIf( ExitSig,"ed", ""); 

if ( EntryB =="eu") 
{ 
GfxSelectSolidBrush( ColorRGB(0,210,0) ); // 

} 
else 

if ( ExitB =="ed") 

{ 
GfxSelectSolidBrush( ColorRGB(210,0,0)); // 

} 

else 

if ( ExitB =="") 

{ 
GfxSelectSolidBrush( colorDarkTeal ); 

} 

GfxSelectFont( "Arial", 10, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorBlue ); 

GfxSelectPen( colorBlue, 1 ); // broader color 
GfxRoundRect( 360,530,250,455, 50, 50 ); 



_SECTION_END(); 



_SECTION_BEGIN("CCI9-2"); 


ccidn=CCI(8) < 0; 
cciup=CCI(9) > 0; 


ccresult1 = WriteIf( cciup,"cu", ""); 
ccresult2 = WriteIf( ccidn,"cd", ""); 




RequestTimedRefresh( 0 ); 
GfxSelectFont( "Tahoma", 12, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorWhite ); 

if ( ccresult1 =="cu") 
{ 
GfxSelectSolidBrush( ColorRGB(0,240,0) ); 

} 
else 

if ( ccresult2 =="cd") 

{ 
GfxSelectSolidBrush( ColorRGB(240,0,0)); 

} 

else 

if ( ccresult2 =="") 

{ 
GfxSelectSolidBrush( colorDarkTeal ); 

} 

GfxSelectFont( "Arial", 10, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorBlue ); 

GfxSelectPen( colorBlue, 1 ); // broader color 
GfxRoundRect( 350,520,260,465, 50, 50 ); 








_SECTION_END(); 




_SECTION_BEGIN("%BB7-1"); 

p=7; 
x=((C+2*StDev(C,p)-MA(C,p))/(4*StDev(C,p)))*100; 
bbdown= x < 40; 
bbup= x > 40; 

bbresult1 = WriteIf( bbup,"bu", ""); 
bbresult2 = WriteIf( bbdown,"bd", ""); 
bbresult3 = WriteIf( C,"bearishrevers", ""); 



RequestTimedRefresh( 0 ); 
GfxSelectFont( "Tahoma", 12, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorWhite ); 

if ( bbresult1 =="bu") 
{ 
GfxSelectSolidBrush( ColorRGB(62,255,62) ); 

} 
else 

if ( bbresult2 =="bd") 

{ 
GfxSelectSolidBrush( ColorRGB(255,62,62) ); 

} 

else 

if ( bbresult2 =="") 

{ 
GfxSelectSolidBrush( colorDarkTeal ); 

} 

GfxSelectFont( "Arial", 10, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorBlue ); 

GfxSelectPen( colorBlue, 1 ); // broader color 

GfxRoundRect( 340,510,270,475, 50, 50 ); 


_SECTION_END(); 




x = 300; 
x2 = 200; 

y = Status( "pxchartheight" ); 
GfxSelectSolidBrush( colorBlue ); 
GfxSelectPen( colorWhite, 1); // broader color 
GfxRoundRect( 535, y - 80, 430,y ,7 , 7 ) ; 



_SECTION_BEGIN("MACDHIGHBULLISH"); 
r1 = Param( "Fast avg", 12, 2, 200, 1 ); 
r2 = Param( "Slow avg", 26, 2, 200, 1 ); 
r3 = Param( "Signal avg", 9, 2, 200, 1 ); 
r4 = Param( "Wk slow", 17, 2, 200, 1 ); 
r5 = Param( "Wk fast", 8, 2, 200, 1 ); 
m1=MACD(r1,r2); 
s1=Signal(r1,r2,r3); 





rsidn=m1>0 AND m1>s1; 
rsiresult2 = WriteIf( rsidn,"cd", ""); 
if ( rsiresult2 =="cd") 

{ 
GfxSelectSolidBrush( ColorRGB(0,147,0)); 

} 

else 

if ( rsiresult2 =="") 

{ 
GfxSelectSolidBrush( colorDarkTeal ); 

} 
RequestTimedRefresh( 0 ); 
GfxSelectFont( "Arial", 10, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorBlue ); 

GfxSelectPen( colorBlue, 1 ); 
// broader color 
GfxCircle( 445,550,10 ); 

_SECTION_END(); 


rsidn=m1<0 AND m1>s1; 
rsiresult2 = WriteIf( rsidn,"cd", ""); 
if ( rsiresult2 =="cd") 

{ 
GfxSelectSolidBrush( ColorRGB(0,147,0)); 

} 

else 

if ( rsiresult2 =="") 

{ 
GfxSelectSolidBrush( colorDarkTeal ); 

} 
RequestTimedRefresh( 0 ); 
GfxSelectFont( "Arial", 10, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorBlue ); 

GfxSelectPen( colorBlue, 1 ); 
// broader color 

GfxCircle( 470,550,10 ); 

_SECTION_END(); 

_SECTION_BEGIN("MACDLOWHBEARISH"); 
r1 = Param( "Fast avg", 12, 2, 200, 1 ); 
r2 = Param( "Slow avg", 26, 2, 200, 1 ); 
r3 = Param( "Signal avg", 9, 2, 200, 1 ); 
r4 = Param( "Wk slow", 17, 2, 200, 1 ); 
r5 = Param( "Wk fast", 8, 2, 200, 1 ); 
m1=MACD(r1,r2); 
s1=Signal(r1,r2,r3); 





rsidn=m1>0 AND m1<s1; 
rsiresult2 = WriteIf( rsidn,"cd", ""); 
if ( rsiresult2 =="cd") 

{ 
GfxSelectSolidBrush( ColorRGB(225,0,0)); 

} 

else 

if ( rsiresult2 =="") 

{ 
GfxSelectSolidBrush( colorDarkTeal ); 

} 
RequestTimedRefresh( 0 ); 
GfxSelectFont( "Arial", 10, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorBlue ); 

GfxSelectPen( colorBlue, 1 ); 
// broader color 

GfxCircle(495,550,10); 

_SECTION_END(); 

_SECTION_BEGIN("MACDHIGHHBEARISH"); 
r1 = Param( "Fast avg", 12, 2, 200, 1 ); 
r2 = Param( "Slow avg", 26, 2, 200, 1 ); 
r3 = Param( "Signal avg", 9, 2, 200, 1 ); 
r4 = Param( "Wk slow", 17, 2, 200, 1 ); 
r5 = Param( "Wk fast", 8, 2, 200, 1 ); 
m1=MACD(r1,r2); 
s1=Signal(r1,r2,r3); 
rsidn=m1<0 AND m1<s1; 
rsiresult2 = WriteIf( rsidn,"cd", ""); 
if ( rsiresult2 =="cd") 
{ 
GfxSelectSolidBrush( ColorRGB(225,0,0)); 
} 

else 

if ( rsiresult2 =="") 

{ 
GfxSelectSolidBrush( colorDarkTeal ); 

} 
RequestTimedRefresh( 0 ); 
GfxSelectFont( "Arial", 10, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorBlue ); 

GfxSelectPen( colorBlue, 1 ); 
// broader color 

GfxCircle( 520,550,10 ); 

_SECTION_END(); 


_SECTION_BEGIN("Average 0"); 
P = HaClose; 
Type = ParamList("Type", "Weighted,Lagless-21,Hull-26,Linear 
Regression-45,Exponential,Double Exponential,Tripple 
Exponential,Wilders,Simple"); 
Periods = Param("Periods", 20, 2, 200 ); 
Displacement = Param("Displacement", 1, -50, 50 ); 
m = 0; 

if( Type == "Weighted" ) m= WMA( P, Periods ); 
if( Type == "Lagless-21" ) m= 2*EMA(P, Periods)-EMA(EMA(P, Periods), Periods); 
if( Type == "Hull-26" ) m= WMA(2*(WMA(P, Periods/2))-WMA(P, Periods) ,4 ); 
if( Type == "Linear Regression-45" ) m= LinearReg( P, Periods ); 
if( Type == "Exponential" ) m = EMA( P, Periods ); 
if( Type == "Double Exponential" ) m = DEMA( P, Periods ); 
if( Type == "Tripple Exponential" ) m = TEMA( P, Periods ); 
if( Type == "Wilders" ) m = Wilders( P, Periods ); 
if( Type == "Simple" ) m = MA( P, Periods ); 

_SECTION_END(); 


_SECTION_BEGIN("Average 1"); 
//Average_switch = ParamToggle("Candle On/off", "Off|On"); 
P = HaClose; 
Type = ParamList("Type", "Weighted,Lagless-21,Hull-26,Linear 
Regression-45,Exponential,Double Exponential,Tripple 
Exponential,Wilders,Simple"); 
Periods = Param("Periods", 60, 2, 200 ); 
Displacement = Param("Displacement", 1, -50, 50 ); 
m = 0; 

if( Type == "Weighted" ) m= WMA( P, Periods ); 
if( Type == "Lagless-21" ) m= 2*EMA(P, Periods)-EMA(EMA(P, Periods), Periods); 
if( Type == "Hull-26" ) m= WMA(2*(WMA(P, Periods/2))-WMA(P, Periods) ,4 ); 
if( Type == "Linear Regression-45" ) m= LinearReg( P, Periods ); 
if( Type == "Exponential" ) m = EMA( P, Periods ); 
if( Type == "Double Exponential" ) m = DEMA( P, Periods ); 
if( Type == "Tripple Exponential" ) m = TEMA( P, Periods ); 
if( Type == "Wilders" ) m = Wilders( P, Periods ); 
if( Type == "Simple" ) m = MA( P, Periods ); 

_SECTION_END(); 

_SECTION_BEGIN("Average 5"); 
P = HaClose; 
Type = ParamList("Type", "Weighted,Lagless-21,Hull-26,Linear 
Regression-45,Exponential,Double Exponential,Tripple 
Exponential,Wilders,Simple"); 
Periods = Param("Periods", 120 ,2, 200 ); 
Displacement = Param("Displacement", 1, -50, 50 ); 
m = 0; 

if( Type == "Weighted" ) m= WMA( P, Periods ); 
if( Type == "Lagless-21" ) m= 2*EMA(P, Periods)-EMA(EMA(P, Periods), Periods); 
if( Type == "Hull-26" ) m= WMA(2*(WMA(P, Periods/2))-WMA(P, Periods) ,4 ); 
if( Type == "Linear Regression-45" ) m= LinearReg( P, Periods ); 
if( Type == "Exponential" ) m = EMA( P, Periods ); 
if( Type == "Double Exponential" ) m = DEMA( P, Periods ); 
if( Type == "Tripple Exponential" ) m = TEMA( P, Periods ); 
if( Type == "Wilders" ) m = Wilders( P, Periods ); 
if( Type == "Simple" ) m = MA( P, Periods ); 
_SECTION_END(); 


_SECTION_BEGIN("Sell Average 3"); 
P = HaClose; 
Type = ParamList("Type", "Weighted,Lagless-21,Hull-26,Linear 
Regression-45,Exponential,Double Exponential,Tripple 
Exponential,Wilders,Simple"); 
Periods = Param("Periods", 180, 2, 800 ); 
Displacement = Param("Displacement", 1, -50, 50 ); 
m = 0; 

if( Type == "Weighted" ) m= WMA( P, Periods ); 
if( Type == "Lagless-21" ) m= 2*EMA(P, Periods)-EMA(EMA(P, Periods), Periods); 
if( Type == "Hull-26" ) m= WMA(2*(WMA(P, Periods/2))-WMA(P, Periods) ,4 ); 
if( Type == "Linear Regression-45" ) m= LinearReg( P, Periods ); 
if( Type == "Exponential" ) m = EMA( P, Periods ); 
if( Type == "Double Exponential" ) m = DEMA( P, Periods ); 
if( Type == "Tripple Exponential" ) m = TEMA( P, Periods ); 
if( Type == "Wilders" ) m = Wilders( P, Periods ); 
if( Type == "Simple" ) m = MA( P, Periods ); 
_SECTION_END(); 


_SECTION_BEGIN("traing sl"); 

function vstop_func(trBull,trBear) 
{ 
trailArray[ 0 ] = C[ 0 ]; // initialize 
for( i = 1; i < BarCount; i++ ) 
{ 
prev = trailArray[ i - 1 ]; 

if (C[ i ] > prev AND C[ i - 1 ] > prev) 
{ 
trailArray[ i ] = Max(prev,C[ i ] - trBull[ i ]); 
} 
else if (C[ i ] < prev AND C[ i - 1 ] < prev) 
{ 
trailArray[ i ] = Min(prev,C[ i ] + trBear[ i ]); 
} 
else if (C[ i ] > prev) 
{ 
trailArray[ i ] = C[ i ] - trBull[ i ]; 
} 
else 
{ 
trailArray[ i ] = C[ i ] + trBear[ i ];	
} 
} 
return trailArray; 
} 

per = Param("per",20, 1, 150, 1); 
multBull = Param("multBull",2, 1, 4, 0.05); 
multBear = Param("multBear",2, 1, 4, 0.05); 

trBull = multBull * ATR(per); 
trBear = multBear * ATR(per); 

trailArray = vstop_func(trBull,trBear); 
s0=trailArray; 

s1= s0 > C ; 
s2= s0 <C ; 
ccresult1 = WriteIf( s1,"cu", ""); 
ccresult2 = WriteIf( s2,"cd", ""); 

GfxSelectFont("arial", 13, 700 ); GfxSetBkMode( colorRed); 
GfxSetTextColor( ParamColor("Color",colorRed) ); 
Hor=Param("Horizontal Position",30,10,1200,1); 
Ver=Param("Vertical Position",185,100,50,50); 



_SECTION_END(); 

_SECTION_BEGIN("traing s2"); 

s0=trailArray; 

s1= s0 > C ; 
s2= s0 <C ; 
ccresult1 = WriteIf( s1,"cu", ""); 
ccresult2 = WriteIf( s2,"cd", ""); 



_SECTION_END(); 


_SECTION_BEGIN("buycircle"); 
GfxSelectFont( "Arial", 10, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorBlue ); 
GfxSelectPen( colorBlue, 1 ); 
if ( ccresult2 =="cd") 
{ 
GfxSelectSolidBrush( ColorRGB(0,255,0) ); 
} 
else 
{ 
GfxSelectSolidBrush( ColorRGB(0,0,94) ); 
} 

GfxCircle( 455,510,20 ); 

_SECTION_END(); 
_SECTION_BEGIN("sellcircle"); 
GfxSelectFont( "Arial", 10, 100 ); 
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorBlue ); 
GfxSelectPen( colorBlue, 1 ); 
if ( ccresult1 =="cu") 
{ 
GfxSelectSolidBrush( ColorRGB(255,0,0) ); 
} 
else 
{ 
GfxSelectSolidBrush( ColorRGB(0,0,94) ); 
} 

GfxCircle( 510,510,20 ); 
_SECTION_END(); 
_SECTION_BEGIN("ema_crossover"); 
Plot(EMA(Close,10),"",colorOrange,styleLine ); 
Plot(EMA(Close,20),"",colorBlueGrey,styleLine); 
Plot(EMA(Close,30),"",colorTeal,styleLine); 
_SECTION_END(); 








//This Section is For HH HL LH LL // 
Q = Param( "% Change", 0.6, 0.1, 10, 0.1 ); 
Z = Zig( C , q ) ; 
HH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( z, q, 1 ) > Peak( Z, q, 2 ) ) ); 
LH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( Z, q, 1 ) < Peak( Z, q, 2 ) ) ); 
HL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) > Trough( Z, q, 2 ) ) ); 
LL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) < Trough( Z, q, 2 ) ) ); 
GraphXSpace = 5; 
dist = 0.5 * ATR( 20 ); 

for ( i = 0; i < BarCount; i++ ) 
{ 
if ( HH[i] ) 
PlotText( "H TOP ", i, H[ i ] + dist[i], colorYellow ); 

if ( LH[i] ) 
PlotText( "L TOP", i, H[ i ] + dist[i], colorYellow ); 

if ( HL[i] ) 
PlotText( "H Bottom", i, L[ i ] - dist[i], colorYellow ); 

if ( LL[i] ) 
PlotText( "L Bottom", i, L[ i ] - dist[i], colorYellow ); 

} 































_SECTION_BEGIN("Magnified Market Price"); 
FS=Param("Font Size",30,30,100,1); 
GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True ); 
GfxSetBkMode( colorWhite ); 
GfxSetTextColor( ParamColor("Color",colorWhite) ); 
Hor=Param("Horizontal Position",350,800,800,800); 
Ver=Param("Vertical Position",50,27,27,27); 
GfxTextOut(""+C,Hor+250 , Ver-53 ); 
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+250, Ver-1 ); 
_SECTION_END(); 

_SECTION_BEGIN("Right Functions"); 

function HAI_F1(no) 
{ 
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); 
return (IIf(avn==1,sup,res)); 
} 

function HAI_F2(no) 
{ 
return (Cross(C,HAI_F1(no))); 
} 

function HAI_F3(no) 
{ 
return (Cross(HAI_F1(no),C)); 
} 

function HAI_F4(no) 
{ 
prev=AMA2(C,1,0); 
d=IIf(C>Ref(Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),-1),Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))), 
IIf(C<Ref(Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),-1),Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),PREV)); 
a=Cross(Close,d); 
b=Cross(d,Close); 
return (IIf(BarsSince(a)<BarsSince(b),1,0)); 
} 

function HAI_F5(no) 
{ 
state = HAI_F4(no); 
s=state>Ref(state,-1); 
ss=state<Ref(state,-1); 

return (state==Ref(state,-1)); 
} 


function HAI_F6(p,n,s,m) 
{ 
return (PDI(p)>MDI(n)AND Signal(s)<MACD(m)); 
} 

function HAI_F7(p,n,s,m) 
{ 
return (MDI(n)>PDI(p)AND Signal(s)>MACD(m)); 
} 


_SECTION_END(); 


_SECTION_BEGIN("trending ribbon"); 
uptrend=PDI()>MDI()AND Signal()<MACD(); 
downtrend=MDI()>PDI()AND Signal()>MACD(); 



_SECTION_END(); 


_SECTION_BEGIN("Swing"); 

no = 22; 
sloss = HAI_F1(no); 
a = HAI_F2(no); 
b = HAI_F3(no); 
state = HAI_F4(no); 
sss = HAI_F5(no); 
uptrend = HAI_F6(20,10,29,22); 
downtrend = HAI_F7(20,10,29,13); 
style = a * styleStaircase + b * styleStaircase; 
PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High)); 

_SECTION_END(); 



_SECTION_BEGIN(""); 
Buy = a; 
Sell = b; 



PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-10); 
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-20); 
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-15); 
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=20); 
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30); 
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25); 

dist =0.5* ATR(10); 
dist1 = 2*ATR(10); 
for (i=0; i<BarCount; i++) { 
if ( Buy[i] ) 
PlotText("Buy:" + H[ i ], i, H[ i ]-3*dist[i], colorGreen); 

if ( Sell[i] ) 
PlotText("Sell:" + L[ i ], i, L[ i ]+3*dist[i], colorRed); 
} 

AlertIf( Buy, "", "BUY @ " + H, 1 ); 
AlertIf( Sell, "", "SELL @ " + L, 2 ); 
AlertIf( Buy, "EMAIL", "A sample alert on "+FullName(), 1 ); 
AlertIf( Sell, "EMAIL", "A sample alert on "+FullName(), 2 ); 
_SECTION_END(); 



//d = Close > Ref( ChandelierHL(ATR(3),20), -1); 
//e =Close < Ref( ChandelierHL(ATR(3),20), -1); 
//f = Close < Ref( ChandelierHL(ATR(3),20), -1); 
//g = Close > Ref( ChandelierHL(ATR(3),20), -1); 

Buy = a AND uptrend ; 
Short = b AND downtrend ; 
Sell = b AND downtrend ; 
Cover = a AND uptrend; 

Buy=ExRem(Buy,Sell); 
Sell=ExRem(Sell,Buy); 
Cover=ExRem(Cover,Short); 
Short=ExRem(Short,Cover); 

Filter=Buy OR Sell; 
Filter= Cover OR Short; 

AddColumn( Buy, "Buy", 1); 
AddColumn(Sell, "Sell", 1); 
AddColumn(Close,"Close",1.2); 
AddColumn(Volume,"Volume",1.0); 



//Plot(sloss,"Swing",colorYellow,styleStaircase); 

//SetChartBkGradientFill( ParamColor("BgTop", ColorRGB( 172,172,172 )), 

//ParamColor("BgBottom", ColorRGB( 172,172,172 )),ParamColor("titleblock",ColorRGB( 172,172,172 ))); 
//Alerts 


GraphXSpace = 5; 

/* -------------------------------------------------------------------------------------- */ 

SetChartBkColor(colorBlack); 
SetChartOptions(0,chartShowArrows|chartShowDates); 

/* -------------------------------------------------------------------------------------- */ 
//////////////////////////////////////////////////////////////////////////////////////////////// 
messageboard = ParamToggle("Message Board","Show|Hide",0); 
showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0); 

style = a * styleStaircase + b * styleStaircase; 

PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High)); 
if (showsl == 0) Plot(sloss,"Stop Loss",colorYellow,styleLine |styleDashed|styleThick); 
exitlong = Cross(sloss, H); 
PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10); 
exitshort = Cross(L, sloss); 
PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15); 

Buy = exitshort; 
Sell = exitlong; 
//Short = Sell; 
//Cover = Buy; 
Buy = ExRem(Buy,Sell); 
Sell = ExRem(Sell,Buy); 
//Short = ExRem(Short, Cover); 
//Cover = ExRem(Cover, Short); 
AlertIf( Buy, "", "BUY @ " + H, 1 ); 
AlertIf( Sell, "", "SELL @ " + L, 2 ); 

for (i=BarCount-1; i>1; i--) { 
if (Buy[i] == 1) { 
entry =H[i]; 
sig = "BUY"; 
sl = sloss[i]; 
tar1 = entry + (entry * .0040); 
tar2 = entry + (entry * .0085); 
tar3 = entry + (entry * .0179); 
bars = i; 
i = 0; 
} 
if (Sell[i] == 1) { 
sig = "SELL"; 
entry = L[i]; 
sl = sloss[i]; 
tar1 = entry - (entry * .0050); 
tar2 = entry - (entry * .0085); 
tar3 = entry - (entry * .0212); 
bars = i; 
i = 0; 
} 
} 

Offset = 20; 
Clr = IIf(sig == "BUY", colorLime, colorRed); 
ssl = IIf(bars == BarCount-1, sloss[BarCount-1], Ref(sloss, -1)); 
sl = ssl[BarCount-1]; 

printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago"); 
printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3); 
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)); 





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



_SECTION_END(); 

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

_SECTION_BEGIN("ATP"); 

B=Volume; 
A=Avg; 
Value=B*A; 
Barsfromtodaybegin = 1 + BarsSince( Day() != Ref(Day(), -1)); 
Totalvalue=Sum(Value,Barsfromtodaybegin); 
Totalvolume=Sum(V,Barsfromtodaybegin); 
ATP=(Totalvalue/Totalvolume); 
ColorATP=IIf(ATP>Ref(ATP,-1),colorBrightGreen,colorRed); 
Plot(ATP,"ATP",colorATP,styleThick); 
_SECTION_END(); 

a=20; 
GraphXSpace=5; 
p=30; 
p = Param("p",30,2,100,1); 

Om=DEMA(O,p); 
hm=DEMA(H,p); 
lm=DEMA(L,p); 
Cm=DEMA(C,p); 
HACLOSE=(Om+Hm+Lm+Cm)/4; 
HaOpen = AMA( Ref( HaClose, -1), 1); 
HaHigh = Max( Hm, Max( HaClose, HaOpen ) ); 
HaLow = Min( Lm, Min( HaClose, HaOpen ) ); 

slope = Param("slope",2,2,100,1); 

Color20= IIf(LinRegSlope(MA(HaClose,a),slope)<0,colorRed,co lorGreen); 
Plot(MA(HaClose,a),"", color20,styleThick); 

Color=IIf(Haclose>MA(HaClose,a),colorGreen, colorRed); 
//PlotOHLC( HaOpen, HaOpen, HaClose, HaClose, "" + Name(), Color, styleCandle); 
_SECTION_END(); 

_SECTION_BEGIN("Priyanvada's Price Action"); 
P = ParamField( "Price field" ); 
CandleT=ParamToggle("Candlestick Display","No|Yes",defaultval=1 ); 
BarT=ParamToggle("Bar Display","No|Yes",defaultval=0 ); 
LineT=ParamToggle("Line Display","No|Yes",defaultval=0 ); 
//T3MA toggle 
T3MAT=ParamToggle("Moving Average","No|Yes",defaultval=1 ); 
//T3MA Check Periods 
T3MAP = Param("T3MA Periods", 46, 2, 300, 1, 10 ); 

function T3(price,periods) 
{ 
s = 0.84; 
e1=EMA(price,periods); 
e2=EMA(e1,Periods); 
e3=EMA(e2,Periods); 
e4=EMA(e3,Periods); 
e5=EMA(e4,Periods); 
e6=EMA(e5,Periods); 
c1=-s*s*s; 
c2=3*s*s+3*s*s*s; 
c3=-6*s*s-3*s-3*s*s*s; 
c4=1+3*s+s*s*s+3*s*s; 
Ti3=c1*e6+c2*e5+c3*e4+c4*e3; 
return ti3; 
} 
T3MA = T3(P,T3MAP); 
for( i = 1; i < BarCount; i++ ) 
{ 
//assignments 
NvadaOpen[i] = Close[i-1]; 
NvadaClose[i]=Close[i]; 
NvadaHigh[i]=IIf(NvadaOpen[i]>=NvadaClose[i],NvadaOpen[i],NvadaClose[i]); 
NvadaLow[i]=IIf(NvadaOpen[i]>=NvadaClose[i],NvadaClose[i],NvadaOpen[i]); 
averagechange[i]=(NvadaOpen[i]+NvadaClose[i])/2; 

//============================= 
//CHECKS 

//check1= uptrend and upbar as referred for last 2 bars 
Check1[i]=averagechange[i]>T3MA[i] AND NvadaClose[i]>=NvadaOpen[i-2]; 
//check2= uptrend and downbar as referred for last 2 bars 
Check2[i]=averagechange[i]>T3MA[i] AND NvadaClose[i]<NvadaOpen[i-2]; 

//check3= downtrend and downbar as referred for last 2 bars 
Check3[i]=averagechange[i]<T3MA[i] AND NvadaClose[i]<=NvadaOpen[i-2]; 
//check4= downtrend and upbar as referred for last 2 bars 
Check4[i]=averagechange[i]<T3MA[i] AND NvadaClose[i]>NvadaOpen[i-2]; 

//check5=check2 or check 4 => possible corrections! 
Check5[i]=Check2[i] OR Check4[i]; 

//Color assignment 
if(Check1[i]==1){pricolor[i] =colorGreen;} 
if(Check3[i]==1){pricolor[i] =colorRed;} 
if(Check5[i]==1){pricolor[i] =colorYellow;} 
//Pricolor = IIf(NvadaClose>Ref(NvadaOpen,-2),colorGreen,colorRed); 
} 



//T3MA Display 
if(T3MAT==1) 
{ 
T3MAcolor = IIf(C>=T3MA,colorGreen,colorRed); 
//Plot(T3MA,"T3MA",T3MAcolor,styleThick); 
} 
Buy=T3MAcolor==colorGreen; 
Sell=T3MAcolor==colorRed; 
Short=Sell; 
Cover=Buy; 

Cover=ExRem(Cover,Short); 
Short=ExRem(Short,Cover); 

Buy=ExRem(Buy,Sell); 
Sell=ExRem(Sell,Buy); 
//PlotShapes(IIf(Buy , shapeUpArrow, shapeNone),colorWhite); 
//PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorYellow); 
no=Param( "Swing", 12, 1, 55 ); 
tsl_col=ParamColor( "Color", colorLightGrey ); 

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




SetPositionSize(300,spsShares); 
ApplyStop(0,1,10,1); 
//-----------end-------------- 
Long=Flip(Buy,Sell); 
Shrt=Flip(Sell,Buy); 

BuyPrice=ValueWhen(Buy,C); 
SellPrice=ValueWhen(Sell,C); 


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)+"","")); 
_SECTION_END(); 


H1 = SelectedValue( TimeFrameGetPrice( "H", inDaily, -1 ) ); 
L1 = SelectedValue( TimeFrameGetPrice( "L", inDaily, -1 ) ); 
C1 = SelectedValue( TimeFrameGetPrice( "C", inDaily, -1 ) ); 
H2 = SelectedValue( TimeFrameGetPrice( "H", inDaily, 0 ) ); 
L2 = SelectedValue( TimeFrameGetPrice( "L", inDaily, 0 ) ); 
O1 = SelectedValue( TimeFrameGetPrice( "open", inDaily, 0 ) ); 
F4 = 0; 
D1 = ( H1 - L1 ); 
D2 = ( H2 - L2 ); 
F1 = D1 * 0.433; 
F2 = D1 * 0.766; 
F3 = D1 * 1.35; 
if ( D2 <= F1 ) 
F4 = F1; 
else 
if ( D2 <= F2 ) 
F4 = F2; 
else 
F4 = F3; 

S_P = ( O1 - F4 ); 

B_P = ( O1 + F4 ); 

BP = ( L2 + F4 ); 

BPTGT = ( BP + ( BP * .0065 ) );//.0015 brokerage 

BPSTPLS = ( BP - ( BP * .0085 ) ); 

SP = ( H2 - F4 ); 

SPTGT = ( SP - ( SP * .0065 ) ); 

SPSTPLS = ( SP + ( SP * .0085 ) ); 


p = ( H1 + L1 + C1 ) / 3; 

s1 = ( H1 ); 

r1 = ( L1 ); 

r2 = SelectedValue( L2 ); 

s2 = SelectedValue( H2 ); 
Filter = Buy OR Sell; 

AddColumn( IIf( Buy, 66, 1 ), "Buy", formatChar, 1, bkcolor = IIf( Buy, 43, 33 ) ); 

AddColumn( IIf( Sell, 83, 1 ), "Sell", formatChar, 1, bkcolor = IIf( Sell, 25, 32 ) ); 

AddColumn( IIf( Short, 83, 1 ), "Short", formatChar, 1, bkcolor = IIf( Short, 25, 32 ) ); 

AddColumn( C, "CMP", 1.2, colorDefault, colorLightBlue ); 

AddColumn( BP, "SELL PRICE", 1.2, colorDefault, colorGreen ); 

AddColumn( BPTGT, "TGT PRICE", 1.2, colorDefault, colorBrown ); 

AddColumn( BPSTPLS, "STPLS BUY", 1.2, colorDefault, colorRed ); 

AddColumn( p, "PIVOT", 1.2, colorDefault, colorYellow ); 

AddColumn( SPSTPLS, "STPLS SELL", 1.2, colorDefault, colorRed ); 

AddColumn( SP, "SELL PRICE", 1.2, colorDefault, colorGreen ); 

AddColumn( SPTGT, "TGT PRICE", 1.2, colorDefault, colorBrown ); 


AddColumn( H1, "PRE-HIGH" ); 

AddColumn( L1, "PRE-LOW" ); 

AddColumn( D1, "PRE-DIFF" ); 

AddColumn( F1, "0.433" ); 

AddColumn( F2, "0.766" ); 

AddColumn( F3, "1.35" ); 

AddColumn( H2, "D-HIGH" ); 

AddColumn( L2, "D-LOW" ); 

AddColumn( D2, "D-DIFF" ); 

AddColumn( F4, "SELECT FACT" ); 
_SECTION_END(); 
//============== TITLE ============== 
_SECTION_BEGIN("Title"); 
if( Status("action") == actionIndicator ) 
( 
Title = EncodeColor(colorGold)+ "K T S" + EncodeColor(colorRose)+" (" + Name() + ") " + EncodeColor(colorGold)+ Interval(2) + 
" " + Date() +" " +" Open "+WriteVal(O,1.000)+" "+"Hi "+WriteVal(H,1.000)+" "+"Lo "+WriteVal(L,1.000)+" "+ 
"Close "+WriteVal(C,1.000)+" ("+WriteVal(C-Ref(C,-1),1,0)+" "+WriteVal((C-Ref(C,-1))*100/Ref(C,-1),1.1)+ "%) Vol= "+ WriteVal(V,1.0) 



+"\n"+EncodeColor(colorGrey50)+"------------------------------------------------------------------------------------------------------------" 

+"\n"+EncodeColor(colorGold)+ 
WriteIf (Buy , "Signal: Go Long - Entry Price: "+WriteVal(C)+" - Traget: "+WriteVal((BuyPrice+tsl)+BuyPrice) 
+" - StopLoss:"+WriteVal(tsl)+" " 
,"")+ 


WriteIf (Sell , "Signal: Go Short - Entry Price: "+WriteVal(C)+" - Target: "+WriteVal((tsl-SellPrice)-SellPrice)+" - StopLoss:"+WriteVal(tsl)+" ","")+ 
EncodeColor(ColorRGB(111,208,255))+ 
WriteIf(Long AND NOT Buy, "Trade: Long - Entry Price: "+WriteVal((H))+" - Profit: "+WriteVal((C-BuyPrice))+" "+EncodeColor(colorLime)+"Let your profit runs!","")+ 
WriteIf(shrt AND NOT Sell, "Trade: Short - Entry Price: "+WriteVal((L))+" - Profit: "+WriteVal((SellPrice-C))+" - "+EncodeColor(colorLime)+"Let your profit runs!","") 

+"\n"+EncodeColor(colorGrey50)+"------------------------------------------------------------------------------------------------------------" 
); 

dist = 6*ATR(10); 
dist1 = 6*ATR(10); 
for( i = 0; i < BarCount; i++) 
{ 
if( Buy[i] ) 
{ 
//PlotText( "Buy:" + C[ i ] + "\nT= " + tsl[i] + "\nSL= " +((C[i]-tsl[i])+C[i]) , i, C[ i ]-dist[i], colorGreen, colorDarkOliveGreen ); 
} 
if( Sell[i] ) 
{ 
//PlotText( "Sell:" + C[ i ] + "\nT= " + (C[i]-(tsl[i]-C[i])) + "\nSL= " +tsl[i], i, C[ i ]+dist1[i], colorRed, colorDarkOliveGreen ); 
} 
} 




/*Plot Ribbon */ 
Ribbon1=IIf( (C) >(tsl) ,colorGreen, IIf(( tsl )>( C ), colorRed,colorBlack)); 
Plot(3, "Ribbon", Ribbon1, styleOwnScale| styleArea| styleNoLabel,-0.5,100); 

_SECTION_END();
 

oldtrader

Well-Known Member
Res. OT gi
Will u pl backtest KPLswing indicator Factor=13 and 7 min tf when u will free
I have used the following code , pls verify.

Code:
//PATRICK DOHERTY//
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 )) ));
H1=SelectedValue( TimeFrameGetPrice( "H", inDaily, -1 ));
L1=SelectedValue(TimeFrameGetPrice( "L", inDaily, -1 ));
C1=SelectedValue(TimeFrameGetPrice( "C", inDaily, -1 ));
/*PIVOT Calculation*/
p = ( H1+ L1 + C1 )/3;
s1 = (2*p)-H1;
r1 = (2*p)-L1;
s2 = p -(H1 - L1);
s3 = S1 - (H1-L1);
r2 = p +(H1 - L1);
r3 = R1 +(H1-L1);
  
Plot (p,"Pivot",25,styleDots);
Plot (r1,"R1",12,1);
Plot (r2,"R2",12,1);
Plot (r3,"R3",12,1);
Plot (s1,"S1",3,1);
Plot (s2,"S2",3,1);
Plot (s3,"S3",3,1);
X=Cross(C,p);
Z=Cross(p,C);
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
_SECTION_END();
 
 
//---- KPL SWING
HaClose = (O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.8);
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,colorWhite,colorWhite);
if( ParamToggle("Plot Heikin-Ashi", "No,Yes", 1 ) )
   PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "Heikin Ashi " + Name(), colorWhite, styleCandle );
else
 Plot( C, "Regular candles " + Name(), colorWhite, styleCandle );
j=Haclose;
 
//=======================================================================================================================
//=========================Indicator==============================================================================================
 
_SECTION_BEGIN("Swing10");
//Copyright Kamalesh Langote. Email:[email protected]. More details at http://www.vfmdirect.com/kplswing
//Save indicator as "kplswing.afl" in C: program files > Amibroker > Formulas > Custom folder and then drap and drop on price chart
no=Param( "Swing", 1, 1, 55 );
tsl_col=ParamColor( "Color", colorWhite);
  
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);
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorBrightGreen, layer = 0,yposition = HaLow, offset = -15);
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, layer = 0, yposition = HaHigh, offset = -15);

Short=Sell;
Cover=Buy;

SetPositionSize(1,spsShares);
 
_SECTION_END();
TF used = 7 min
Backdata = May 2006 to May 2016
Parameter = 13
Result = 10902 points in 4274 trades.

Comments = Too many trades (almost double the usual number of trades) and too less profit (Almost half the usual profits)
 
Res O T ji sorry for late reply>
_SECTION_BEGIN("KPL Swing");
//Save indicator as "kplswing.afl" in C: program files > Amibroker > Formulas > Custom folder and then drag and drop indicator on price window.
//Copyright Kamalesh Langote. Email:[email protected]. Visit http://www.vfmdirect.com/kplswing for latest code and updates
//You can use in indicator mode (chart) or scanner (generate buy/ sell signals).
//Risk management: do not risk more than 1% of your capital on any trade.
//Avoid trading in futures unless you are well capitalised.

no=Param( "Swing", 13, 1, 100,1 );

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(), colorWhite, styleStaircase,styleThick);
arrows=Cross(C,Ref(res,-1))*shapeUpArrow + Cross(Ref(sup,-1),C)*shapeDownArrow;
PlotShapes(arrows,IIf(C>tsl,colorGreen,colorIndigo),0,IIf(Cross(C,Ref(res,-1)),Low,High));

//Scanner mode
Buy=Cross(C,Ref(res,-1));
Sell=Cross(Ref(sup,-1),C);

_SECTION_END();
 

oldtrader

Well-Known Member
Dear Oldtrader ji
As per backtesting of several afl by you in spite of some pros & cons your's fractal is still the best one.
Regards
True, most of them are not upto the mark. But, one AFL posted by vijkrisji , in post number 268, was really very good. The backtest result for the same was posted in post number 269. Do check it.

Regards
 

Similar threads