Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

Super Trend – Intraday AFL code for Amibroker

1 min read

Super trend is a popular mql strategy converted for the use of intraday amibroker Traders. And you can also watch the same indicator live with various instruments like Nifty , MCX Metals and for few stocks here

Features of the Super Trend AFL code

– Buy and Sell Signals(Green and Red Arrows)
– Trailing stop loss : For Buy signal trailing stop loss is displayed in Green color and for Sell it is Red color
– Template Displaying Buy/Sell Price, Trailing stop loss, Current profit.
– Target Lines T1,T2,T3 (Targets are just a rough estimation and to add value to the AFL code. Its not prediction based)
– Suits lower timeframes like 5min,1min, 15min, hourly timeframe.
– As usual Code is open source. Any body can use it, modify and reuse it.

Nifty Futures 15min charts

Watch Super Trend Trailer
httpv://www.youtube.com/watch?v=WGSBAsGNGnM
[wp_ad_camp_5]

 
Download Non Repainting Super Trend Indicator with time bar left AFL code

For Amibroker version less than 5.3 version

Download Super Trend for Old Amibroker Version

Trend Indicator with the new feature seconds left for the new bar to begin.

I would like each and everyone to go thro the nature of SuperTrend Optimized trading system

– To be honest the trading system accuracy is currently at 42% means out of 100 trades only 42 trades are profitable.

Then how does your wealth is created?
It created with discipline and proper money management to catch those 42% of Winning Trades and Exiting properly at Stop Loss Hits.

What is the maximum continious losses the trading system can yield?
Since 2010 after backtesting with 5min data it is inferred that till to date 9 consecuitve losses had occured. Refer with Bactest results.

What is the Best Paramters to fine tune the system to eliminate more whipsaws?
Optimized Parameters are Multiplier =2 and ATR=11. However the default values of trading system are Multiplier =3 and ATR=10.

For Which Instrument the Trading System is Optimized?
The Trading system is optimized for 5min Nifty Futures charts

Can i trade with Any other stocks/indices?
Stricly No. As the Trading system is optimized for 5min Nifty future charts only.

How to Enter and Exit?

Entry should be based on the completion of the close of 5min Bar Candle. Trade should be executed with 5secs once the 5min candle complete. Trade should not be executed before the completion of 5min bars.

Trade Should be taken only if you see the next bar open. And Strictly not at the intermediate points between the signals.

How many Nifty Future Lots is required to Trade the Trading system?
2 Lots (100 shares) of Nifty at any trades. Size of the trade should not vary throughout the trading system and it is fixed.

Can i trade using the live Buy or Sell indicator?
Charts shown in marketcalls is to study the nature of the trading system to improve your knowledge on trading system. If you are trading based on these buy and sell signals then do it at your own risk. marketcalls wont be responsible for the losses incurred.

Backtest Results
Super Trend Optimized Backtest Results from 1st Jan 2010 – 25th March 2012

Many hours has been spent on making this final code. So give your feedbacks here or mail to [email protected]

Happy Trading!
Rajandran R
Founder – Marketcalls

Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

[Live Coding Webinar] Build Your First Trading Bridge for…

In this course, you will be learning to build your own trading bridge using Python. This 60-minute session is perfect for traders, Python enthusiasts,...
Rajandran R
1 min read

[Webinar] Understanding and Mitigating Curve Fitting in System Trading

"Understanding and Mitigating Curve Fitting in System Trading"! This dynamic session aims to equip novice to intermediate traders, quantitative analysts, and financial engineers with...
Rajandran R
1 min read

P-Signal Strategy Long Only Strategy – Amibroker AFL Code

This tutorial provides an overview of the P-Signal reversal strategy, a quantitative trading strategy that utilizes statistical parameters and error functions to generate probabilistic...
Rajandran R
2 min read

174 Replies to “Super Trend – Intraday AFL code for Amibroker”

  1. Good innovation rajendra .Now a days I am daily visiting to your blog and spending atleast 20 min in a day .
    and your blog is indian wikipedia in indian market .I would like to know how to test this code .

  2. @Dinesh : You need to do backtesting. Goto New Analysis ->Select the AFL file -> Set the Backtesting parameters ->Press backtest button->Click on the report button to view the test results.

    Any How will post short article soon on how to backtest using amibroker

    1. sir iam from bareilly u.p sir i had lost huge amount in mcx now iam in great prolem. sir please help me sir please suggest me that which software i should use to cover my losses, i dont know much about software system and how to use them but ihad a knowledge of physical market. my weaknness is i dont know where to put stopploss and where to take profit. sir please suggest me that i should go for which software. which will have the best results, iwill be very gratefull to you

      1. hi Nitin Agarwal u r still in the market the u can reply me on my email i can help u in this
        i am in delhi

  3. Greetings Brother….

    At the out set GOD BLESS YOU & YOUR FAMILY… before i give you the performance feedback of your AFL,
    I would like to give a feedback on your SELFLESS EFFORTS towards people from trading fraternity…
    RARE is the word for a person like you.. its a very humble work your are doing on the this space here…
    you will definitely get rewarded for all your support to all of us in one or the other way in your life…
    i will keep clicking all the adds on your site everyday as part of my support… thanks for everything…

    Coming back to AFL performance, i just checked the levels where the signals are generated and stunningly
    all are same when it compare to my PAID software…. what else we need??? people make life out of your site
    and bless you through their hearts…

    Great Work
    Take Care

    Shaggy Boo
    Bangalore

  4. Hey Raj,

    Wanted to ask you a Question, If someone needs to learn the basics of Amibroker and how to use that, where can we find Tutorials or guide on that.

  5. @Harshit Patel

    You need to be clear what you are going to learn

    1) Do you want to Build your own trading system – Then you need programming langugage skills to proceed. You can go to the amibroker website and download the AFL guide and proceed with that.

    2)Other wise if you want to test your own trading system and to optimize it then tutors are available in amibroker website itself.

    1. DEAR PRASHANT SIR,

      PLEASE CAN HELP ME OUT AFL CODE FOR BELOW STRATEGY
      I AM USING ONLY SIMPLE INTRADAY CANDLE SYSTEM FOR TRADING ONLY FOR NIFTY &ALL

      FOR EXAMPLE –
      I WANT BUY SELL SIGNAL IN BELOW CONDITION….
      BUY CONDITION :- WHEN MARKET IS UPTREND OPEN AFTER 1 ST 10 MIN IF 5 MIN CANDLE CLOSE ABOVE 3 POINTS COMPARE WITH PRE.CANDLE HIGH THEN WANT SHOW HERE BUY GNAL.
      & MY SL IS CLOSE BELOW 3 POINT OF 1ST 10 MIN CANDLE

      SELL CONDITION :- WHEN MARKET IS IN DOWNTREND OPEN AFTER 10 MIN IF 5 MIN CANDLE CLOSE BELOW 5 POINTS COMPARE WITH PRE.CANDLE LOW THEN WANT SHOW HERE SELL SIGNAL.& MY SL IS CLOSE ABOVE 3 POINT OF 1ST 10 MIN CANDLE

      NOTE – I ALSO WANT TO CONDITION FOR TG 1ST.2ND.3RD..& SO ON FOR BOTH BUY & SELL CONDITION.. FOR EXAMPLE..-(IF BUY SIGNAL SHOW.AT NIFTY 8555 & SL IS 8540 SO MY 1 ST TG IS 15 POINTS)

  6. @Rajandran…….that link gives a code but that does not have any buy sell signal…..etc. Also probably there are different settings…there are more whipsaws….can u please update the settings to the same as your AFL code

  7. @Sidharth : Yes the mql4 doesnt has any signal.

    The default parameters are Factor = 3 and ATR=10 and you can change those parameters for your requirement.

    Factor=Param(“Factor”,3,1,10,1);
    Pd=Param(“ATR Periods”,10,1,100,1);

  8. the last 3 signals(showing on the pic) are same in my software and let me instal the AFL and check it with Ami…

  9. i would say only one thing “god bless U”….U r the lighthouse of traders like us…..

  10. DEAR RAJANDRAN,

    CAN YOU TELL ME WHICH AFL CODE IS USED IN THIS CHART ? IT’S LOOKING VERY GOOD. IS IT POSSIBLE TO MAKE THIS TYPE OF AFL CODE ?

  11. We get different T1,T2,T3 for different time frames.

    I feel they should be the same.

  12. AS FAR AS THE SUPER TREND INDICATOR IS CONCERNED ERROR 29 IS WHAT I AM FACING IT SAYS
    VARIABLE ‘ENTRY’ USED WITHOUT BEING INITIALIZED.

  13. Excellent Code !!

    Can you modify the AFL code to include the output for exploiration so that we can get parameters for all stocks in excel

  14. Hi Rajandran,

    I checked the supertrend, it is not working on 15 minutes timeframe ( not profitable :result (-19.24%)). whereas
    on the 5 minute timeframe, it is giving too many calls, may be some refining on the calls like some filters would help it to be better… have u thought of including volume as an indicator for filtering calls.

  15. @udit

    if you can tell us which system is generating this signal then we can try for it…

    thanks

    Rajesh

  16. Looks very nice but giving error ‘LINE 29 VARIABLE “ENTRY ” USED NOT BEING INITIALIZED PLS HELP

  17. @Nitin Gupta :

    What is your backtesting period?

    I had backtested for 3 years and the results are good and descent . If you want i can share with you

  18. sir i am new to trading… need help…. installed amibroker… and RTDS data for REAL time data…
    amibroker is showing NO data in it… how i would link the RTDS data to amibroker… amibroker data file is empty…
    RTDS has generated all its data in amibroker format and located a file at C:\NSEFUTURESAMI and ther is an other file at C:\Program Files\RTDS

    how i can make this data linked with my amibroker and how can i make my chart look like your chart in the video,,, please help

    thanks … raghu

  19. @Udit

    if its from Nexgen Revolution then the entire AFL is Based of Fimb…

    hope you have not back tested it yet…
    you can check the levels on the same day…. if others then please specify so that we arrive at AFL…
    see the image

  20. Rajendra :-Could you please explain how to test this code .I am very new in amibroker .This can be help for all naw user to explore this new area .If you have any such usefull link then please share us .I tried to dig out from google but not succicde.

  21. @ Rajesh,

    I got its image only from tradaerji.com I am not sure which AFL code are use. But I think it is heikein ashi chart and plot with zigzag indicator. I think it’s B/S signal generate after 4/5 candle (reprint signal). So it is useless.

  22. Rajandran….as usual,you are on cherryon top of the cream…let me test this.but as per ur glorious record…it should be fine.
    God Bless you for your selfless & tireless efforts!!!

    Amirishali

  23. THERE IS ERROR IN SUPER TREND AFL. CAN U HELP I AM ATTACHING JPEG FILE.

  24. Hi sir,

    please sir kindly give us a solution , i am using amibroker 5.20 and getting error 29 –
    variable ‘entry’ used without being initialized .. …

    please please – this super trend afl is looking so good , thanks to you, but not able to use it because of error — please help

  25. Dear Raj…

    is it possible to make an alert out to show the list of all latest alerts generate through this AFL?

    is yes please let us know how to do it?

    regards

    shaggy boo

  26. Sir, the afl is giving error 29.

    variable ‘ entry’ used without being initialized ,
    please help,

    this looks so good, but because of error not able to use it ,

    my amibroker ver 5.2

    thanks for your great work, but please help with this error soon,

    cant wait to see it working fast

  27. Dear Rajandran,

    First so many thanks for this super trend AFL. Today its give amazing result in nifty. Good job, keep it up.

  28. Dear Rajandran,

    First so many thanks for this super trend AFL. Today its give amazing result in nifty. Good job, keep it up.

  29. Dear Rajandran

    I downloaded your super trend afl and used it. its very useful. Thanks a lot. More over i want to appreciate and say thanks to your SELFLESS EFFORTS.

  30. Dear Rajendra

    Can you please tell me how can we conver Mql4 to Afl Or Afl in Mql for . Can u please guide me in this

  31. Hi Rajandran,
    i am unable to backtest. Will u pls share backtesting reults for couple months depending on timeframe.
    And most important, on which which timeframe best results are seen….5min or 15 min.

    pls revert back

  32. hi
    i don’t understand how my recent post has vanished Hence posting again.
    Rajandran i am unable to backtest.Wil u pls share backtesting resuts for couple month.
    And on which timeframe best results are seen? 5min or 15 min

  33. Rajandran, one more thing. As most of us are intraday aspirant traders/players.
    In your backtesting, my sense you will be giving arithmetic of plain entry and exit calcuations and returns and cumulative points etc. But it will be better if u can also add how many instances call was able to get xyz points, the bare minium points at which most of day traders look as first target.Some take as 15 or 20 or 25 depending on their mindst and brokerage.
    Today, Nifty FUTURE as per super trend gave a sell @5103 09.45 and reverse long came at 5106 11.10. So at first glance, it was a loss of 3 points. But there was a dip to 5072 means was a chnce of booking 15/20/25 points depending on persoanl first target level.I am aware of super trend’s T1/T2/T3. But i am talking about bare minium first target.Also you are welcome with analysis of supertrend’s T1/T2 achieved.

    Hope u get my point..

  34. Sir,

    I am using Amibroker 5.1. Today I have add your Super Trend Afl Code in my Amibroker 5.1 ver but it is showing error 29. Sir pls rectify and give at your earliest will me a Great needfull, also for Mr.Ajay choudhary & Mr.Mohsin. Expecting your reply very eagerly. Bye.

  35. Sir,

    I am using Amibroker 5.1. Today I have add your Super Trend Afl Code in my Amibroker 5.1 ver but it is showing error 29. Sir pls rectify and give at your earliest will do me a Great needfull, also for Mr.Ajay choudhary & Mr.Mohsin. Expecting your reply very eagerly. Bye.

  36. Sir

    I am using Amibroker 5.1 Ver. I am very much impressed by your Super Trend Afl Code and added in my Amibroker 5.1 Ver but it is giving error 29. Hence pls rectify & give at your earliest will do me a Great Needfull. Thank you. Bye.

    1. It will be overloading my server. So currently not including it. Other wise in need to rent another server which is again costlier.

  37. Hi Is This System Look In To Future Like Other System If Yes Then It’s Useless To Do Backtest And Use In Realtime

  38. Hi Rajandran R

    Many Of My Friends Using SuperTrend (ATR Length 5,ATR Multiplier 1,HighLow Bars 5) of FALCON software
    and i heard it gives excelant result and narrow stoploss for nifty and Banknifty (30Minites) Time Frame. And as per their record it gives highest return in backtest also

    I Tried Same Parameters In Amibroker in Your Super Trend afl file But it is not giving the same signals,

    I am encloseing niftycash5min.jpg file for your referance

    Hoping your early reply with best solution.
    Thanks

  39. Hi Rajandran R
    I Was serching supertrend formula for my amibroker since last 2 months i found best formula from your site.
    Many Of My Friends Useing Supertrend System (ATR Length 5days, ATR Mulitiplier 1 , Highlow Bar 5)
    For Nifty / Bank nifty in 30 miniutes time frame and it gives best result with narrow stoploss.

    I Change Parameters as per above mention in amibroker. But its not giving same indication as falcon software is giving. I enclosed please find nifty cash 5 min.jpg file for your referance.

  40. Hi Rajandran R
    I Was serching supertrend formula for my amibroker since last 2 months i found best formula from your site.
    Many Of My Friends Useing Supertrend System (ATR Length 5days, ATR Mulitiplier 1 , Highlow Bar 5)
    For Nifty / Bank nifty in 30 miniutes time frame and it gives best result with narrow stoploss.

    I Change Parameters as per above mention in amibroker. But its not giving same indication as falcon software is giving. I enclosed please find nifty cash 5 min.jpg file for your referance.

    Hopeing your best solution for the same

  41. many thanx for this afl, its near pro afl. now in parameter what to set for factor from 1,2,3

  42. HI,
    I HAVE JUST MIXED YOUR OLD & NEWER {FOR OLDER VERSIONS} AFL FOR SUPER TREND B’CAUSE THE NEWER VERSION WAS NOT SHOWING MASSAGE BOARD CHECK OUT & REPLY

    /* Done by Rajandran R */
    /* Author of http://www.marketcalls.in */

    _SECTION_BEGIN(“Price”);
    SetChartOptions(0,chartShowArrows|chartShowDates);
    _N(Title = StrFormat(“{{NAME}} – {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}”, O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
    Plot( C, “Close”, ParamColor(“Color”, colorBlack ), styleNoTitle | ParamStyle(“Style”) | GetPriceStyle() );
    _SECTION_END();

    /* Done by Rajandran R */
    /* Author of http://www.marketcalls.in */

    _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”,3,2,10,1);
    Pd=Optimize(“ATR Periods”,10,1,20,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]<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) {
    flag=1;
    }
    else {
    flag=0;
    }

    if (trend[i]>0 && trend[i-1]0 && Dn[i]<Dn[i-1]){
    Dn[i]=Dn[i-1];
    }

    if (trend[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 http://www.marketcalls.in” + ” – ” + Name() + ” – ” + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
    ” – ” + Date() +” – “+”
    ” +EncodeColor(colorRed) +”Op-“+O+” “+”Hi-“+H+” “+”Lo-“+L+” “+
    “Cl-“+C+” “+ “Vol= “+ WriteVal(V)+”
    “+
    EncodeColor(colorLime)+
    WriteIf (Buy , ” GO LONG / Reverse Signal at “+C+” “,””)+
    WriteIf (Sell , ” EXIT LONG / Reverse Signal at “+C+” “,””)+”
    “+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 <BarCount;i++)
    {
    PlotText(""+sig+"@"+entry, BarCount+1,entry,Null,colorBlue);
    PlotText("T1@"+tar1,BarCount+3,tar1,Null,Clr);PlotText("T2@"+tar2,BarCount+3,tar2,Null,Clr);PlotText ("T3@"+tar3,BarCount+3,tar3,Null,Clr);

    }

    messageboard = ParamToggle("Message Board","Show|Hide",1);
    if (messageboard == 1 )
    {
    GfxSelectFont( "Tahoma", 13, 100 );
    GfxSetBkMode( 1 );
    GfxSetTextColor( colorWhite );

    if ( sig =="BUY")
    {
    GfxSelectSolidBrush( colorBlue ); // this is the box background color
    }
    else
    {
    GfxSelectSolidBrush( colorRed ); // this is the box background color
    }
    pxHeight = Status( "pxchartheight" ) ;
    xx = Status( "pxchartwidth");
    Left = 1100;
    width = 310;
    x = 5;
    x2 = 290;

    y = pxHeight;

    GfxSelectPen( colorGreen, 1); // broader color
    GfxRoundRect( x, y – 98, x2, y , 7, 7 ) ;
    GfxTextOut( ( "Marketcalls – Supertrend"),13,y-100);
    GfxTextOut( (" "),27,y-100);
    GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-80) ; // The text format location
    GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-60);
    GfxTextOut( ("Trailing SL : " + TrendSL + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-40);
    /*GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
    GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
    GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);*/
    GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-22);;

    }

    _SECTION_END();

  43. SIR I WANT ONE MORE HELP FROM YOU. AS I TOLD YOU I DID LITTLE BIT EDITING OF YOUR BOTH SUPER TREND VERSIONS FOR BORD DISPLAY BUT FOR THE LOWER VERSION IT SHOWS NOTHING IN PARAMETER BOX SO IF I HAVE TO CHANGE ATR LINE OR MULTIPLIER I HAVE TO GO TO AFL CANT EDIT IT FROM PARAMETERS WINDOW PLS HELP … OR DO REPLY A.S.A.P.

    THNX IN ADVANCE

  44. Hi Rajendran,

    Am new to intraday trading in Nifty futures and Bank Nifty futures.
    Been watching your Super Trend live charts. ( not working today though !)
    Am very impressed with the results. How can I get this onto y desktop?
    Am on icicidirect Traderacer.

    Advance thanks, best regards.

  45. Thanks. Got the site.

    Can something like this be configured in icicidirect Traderacer software?

  46. Dear Rajandran,

    Very much inspired by your work and the help you are providing to all. I m new to the amibroker and I have version 5.2. I downloaded the .afl from this page, but after running the same, I m not able to get the same kind of graph which you have mentioned or the one that is shown in the youtube. Can you pls send me the .afl code to my mail address, [email protected]. Thanks in advance.

    Regards
    Ram

  47. Hi,

    I would want to use this AFL code in my newly purchased Amibroker software.
    Sorry to bother but can some one reply or email ([email protected]) on how to add this .zip file or any other AFL code (.txt) into my Amibroker and start using / testing it?
    I would highly appreciate your support / help in this regard.

    Thanks.
    Swetal

  48. Hi Rajandran,

    Super trend is working fine with MT platform. I have one query, can we predict a trend, either up or down, will go for a long time so that we can put our position in that to get maximum return. OR can we get signal of trend reversal few sticks earlier so that we can close out current position and quit so that we could not trap in reverse trend, losing our profit. If yes please tell.

    Thank you for super SUPERTREND

    Yogesh

    1. Its tough to predict even a structured market in lower timeframes where you dont know when it reacts and when it turns/twists its direction. Its tough to predict a sideways market though prediction tools like Elliot Wave, GANN are available. But the problem is that the risk involved in such system are tough to evaluated.

  49. @ Swetal
    From your amib upper tool bar click on ‘Formula Editor’ ( icon resembles hammer) and just copy paste that code from text file and save that AFL to desired sub- folder under Formuals.

  50. Hi
    please tell me how to install amibroker and how to add AFL and after done all things, how to run real time data free as can do in mt4..

    hope you will guide me step by step

    Thanks

  51. Very very thanks Rajandra for your code. I have recently purchased Amibroker Professional and made and tried many system, But today i found your super trend and I visualize it on 3-min IEOD data of Nifty future and found excellent.

    But when I back tested I found it giving negative results can you please tell me what position size, periodicity and equity, margin and brokerage to be used when backtesting to get original results as we see in the charts.

    I am going to trade your system for next month and I am sure will get huge profit, obviously with my own risk.

    Once again very thanks for your help.

    Rakesh

  52. hi mr.rajendra am a s/w engg. student i want to learn creating such s/w so can you tell me which programming language and platform used to built Amibroker Software .AFL thanks

    1. Hi All friends
      I just like to know step by step how to install amibroker and after that how to use this indicator and main part that how to get real time data free to run this indicator…

      Hope I will get my solution….

      thaks

  53. i wanna to buy supertrend afl software for option and mcx…………plz tell me from where and with charges……….

  54. Average True Range (ATR)
    Introduction

    Developed by J. Welles Wilder, the Average True Range (ATR) is an indicator that measures volatility. As with most of his indicators, Wilder designed ATR with commodities and daily prices in mind. Commodities are frequently more volatile than stocks. They were are often subject to gaps and limit moves, which occur when a commodity opens up or down its maximum allowed move for the session. A volatility formula based only on the high-low range would fail to capture volatility from gap or limit moves. Wilder created Average True Range to capture this “missing” volatility. It is important to remember that ATR does not provide an indication of price direction, just volatility.

    Wilder features ATR in his 1978 book, New Concepts in Technical Trading Systems. This book also includes the Parabolic SAR, RSI and the Directional Movement Concept (ADX). Despite being developed before the computer age, Wilder’s indicators have stood the test of time and remain extremely popular.
    True Range

    Wilder started with a concept called True Range (TR), which is defined as the greatest of the following:

    Method 1: Current High less the current Low
    Method 2: Current High less the previous Close (absolute value)
    Method 3: Current Low less the previous Close (absolute value)

    Absolute values are used to ensure positive numbers. After all, Wilder was interested in measuring the distance between two points, not the direction. If the current period’s high is above the prior period’s high and the low is below the prior period’s low, then the current period’s high-low range will be used as the True Range. This is an outside day that would use Method 1 to calculate the TR. This is pretty straight forward. Methods 2 and 3 are used when there is a gap or an inside day. A gap occurs when the previous close is greater than the current high (signaling a potential gap down or limit move) or the previous close is lower than the current low (signaling a potential gap up or limit move). The image below shows examples of when methods 2 and 3 are appropriate.

    ATR – True Range Image

    Example A: A small high/low range formed after a gap up. The TR equals the absolute value of the difference between the current high and the previous close.

    Example B: A small high/low range formed after a gap down. The TR equals the absolute value of the difference between the current low and the previous close.

    Example C: Even though the current close is within the previous high/low range, the current high/low range is quite small. In fact, it is smaller than the absolute value of the difference between the current high and the previous close, which is used to value the TR.
    Calculation

    Typically, the Average True Range (ATR) is based on 14 periods and can be calculated on an intraday, daily, weekly or monthly basis. For this example, the ATR will be based on daily data. Because there must be a beginning, the first TR value is simply the High minus the Low, and the first 14-day ATR is the average of the daily TR values for the last 14 days. After that, Wilder sought to smooth the data by incorporating the previous period’s ATR value.

    Current ATR = [(Prior ATR x 13) + Current TR] / 14

    – Multiply the previous 14-day ATR by 13.
    – Add the most recent day’s TR value.
    – Divide the total by 14

    ATR – Spreadsheet

    Click here for an Excel Spreadsheet showing the start of an ATR calculation for QQQQ.

    In the Spreadsheet example, the first True Range value (.91) equals the High minus the Low (yellow cells). The first 14-day ATR value (.56)) was calculated by finding the average of the first 14 True Range values (blue cell). Subsequent ATR values were smoothed using the formula above. The spreadsheet values correspond with the yellow area on the chart below. Notice how ATR surged as QQQQ plunged in May with many long candlesticks.

    ATR – Chart 1

    For those trying this at home, a few caveats apply. First, ATR values depend on where you begin. The first True Range value is simply the current High minus the current Low and the first ATR is an average of the first 14 True Range values. The real ATR formula does not kick in until day 15. Even so, the remnants of these first two calculations linger to slightly affect ATR values. Spreadsheet values for a small subset of data may not match exactly with what is seen on the price chart. Decimal rounding can also slightly affect ATR values.
    Absolute ATR

    ATR is based on the True Range, which uses absolute price changes. As such, ATR reflects volatility as absolute level. In other words, ATR is not shown as a percentage of the current close. This means low priced stocks will have lower ATR values than high price stocks. For example, a $20-30 security will have much lower ATR values than a $200-300 security. Because of this, ATR values are not comparable. Even large price movements for a single security, such as a decline from 70 to 20, can make long-term ATR comparisons impractical. Chart 4 shows Google with double digit ATR values and chart 5 shows Microsoft with ATR values below 1. Despite different values, their ATR lines have similar shapes.

    ATR – Chart 4

    ATR – Chart 5
    Conclusions

    ATR is not a directional indicator, such as MACD or RSI. Instead, ATR is a unique volatility indicator that reflects the degree of interest or disinterest in a move. Strong moves, in either direction, are often accompanied by large ranges, or large True Ranges. This is especially true at the beginning of a move. Uninspiring moves can be accompanied by relatively narrow ranges. As such, ATR can be used to validate the enthusiasm behind a move or breakout. A bullish reversal with an increase in ATR would show strong buying pressure and reinforce the reversal. A bearish support break with an increase in ATR would show strong selling pressure and reinforce the support break.
    SharpCharts

    Listed as “Average True Range”, ATR is on the Indicators drop-down menu. The “parameters” box to the right of the indicator contains the default value, 14, for the number of periods used to smooth the data. To adjust the period setting, highlight the default value and enter a new setting. Wilder often used 8 period ATR. SharpCharts also allows users to position the indicator above, below, or behind the price plot. A moving average can be added to identify upturns or downturns in ATR. Click “advanced options” to add a moving average as an indicator overlay. Click here for a live example of ATR.

  55. I have Amibroker 5.5 and Super trend AFL.IT work fine i can see buy sell signal But It shows Error 29 when i scan..so i am not able to scan the signal at right time can you please help how to rectify that?
    thanks in advance

  56. Hi,
    Sir in sacnning supper trend i am getting error like }

    }

    Offset = 20;

    Clr = IIf(sig =
    ————–^

    Error 29.
    Variable ‘sig’ used without having been initialized.

    How can i solve this pls explain me.

    Thanx

  57. Couls you please advice on how to code for exiting all open position by eod ,i was given
    no_trading = TimeNum() > 152000;
    Buy = ..your rules AND NOT no_trading;
    Sell = ..your rules… OR no_trading;
    But it does not work,any suggestions?

    1. @mithoon

      try this one

      tradingtime = TimeNum() < 152000; exittime = TimeNum() > 152000;
      Buy = ..your rules AND tradingtime;
      Sell = ..your rules… OR exittime

  58. Hi Raj

    Installed your super trend today, the first time when manshi rt opened amibroker it showed the box on the left side where you inform last buy/sell call sl etc. I closed amibroker lot of pain went in actually getting odin data in amibroker and finally data came in to amibroker. Your buy sell is also appearing for previous day. But today (saturday) is not getting updated.

    My question is does your code not work on Saturday ??. Does it work only on weedays? Also I am trying to use your indicator for commodities, will that be a problem?

    I also have another question, is it not possible for your code logic to be somehow put directly in ODIN?

  59. Error 29: variable ‘entry’ used without having been initialsed.. Line 217 column 75 showing error sir.. can u help

    GfxTextOut( (“Current P/L : ” + WriteVal(IIf(sig == “BUY”,(C-entry),(entry-C)),2.2)), 13, y-22);;

  60. please give me the correct afl for supertrend . bec currently i see the image for supper trend …. stop loss are not correct …

    example : sell 540 tr 530 sl 542 this is correct

    currently i see the sell trade sell 540 tr 530 sl 538

    ????

  61. I’m using manshiRT demo for data & having 5 days of backfill data.. used with all the commodities same error showing.. Or u can explain any method of using the afl as I haven’t used any before..

  62. I tried the supertrend AFL Code,but i do get error of entry variable not initialized

    I went through the forum there was not solution given to that problem 🙁

    version : 5.6 latest

  63. I’m also using Amibroker 5.6.. there is no solution anywhere.. I have given the images of the error.. plz sort it out.. nothing is helping.. plz enlighten.. Ur video above is only showing bar replay..
    Is there any other video which can help in this error.. plz give d link..

  64. Hi Raj

    first of all god bless you for coming up the afl code, i know as you said accuracy is about 42% or whatever the figure is, however i just want to say that now either i get out at cost or maybe 1 or 2 ticks above my cost either way i am not losing money. earlier i used to take heavy losses now atleast my losses have come down. god bless u once again. making money is in your fate, if i make good if i dont its not fate, but with ur afl code atleast i wont lose a lot.

  65. Sir,
    The Super Trend AFL code is it valid only for intraday using Amibroker? Can you provide Super Trend AFL code for Short Term(1-3 weeks) and long term (1-3 months) Periods. Iam very much thankful to you.

  66. SIR, At present i am using ticker plants super trend, in which multiplier is 3 and period is 10.would you suggest 2 and 11 instead of 3 and 10.

  67. Thank Rajandran for the useful code of super trend. Sir, when I used the function “new analysis” to scan the categories, an error, namely “Error 29. Variable ‘entry’ used without having been initialized. (Ln: 217,Col:75) ocurred. I used “Non Repainting Super Trend Indicator” for Amibroker, version 5.5. Please help me correct the error. Many thanks.

  68. Sir, I am Ravi from Erode, I like your amibroker chart. I like to contact you I want your cell No. Please reply immediately.

  69. I ran into your program on the AB Yahoo Group site but it was not your entire version but one posted by Ed Pottasch. I am not a day traded but a EOD trader. The formula appeared to target changes in Trend which I want to use as trade signals in trading ETF’s long/short (pairs trading) . There are over 100 Long/Short ETF Pairs.
    I would appreciate if you could send me the necessary changes to the program so it will work on a EOD basis. I especially like the PopUP (red) but it is useless with current time periods so a change to daily would be most appreciated. Thanks
    Dick

    Dick

  70. Raj,
    This is in follow up to my recent post. I find the Super Trend formula (without the red message board and black background to be more accurate on trend Buy/Sell arrows than the aforementioned newer one. This is based on the long/short silver ETF’s (USLV & DSLV) Why so? As I presume same basic formula used.
    I do like the “Message board” box but would like to get version (tell me how to change) so that daily time period rather than minutes or seconds. Your help on this will be most appreciated. Thanks

    Dick Hoierman
    [email protected]

    1. HI Dick Hoierman,

      Which Amibroker version you are using. If you are using less than 5.4 then the supertrend code wont support dashboard

      Rajandran R

  71. Thanks Raj,
    I’m using 5.60.3 version … which works fine. Will look forard to Dashboard for Daily.

    Dick

  72. Your super trend formula for amibroker is excellent – the only drawback for me is that it is an automated formula system, and also to change the parameters I have to use the edit function. It would be great if you can make a minor modification wherein we can change the settings in the parameters menu. Unfortunately I am not skilled in programming.
    I would also like to know how to plot only the lines of the supertrend on to the price chart itself with an ability to change the parameters from the parameter menu

  73. OOps , I am using the older version of the code, but I would still like to plot only the lines on the bar charts. please do help.
    thank you,
    vin

  74. Dear Raj,
    You are Outstanding man!!!!I am soft engineer and i was just trying to understand the Super Trend AFL code it is fantastically presented but I have one doubt in you code basically i was just trying out first in Excel by creating same set of variables you have created in it. The only doubt I am having is while initializing the values of first time againt Dn and UP variable what should I set also similarly what should be initialize value for Dn-1 and Up-1 since there will not be any values against it. I would appreciate if you help me out in resoving thsi issue. If need I can attache my excel sheet …..pls help!!!

  75. Sir,
    I have checked this afl for current nifty future. This is not working now (going in loss). Can you tell me why it is now not working?

    Thanks in advance.

  76. Hi Rajandran,

    The code gives an error at line 217 col 75 that “entry” is not initialized. Could you please let me know the fix for it??
    Thanks for advance!!

    1. Make sure that you are using amibroker ver above 5.4 and suffcicient backfill data atleast 50 candles are required to plot the indicator

  77. You are a great guy helping us. Your backtesting shows results for futures, Can I use the same AFL for options data ? Would it have the similar results ? What will be the changes I would have to make to the AFL script, if any ?

  78. Hello Friends, Can some one help me on how to add this AFL indicator to Amibroker please ?

  79. I”m getting below error. Can you please help
    (I’m using amibroker 5.4 rc2 version)

  80. I’m getting below error. please help. I’m using amibroker 5.4 rc2 version.

    Error 29.
    Variable ‘sig’ used without having been initialized.

  81. Raj, I tried the supertrend strategy on Nifty 5Mins for the period August 2012 to July 2013 with the same parameter of 2 and 11. The strategy has lost 8% during this period against 11% gain on Nifty (this is excluding the cost). I also tried with Nifty 60 Mins and Gold 60 and 5 Mins, the results are not satisfactory as the strategy lost money in most cases. Does this strategy really work? Has any one traded on live basis and made money? How can I improvise the strategy so that it really makes money in real trading.

    1. @Kannan : The Finetuned parameters for Nifty futures is 3 and 7 in 5min. And backtest should be done with atleast with 2-3 years of data to look into the actual result. with three or four month of backtesting we can judge the entire strategy performance.

      1. @ Raj, may be my trade logic needs to be corrected. I buy when current close is greater than previous supertrend value and vice versa for sell; no stop as it a toggle. Is this logic correct? Also, what is the optimized parameters for Nifty 60Mins?

  82. hii,
    what is default name of the array used for storing the price’s of intraday stocks ? So i can use it while coding my strategies. I know I am asking very basic question but I am quite new to use this.Please help me.

  83. I saw your backtesting results for NIFTY Future. At what price do you book the profits in the backtesting ? Do you book first lot at first target and second lot at trailing stop loss ?

  84. Dear Raj sir,

    Thnks a lot very much for your supertrend.
    I tried back testing MCX crude oil with your back testing video reference for the five months data in 2010 but its giving negative results.May be i m doing some wrong can you pls asssit me in this or is it possbile for you to share the back test results.

    Regards
    Priya

  85. Hi Raj,
    In the newer version, your magnified market price is behind the background. Is it because of the layer? How can i bring it to front? Also, your message box is invisible. Do the code need to be update incorporating the zorder? How can this be displayed? Pls suggest.

  86. Dear Mr.Rajendran,
    I would like to Buy AMIBROKER software and also I need SUPER TREND . Will you help me in this regards. I look forward your favourable reply at the earliest.

    Kind regards,
    Shankar,

  87. i have amibroker,i want super trend to trade in nifty/banknifty,please send me details,

    HARE KRISHNA
    Siddesh TM
    9900162253

      1. Yes I have done as you mention Axes/Grids And Uncheck all The Option still it is not showing Messageboard

  88. Dear Mr.Rajendran,
    Even I would like to Buy AMIBROKER software and also I need SUPER TREND . Will you help me in this regards. the same msg which Shankar send you before. Pls, I look forward your favourable reply at the earliest.

  89. Dear Rajendran,

    Can you please share me the super trend excel formula.
    I would like to calculate it thru excel. Please help me.

  90. Dear Mr.Rajendran,
    I would like to Buy AMIBROKER software and also I need SUPER TREND . Will you help me in this regards. I look forward your favourable reply at the earliest.

    Kind regards,
    SIVA

  91. Dear Mr Rajendran
    can you please explain me how to interpret super trend for old amibroker

      1. Sir thank you for your reply
        what i want to know is when i am running analyzer for old super trend using EOD data, 98% of buy signals given are turning in to loss makers, some times loss is beginning in the very next trade itself.
        I am using amibroker 5.0

  92. Hi Rajendran,

    I have modified the Super trend, and signals are reversed if the High/Low touches the TrendUp/TrendDown line. I have done this to achieve 2 things.

    a) Reducing the Slippage (As the Stoploss order is already with server and there is no delay when the signal is generated and order execution. This is helpful in volatile markets.)

    b) I can trade multiple scripts at the same time as my automated trading system will not work when the multiple orders are generated at the same time.

    Further some of the features are:
    1) I am using the ATR -6 and Multiplier-4 and 10 min TF

    2) I keep trailing the Stoploss as mentioned in step 1.

    3) My setup is fully automated and runs on the VPS.

    Last 3 months I am not getting good results. I would like to know if I am doing anything wrong?
    Can you share the performance of the ST used by you for last 3 months?

  93. I want only last trade signals in Alert Output window.I am using following code.But it is not giving desired results.Pl. see image and correct the code.
    barcomplete = BarIndex() < LastValue(BarIndex());

    AlertIf( barcomplete AND (Buy OR Short), "", "Text", 1+8 );

    regards

    bharat

  94. Hello Rajandran sir can you please share the exploration code for supertrend indicator

  95. Sir could you please give SuperTrend Afl with settings of 10 & 4. Please i need it very urgently.
    Thanks

  96. sir i download it for super trend my amibroker eror 42 is show how t instel this plz help me

  97. Hi Raj, Thanks for the knowledge you are sharing.
    can i please request you to share the super trend logic, so i can transform the same in TradeScript – modulus code.

    Please let me know at the earliest. Apologies if you dont want to share.

  98. Dear Sir,

    as i have mentioned in previous mail that i m now trading with Super trend V3 and trading in Nifty only –not even bank nifty . As of now my losses are stopped now and started covering my lost money . I am trading with Robo Trader with your Afl. My trading style is whenever signal comes my robo execute the order and when 0.55% price moves it books 50% profit (2 LOTS OF NIFTY) and remaining 50% with trailing stop loss of 0.50%.

    thanx a lot for this afl

    my query is this that youn mentioned in someones reply of 22nd may 2014 that you will soon bring an or working on to minimize the carry forward risk . If you have done so then pls send the same link pls .

    second thing ….is the trend blaster is something different i mean can be used for stocks and if you have that kindly send the link .

    thnx in advance

    sameer chaturvedi

  99. How to solve “Variable “entry” used without having been initialized in intraday

    GfxTextOut( (“Current P/L : ” + WriteVal(IIf(sig == “BUY”,(C-entry),(entry-C)),2.2)), 13, y-22);;

    1. Dear kiran sir
      I want AFL code as per my technique . can u please help me..please send me ur I’d so I can send u the details.wating for u r reply my I’d – shreyas4us@ gmail.com

  100. Dear Rajandran,

    How can I find sharp growth of stocks for a month?
    I work with daily data. I am looking forward to hearing from you.
    Thanks in advance for your consideration.

    Bests,
    Siamak

  101. when i am using super trend for exploration iam getting following error

    can you please help with this error ” variable ‘trend” used without being initialised.

  102. Hi sir, i m interested in configuring my own robo trading with afl. No matter even if it requires coding for every single scrip. I dont understand how start and configure robo configuration for amibroker

  103. Hi Sir,
    Please let me know what is the change i should do for “1 factor and 2 length parameter”?
    Factor=Param(“Factor”,1, 1, 2, 1);
    Pd=Param(“ATR Periods”,2, 1, 10, 1);
    the above changes does not reflect .

    I was using below factor and length and was working perfect
    Factor=Param(“Factor”,4,1,10,1);
    Pd=Param(“ATR Periods”,10,1,100,1);

    But when I change it to 1factor and 2 length I cannot see any changes in the graph.

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More