/* Done by Rajandran R */ /* Author of www.marketcalls.in */ /* Date : 10th Dec 2014 */ 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; } _SECTION_BEGIN("SuperTrend Ver 3.0"); SetBarsRequired(100000,0); GraphXSpace = 15; SetChartOptions(0,chartShowArrows|chartShowDates); SetChartBkColor(ParamColor("bkcolor",colorPaleGreen)); GfxSetBkMode(0); GfxSetOverlayMode(1); SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey))); Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0); // Initial Values overrides you backtesting settings /* SetOption( "InitialEquity", 100000); SetOption("FuturesMode" ,false); SetOption("MinShares",1); SetOption("CommissionMode",2); SetOption("CommissionAmount",0); SetOption("AccountMargin",100); SetOption("RefreshWhenCompleted",True); SetTradeDelays(0,0,0,0);*/ SetPositionSize(100000,spsvalue); _N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) )); Factor=Param("Factor",4,1,10,0.1); Pd=Param("ATR Periods",10,1,100,1); Up=(H+L)/2+(Factor*ATR(Pd)); Dn=(H+L)/2-(Factor*ATR(Pd)); iATR=ATR(Pd); TrendUp=TrendDown=Null; trend[0]=1; changeOfTrend=0; flag=flagh=0; for (i = 1; i Up[i-1]) { trend[i]=1; if (trend[i-1] == -1) changeOfTrend = 1; } else if (Close[i]0) { flag=1; } else { flag=0; } if (trend[i]>0 && trend[i-1]<0) { flagh=1; } else { flagh=0; } if (trend[i]>0 && Dn[i]Up[i-1]) { Up[i]=Up[i-1]; } if (flag==1) { Up[i]=(H[i]+L[i])/2+(Factor*iATR[i]);; } if (flagh==1) { Dn[i]=(H[i]+L[i])/2-(Factor*iATR[i]);; } if (trend[i]==1) { TrendUp[i]=Dn[i]; if (changeOfTrend == 1) { TrendUp[i-1] = TrendDown[i-1]; changeOfTrend = 0; } } else if (trend[i]==-1) { TrendDown[i]=Up[i]; if (changeOfTrend == 1) { TrendDown[i-1] = TrendUp[i-1]; changeOfTrend = 0; } } } Plot(TrendUp,"Trend",colorGreen); Plot(TrendDown,"Down",colorRed); Buy = trend==1; Sell=trend==-1; Buy=ExRem(Buy,Sell); Sell=ExRem(Sell,Buy); Short=Sell; Cover=Buy; SetTradeDelays(1,1,1,1); BuyPrice=Open; SellPrice=Open; ShortPrice=Open; CoverPrice=Open; Title = EncodeColor(colorWhite)+ "Super Trend AFL code from www.marketcalls.in" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) + " - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+ "Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+ EncodeColor(colorLime)+ WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+ WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorYellow)+ WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+ WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"",""); PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40); PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50); PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40); PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50); PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45); TrendSL=IIf(trend==1,TrendUp,TrendDown); for(i=BarCount-1;i>1;i--) { if(Buy[i] == 1) { entry = C[i]; sig = "BUY"; sl = TrendSL[i]; tar1 = entry + (entry * .0050); tar2 = entry + (entry * .0092); tar3 = entry + (entry * .0179); bars = i; i = 0; } if(Sell[i] == 1) { sig = "SELL"; entry = C[i]; sl = TrendSL[i]; tar1 = entry - (entry * .0050); tar2 = entry - (entry * .0112); tar3 = entry - (entry * .0212); bars = i; i = 0; } } Offset = 20; Clr = IIf(sig == "BUY", colorLime, colorRed); ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1)); sl = ssl[BarCount-1]; Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset); Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset); Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset); //Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorDarkRed, styleLine|styleLine, Null, Null, Offset); //Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset); /* for (i=bars; i