//Simple EMA based trading system with stop loss and re-entry signals //Abnash Singh - abnash1978@yahoo.co.uk //30 October 2011 //Stop loss and re-entry levels are adjustable for different scrips. //Param statements can be moditified for decimal values of stop losses and re-entries. stoploss=Param("Stoploss",11,1,25,1); reentry=Param("Re-entry after",8,1,25,1); EMA10per=Param("EMA10 period",10,1,25,1); EMA21per=Param("EMA21 period",21,20,50,1); EMA60per=Param("EMA60 period",60,30,100,1); Plot(C,"price",colorWhite,styleCandle); EMA10=EMA(C,ema10per); EMA21=EMA(C,ema21per); EMA60=EMA(C,ema60per); Plot(EMA10,"EMA10",colorGreen,styleLine); Plot(EMA21,"EMA21",colorRed,styleLine); Plot(EMA60,"EMA60",colorYellow,styleLine); trend=IIf(EMA10>EMA21 AND EMA21>EMA60,1,0); trend1=IIf(EMA21starti ) { if (H[i]>slhigh[i]) { slhigh[i]=H[i]; starth=i; } if (L[i]starti AND i>starth AND slhigh[i]-avp[i]>stoploss AND exitbs==0) { exitb[i]=1;//signal exitbs=1;//signal flag priceatexitb=avp[i];//price to use for re-entry calc starti=i; Signals=0; PlotText(WriteVal(avp[i]-priceatbuy,1.0),i,H[i]+10,IIf(avp[i]-priceatbuy>0,colorGreen,colorRed)); } if (trend[i]==0)Lastbuy=0; // buy re-entry logic if (trend[i]==1 AND Lastbuy==1 AND exitbs==1 AND avp[i]-priceatexitb>reentry AND i>starti) { Buy[i]=1; Lastbuy=1; Lastshort=0; Signals=1; exitbs=0; priceatbuy=avp[i]; slhigh[i]=H[i]; sllow[i]=L[i]; starti=i; } //Stoploss short signals //PlotText(WriteVal(exitbc,1.0),i,H[i]+10,IIf(avp[i]-priceatbuy>0,colorGreen,colorRed)); if (Lastshort==1 AND i>starti AND i>startl AND avp[i]-sllow[i]>stoploss AND exitbc==0) { exitc[i]=1;//signal exitbc=1;//signal flag priceatexitc=avp[i];//price to use for re-entry calc starti=i; Signals=0; PlotText(WriteVal(priceatshort-avp[i],1.0),i,L[i]-15,IIf(priceatshort-avp[i]>0,colorGreen,colorRed)); } if (trend1[i]==0)Lastshort=0; // short re-entry logic if (trend1[i]==1 AND Lastshort==1 AND exitbc==1 AND priceatexitc-avp[i]>reentry AND i>starti) { Short[i]=1; Lastshort=1; Lastbuy=0; Signals=1; exitbc=0; priceatshort=avp[i]; slhigh[i]=H[i]; sllow[i]=L[i]; starti=i; } } shape = Buy * shapeUpArrow + Sell * shapeHollowDownArrow; shape2 = Cover * shapeHollowUpArrow+ Short*shapeDownArrow; shape3 = exitb * shapeDownArrow + exitc*shapeUpArrow; PlotShapes( shape, IIf( Buy, colorGreen, colorBlue ),0, IIf( Buy, Low, High ) ); PlotShapes( shape2, IIf( Short, colorRed, colorBlue ),0, IIf( Short, High, Low ) ); PlotShapes( shape3, IIf( exitb, colorWhite, colorWhite ),0, IIf( exitb, High, Low ) );