Can anyone provide tradescript code for Supertrend Signal?

Supertrend is coded in afl programming langauge which is bit advanced than tradescript. So i guess supertrend cant be coded in Tradescript.

check it your self.

it get from web.

_SECTION_BEGIN(“SuperTrend”);
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot( C, “Close”, ParamColor(“Color”, colorBlack ), styleNoTitle |
ParamStyle(“Style”) | GetPriceStyle() );

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g,
Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

PositionSize = 100000;

Factor=Optimize(“Factor”,2,2,10,1);
Pd=Optimize(“ATR Periods”,11,1,20,1);
Up=(H+L)/2+(FactorATR(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 <BarCount-1; i++) {
TrendUp[i] = Null;
TrendDown[i] = Null;

  trend[i]=1;

if (Close[i]>Up[i-1]) {
trend[i]=1;
if (trend[i-1] == -1) changeOfTrend = 1;

  }
  else if (Close[i]<Dn[i-1]) {
     trend[i]=-1;
     if (trend[i-1] == 1) changeOfTrend = 1;
  }
  else if (trend[i-1]==1) {
     trend[i]=1;
     changeOfTrend = 0;       
  }
  else if (trend[i-1]==-1) {
     trend[i]=-1;
     changeOfTrend = 0;
  }

  if (trend[i]<0 && trend[i-1]>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]<Dn[i-1]){
     Dn[i]=Dn[i-1];
    }
  
  if (trend[i]<0 && Up[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;

BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);

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

_SECTION_END();

Folks,

There is so much fuss about this supertrend indicator. Let me clear the air a bit. It is also called ‘ATR trailing stop’ or vervoort stop indicator ( http://traders.com/documentation/FEEDbk_docs/2009/06/Vervoort.html ) and its been around from 2002.

It is not true that it is available only for Amibroker. As a matter of fact, this indicator is available in 16 different languages and you can find them in the below pasted link. Am sure someone would be able to do it in tradescript or it might already exist in the below link.

http://traders.com/documentation/FEEDbk_docs/2009/06/TradersTips.html

Hope it helps.

–Madan

2 Likes

Friends, I decide to trail my stop using SuperTrend indicator. Can I know what should be the ‘Period’ and ‘Multiplier’ pls? Any suggestions?