//Moving Average Based Trading Advanced version // Abnash Singh // 30th October 2011 // abnash1978@yahoo.co.uk SetChartOptions(0,chartShowDates|chartShowArrows|chartLogarithmic|chartWrapTitle); 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; SetChartOptions(0,chartShowArrows|chartShowDates); showsig=ParamList("Show Signals","YES|NO"); Showprice=ParamList("Show Buy/Sell Prices","YES|NO"); Plot( C, "Close", ParamColor("Color", colorBlack), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); period = Param("Period", 13, 1, 240, 1); mult = Param("Multiplier", 2.21, 0, 3, 0.01); A=EMA (RSI(14),5); B=EMA (RSI(21),5); f=ATR(period); x=5; VS[0] = Close[0]; trend[0] = 0; HighC[0]=0; Lowc[0]=0; for( i = period+1; i < BarCount; i++ ) { vs[i] = vs[i-1]; trend[i] = trend[i-1]; highC[i] = HighC[i-1]; lowc[i] = lowc[i-1]; if ((trend[i]>=0) AND ( C[i] VS[i])) { trend[i]=1; HighC[i] = C[i]; lowc[i] = C[i]; } if (trend[i]==-1) { if (C[i]HighC[i]) HighC[i] = C[i]; VS[i]= HighC[i]-(mult*f[i]); } } Pribbon=ParamList("Ribbon? ", "Yes|No"); if (Pribbon=="Yes") { Plot( 2, /* defines the height of the ribbon in percent of pane width */"ribbon", IIf( trend==1, colorGreen, IIf( trend==-1, colorRed, 0 )), /* choose color */ styleOwnScale|styleArea|styleNoLabel, -0.5, 100 ); } _SECTION_BEGIN("Volume"); Plot( Volume, _DEFAULT_NAME(), IIf( C > O, ParamColor("Up Color", colorGreen ), ParamColor("Down Color", colorRed ) ), ParamStyle( "Style", styleHistogram | styleThick |styleOwnScale, maskHistogram ),7 ); _SECTION_END(); TrailStop = HHV( C - 2.1 * ATR(3), 7); //trailstop=(IIf(!downtrend OR uptrend, trailstop, Null)); //Plot( trailstop , "Trailing stop", colorCustom12, 8); //Plot( IIf(shrttgtStochD(14); Cond2=StochK(14)MDI(); _SECTION_END(); _SECTION_END(); _SECTION_BEGIN("my FIST"); Slowavg=Param("Slow Average",10,10,70,1); Fastavg=Param("Fast Average",3,1,15,1); gapx=Param("Tolerance",3,0,10,.001); SPsignals=ParamList("Generate new Buy/Sells after SP","YES|NO"); n4=4; Datex=DateNum(); Buy1=Cross(EMA(C,fastavg),EMA(C,slowavg)); Sell1=Cross(EMA(C,slowavg),EMA(C,fastavg)); EMA3=EMA(C,3); EMA30=EMA(C,30); Lastsig=0; diff=5; for (i=1;i EMa30[i] ) buy1[i]=1; if(EMA3[i]< EMA30[i] ) Sell1[i]=1; } if(Buy1[i]) { if(Sell1[i-1]) { Buy1[i]=0; Sell1[i-1]=0; } } if(Sell1[i]) { if(Buy1[i-1]) { Buy1[i-1]=0; Sell1[i]=0; } } } gapema=abs(EMA(C,fastavg)-EMA(C,slowavg)); Nowbuy=0;Nowsell=0;starti=0;Lastbuy=Lastsell=0; avp=(O+C)/2; for (i=1;igapx) { Buy1[i]=1; Nowbuy=0; Nowsell=0; } if (Nowsell==1 AND gapema[i]>gapx ) { Sell1[i]=1; starti=i; Nowsell=0; Nowbuy=0; } if (Buy1[i]) { Lastbuy=1; Lastsell=0; } if (Sell1[i]) { Lastbuy=0; Lastsell=1; } } slhigh=HHV(H,BarsSince(Buy1)); sllow=LLV(L,BarsSince(Sell1)); gapy=Param("SP",10,0,50,0.01); Lastshort=0;priceatcover=priceatshort=0;Cover2=0;Lastcover=0;Sell2=0;Lastsell=newbuy=newshort=0; for (i=1; iC[i]) { sell1[i]=1; newshort=0; } } if (C[i]-sllow[i]>gapy AND Lastshort==1 AND Lastcover==0 AND I>starti AND sllow[i]==sllow[i-1]) { Cover2[i]=1; Lastcover=1; priceatcover=C[i]; newshort=1; } if ((Lastcover==1 AND C[i]priceatsell+n4 AND O[i]gapy AND Lastbuy==1 AND Lastsell==0 AND i>starti AND slhigh[i]==slhigh[i-1]) { Sell2[i]=1; Lastsell=1; // priceatsell=avp[i]; priceatsell=C[i]; } if ((Lastsell==1 AND C[i]>priceatsell+(gapy/2)) )Lastsell=0; } shape = Buy * shapeUpArrow + Sell * shapeDownArrow; shape1 = Buy1 * shapeUpTriangle + Sell1 * shapeDownTriangle; shape2 = Cover2 * shapeHollowUpArrow+ Sell2*shapeHollowDownArrow; if(showsig=="YES") { PlotShapes( shape, IIf( Buy, colorBlue, colorRed ),0, IIf( Buy, Low, High ) ); PlotShapes( shape1, IIf( Buy1, colorBlue, colorRed ),0, IIf( Buy1, Low, High ) ); PlotShapes( shape2, IIf( Cover2, colorGreen, colorGreen ),0, IIf( Cover2, Low, High ) ); } GraphXSpace = 5; dist = 5*ATR(10); mth=int(DateNum()/100)-int(DateNum()/10000)*100; Currmthstart=int(DateNum()/100)*100; Profit=profitmth=0; Lastsig=Lastbuysig=Lastsellsig=Lastcoversig=Lastshortsig=0; for( i = 0; i < BarCount; i++ ) { if (i>0) { if(mth[i]!=mth[i-1]) { profitmth[i]=0; } else { profitmth[i]=profitmth[i-1]; } } if(i>0)profit[i]=profit[i-1]; if((i>0 AND Datex[i]!= Datex[i-1]) OR i==(BarCount-1)) { if(i!=BarCount-1) { if (Lastbuysig==1)profit[i]=profit[i]+avp[i-1]-priceatbuy; if (Lastshortsig==1)profit[i]=profit[i]+priceatshort-avp[i-1]; } else { if (Lastbuysig==1)profit[i]=profit[i]+avp[i]-priceatbuy; if (Lastshortsig==1)profit[i]=profit[i]+priceatshort-avp[i]; } if (showprice=="YES" AND Interval()< 86400)PlotText( "Profit\n" + WriteVal(Profit[ i ],1.0) , i, L[ i ]-dist[i]/2, colorBlack ); if(Datex[i]>Currmthstart[i] AND mth[i]==mth[i-1] ) { ProfitMth[i]=profitmth[i-1]+profit[i]; } profit[i]=0; Lastsig=Lastbuysig=Lastsellsig=Lastcoversig=Lastshortsig=0; } if (Buy1[i]) { Lastbuysig=1; priceatbuy=avp[i]; if (Lastshortsig==1) { profit[i]=profit[i]+priceatshort-avp[i]; Lastshortsig=0; } } if (Sell1[i]) { Lastshortsig=1; priceatshort=avp[i]; if (Lastbuysig==1) { profit[i]=profit[i]+avp[i]-priceatbuy; Lastbuysig=0; } } if (Cover2[i]) { Lastcoversig=1; priceatcover=avp[i]; if (Lastshortsig==1) { profit[i]=profit[i]+priceatshort-avp[i]; Lastshortsig=0; } } if (Sell2[i]) { Lastsellsig=1; priceatsell=avp[i]; if (Lastbuysig==1) { profit[i]=profit[i]+avp[i]-priceatbuy; Lastbuysig=0; } } if(showprice=="YES" ) { if( Buy[i] ) PlotText( "CBuy\n@" + avp[ i ] , i, L[ i ]-dist[i], colorBlue ); if( Sell[i] ) PlotText( "CSell\n@" + avp[ i ], i, H[ i ]+dist[i], colorBlue); if( Buy1[i] ) PlotText( "EBuy\n@" + avp[ i ], i, L[ i ]-dist[i], colorBlue ); if( Sell1[i] ) PlotText( "ESell\n@" + avp[ i ], i, H[ i ]+dist[i], colorBlue); } } Plot( 1, "", IIf(EMA(C,15)>EMA(C,60) , colorPaleGreen, colorRose ),styleArea | styleOwnScale, 0, 1 ); _SECTION_END(); _SECTION_BEGIN("Volume At Price"); //PlotVAPOverlay(Param("Lines", 1000, 100, 1000, 10), Param("Width", 15, 1, 100, 1), ParamColor("Color", colorBlue), ParamToggle("Side", "Left|Right", 1) | 4 *ParamToggle("Z-order", "On top|Behind", 1)); _SECTION_END(); Title = "Moving Average TRADES "+Date()+" "+ Interval(format=2)+" "+Name()+" "+"O "+WriteVal(O,1.2)+" "+"H "+WriteVal(H,1.2)+" L"+WriteVal(L,1.2)+" C "+WriteVal(C,1.2)+" Vol "+WriteVal(V,1.0)+" "+EncodeColor(colorRed)+WriteIf(EMA(C,3)>EMA(C,16),EncodeColor(colorGreen),EncodeColor(colorRed))+" EMA 3/16 "+WriteVal(EMA(C,3),1.0)+"/"+WriteVal(EMA(C,16),1.0)+WriteIf(EMA(C,15)>EMA(C,60),EncodeColor(colorGreen),EncodeColor(colorRed))+" EMA 15/60 "+WriteVal(EMA(C,15),1.0)+"/"+WriteVal(EMA(C,60),1.0)+" ProfitMth "+WriteVal(profitmth+profit,1.0)+" Bar Secs Left "+ WriteVal(secstogo,1.0)+" "+ "\n"+EncodeColor(colorRed)+" Stoploss " +WriteVal(Trailstop,1.2) ;