SH's swing trading system - a simple way to play the markets


badbadbadbadbabd afl
:p:p:p:p: :D

_SECTION_BEGIN(" ema 3-15 ");



x = Ref(H,-1);
Y = Ref(L,-1);
a=x+1;
b=y-1;
aa=EMA(C,3);
bb=EMA(C,15);
Buy = Cover = C>a AND aa>bb;
Sell = Short = C<b AND aa<bb;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,L,-15);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);

b1=Cross(aa,bb);
s1=Cross(bb,aa);
Buysetup=Flip(b1,s1);
Shortsetup=Flip(s1,b1);
trend=IIf(BarsSince(Buysetup)<BarsSince(Shortsetup ),1,0);
Col=IIf(trend==1,colorGreen,4);
SetBarFillColor(Col);
Plot(C,"Close",Col,64);
_SECTION_END();
//==============================
_SECTION_BEGIN("HL Pivots");
//==============================
psh= ParamToggle("Pivot Shapes","Off|On",1);
plb= ParamToggle("Pivot Labels","Off|On",1);
snd= ParamToggle("Sound Alerts","Off|On",1);
lbk= Param("Hi Lo Lookback",350,50,5000,10);
nbz= Param("Swing Bars",20,5,150,1);
tht= Param("Hi Label Adjust",0.65,0.10,5,0.05)*ATR(5);
lbk= Min(BarCount-1,Lbk);
bc=BarCount-1;
//================
xH=H-H; xL=L-L; yH=H-H; yL=L-L; xR=H-H; xS=L-L;
xrb=0; xSb=0; yR0=0; yS0=0; xR0=0; xS0=0; xx=0;
xHH= HHVBars(H,nbz); xLL= LLVBars(L,nbz);
yHH= HHV(H,nbz); yLL= LLV(L,nbz);
viz= Status("BarVisible");
vbz= LastValue(Highest(IIf(viz,BarIndex(),0)));
_TRACE("Last visible bar: "+ vbz);
bct= (BarCount-1); dir = "";
if(xLL[bc]<xHH[bc]) { dir="D"; } else { dir="U"; }
for(i=0; i<lbk; i++) { bc=bct-i;
if(xLL[bc]<xHH[bc]) { if(dir=="U"){dir="D";
xx=bc-xLL[bc]; xL[xx]=1;
yL[xSb]=L[xx]; xS[xSb]=xx; xSb++; }
} else { if(dir=="D") { dir = "U";
xx=bc-xHH[bc]; xH[xx]=1; yH[xrb]=H[xx]; xR[xrb]=xx;xrb++; }}}
xP= 0; yP= 0; xS0= xS[0]; yS0=yL[0]; xR0= xR[0]; yR0= yH[0];
if(xS0>xR0) { xP=bc-xHH[bc]; yP= yHH[bc];
if(yR0<yP AND xP>xS0 AND xP<bc) { xH[xP]=1;
for(j=0; j<xrb; j++) { yH[xrb-j]= yH[xrb-(j+1)];
xR[xrb-j]= xR[xrb-(j+1)]; }
yH[0]= yP; xR[0]= xP; xrb++; }
} else { xP= bc-xLL[bc]; yP= yLL[bc];
if(yS0>yP AND xP>xR0 AND xP<bc) { xL[xP]=1;
for(j=0; j<xSb; j++) { yL[xSb-j]= yL[xSb-(j+1)]; xS[xSb-j]= xS[xSb-(j+1)]; }
yL[0]=yP; xS[0]=xP; xSb++; }}
ushp=shapeHollowUpArrow; dshp=shapeHollowDownArrow;
if(psh) { PlotShapes(xH*dshp,42,0,H,-10); PlotShapes(xL*ushp,43,0,L,-10); }
if(snd) {
AlertIf(xL==1,"SOUND C:\\Windows\\Media\\Windows XP Startup.wav","Audio alert",2);
AlertIf(xH==1,"SOUND C:\\Windows\\Media\\Ringin.wav","Audio alert",2); }
Buy=(xL); Sell=(xH); Cover=(xL); Short=(xH); Long=Flip(Buy,Sell); Shrt=Flip(Sell,Buy);
SellPrice=ValueWhen(Sell,H,1); BuyPrice= ValueWhen(Buy,L,1);
if(plb) {
for(i=0; i<BarCount; i++) {
if(Buy )PlotText("\n\n"+ StrRight(NumToStr(L,6.2),5),i-1,L,43,16);
if(Sell)PlotText(StrRight(NumToStr(H,6.2),5),i-1,H+tht,32,16); }
}
_SECTION_END();
//===========================

_SECTION_BEGIN( "MA Envelope" );
Type = ParamList( "Avg. Type", "SMA,EMA" );
P = ParamField( "Price field", -1 );
Periods = Param( "Avg. Periods", 20, 2, 300, 1, 10 );
F = Param( "Filter %", 5, 0.05, 100, 1 );

if ( Type == "SMA" )
A = MA( P, Periods );

if ( Type == "EMA" )
A = EMA( P, Periods );

EnvUp = A + A * F / 100;

EnvDn = A - A * F / 100;

Plot( A, _DEFAULT_NAME(), IIf( Ref( A, 0 ) > Ref( A, -1 ), ParamColor( "ColorUp", colorWhite ), ParamColor( "ColorDown", colorOrange ) ), ParamStyle( "Style", styleThick ) );

Plot( EnvUp, "EnvUp", ParamColor( "EnvUp Color", colorRed ), styleThick + styleNoLabel );

Plot( EnvDn, "EnvDn", ParamColor( "EnvDn Color", colorGreen ), styleThick + styleNoLabel );

_SECTION_END();

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


its dangerous ok :spam: :D
 
Last edited:
JamesBond 007,
When I try to apply this afl the bands are away from price and on your chart the bands are different.

vishnu_1990v
are vishnu bhai sahab ji apun ne bola tha its dangerous try mat karo firrrrrrr bhi :D :D

hmmmmm avg price 25 to 35 and filter%=0.6 to 0.9 ke middle rakho and timeframe 15 to 30 min.. and try ...checked them ok :lol:
 

Similar threads