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)

Supertrend Multi Timeframe Based Trading System – Amibroker AFL Code

41 sec read

Here is the first prototype from Marketcalls which demonstrates multi-timeframe based trading system which compares two timeframes (5min and hourly in this case) and takes a trade decision based on both the timeframes. To demonstrate with simple example we used supertrend on 5min timeframe and Hull RSI on the hourly timeframe to filter unwanted trading signals.

Trading Logic

Go long if Hourly HRSI is trending upwards and Supertrend turns to buy mode on 5min charts
Exit long if Supertrend turns to sell mode (i.e Trailing Stop hits on closing basis) on 5min charts

Go Short if Hourly HRSI is trending downwards and Supertrend turns to short mode on 5min charts
Exit Short if Supertrend turns to sell mode (i.e Training Stop hits on closing basis) on 5min charts

Bank Nifty Futures showing Supertrend Along with Hourly HRSI indicator as a filter

Download Supertrend with Multitimeframe Filter – Amibroker AFL Code

Here is the backtested results for Bank Nifty Futures (5min charts) Since SEP 2010 onwards with Brokerage + Other Transaction costs added as 0.02%
Max open position is taken based on 15% of the available capital.

Equity Curve

Drawdown

Download the Backtest Result

Multi Supertrend V3.0-20170224141735498

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

27 Replies to “Supertrend Multi Timeframe Based Trading System – Amibroker AFL…”

  1. Is this the best intraday trading system. If ‘No’ then what is the best trading system you like the most.
    Is your back test only on long side?

    1. May be SPSO Optimizer is not installed in your machine. Either Install the SPSO optimizer or remove those three lines of code from your afl.

      OptimizerSetEngine(“spso”);
      OptimizerSetOption(“Runs”, 1 );
      OptimizerSetOption(“MaxEval”, 500 );

  2. HI,
    paramrSetEngine(“spso”);
    paramrSetOption(“Runs”, 1 );
    paramrSetOption(“MaxEval”, 500 );

    is giving error.

    i use licensed Ami 6.20.1

    Thanks.

    1. May be SPSO Optimizer is not installed in your machine. Either Install the SPSO optimizer or remove those three lines of code from your afl.

  3. showing error in these lines

    paramrSetEngine(“spso”);
    paramrSetOption(“Runs”, 1 );
    paramrSetOption(“MaxEval”, 500 );

  4. Hi

    I have try to use the above-mentioned afl codes but got following error

    Multi Supertrend V3.0 :

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

    paramrSetEngine(“spso”)
    ———————^
    File: ‘Formulas\Drag-drop\Multi Supertrend V3.0. 2.afi’, Ln:52, Col:23
    Error 30.
    Syntax error, identifier ‘paramrsetengine’ is undefined.

    Use ‘Edit Formula’ to correct error”

    Now what should I do to correctly apply these codes?

    Thanks and regards

    1. What Version you are using as SPSO is a optimizer engine plugin which released post 5.7 onwards. May be if you are using older codes you may need to
      remove the optimizer blocks i.e the below lines from the code and try out.

      OptimizerSetEngine(“spso”);
      OptimizerSetOption(“Runs”, 1 );
      OptimizerSetOption(“MaxEval”, 500 );

  5. Hi Rajandran,

    I appreciate you do provide Super trend afl code for every new version,
    but why dont you provide code for back testing and back testing setup.

    Could you please share us the link for Lintra and its backtesting code and setup

    1. All the AFL trading system which i provided here supports backtesting. And you can backtesting on your own.
      When comes to lintra its not open source but system is open to use http://www.marketcalls.in/lintra and also available as free addon for
      nimbledataprolite subscribers who subscribe via marketcalls http://www.marketcalls.in/premium/globaldatafeeds/nimbledatapropluslite

      For backtesting and learning about lintra try this webinar http://www.marketcalls.in/workshop/webinar-lintra-intraday-trading-system-system-performance.html

  6. Hi Rajandran,

    I am very big fan of you,to such kind give strategies and i have many time try to talk you but your team not touch you and I have also mail you.please check e-mail and answer me.

  7. Could some one explain the values of the below 2 lines

    Factor=param(“Factor”,3,1,4,1);

    Pd=param(“ATR Periods”,14,1,50,1);

    I understood 3 is multiplier and 14 is ATR
    but what about 1,4,1 and 1,50,1

      1. Hi Rajandran,

        I was wondering if you could help me with a bit of Amibroker formula please. In the following example I want to explore and find any stocks where “MyF()” condition is true if x is equal to 10,11,12,13,14,15,16 and so on. Perhaps I want to check 100 different periods.

        The code works fine and if MyF(10) is true then the explorer “DayDivG” column will show “10”, if MyF(11) is true then the explorer “DayDivG” column will show “11”, and so on.

        My Question is (if you have the time) is there an easier way to write the formula than having to use multiple OR expressions and IIF functions?

        If you could show an example I would greatly appreciate it.

        Many thanks for your great website and very helpful Amibroker lessons.

        ///////////////////////////////////////////////////////
        MDHist = MACD() – Signal();

        function MyF(x)
        {
        PD = L < Ref(LLV(L,x),-1) AND Ref(L,-x) < Ref(L,-x + 1) AND Ref(L,-x) Ref(MDhist,-x) AND MDHist < 0 AND Ref(MDHist,-x) < 0;

        DivG = PD AND MDHU ;

        Return DivG;
        }

        Setup = MyF(10) OR MyF(11) OR MyF(12) OR Myf(13) OR Myf(14) OR MyF(15) OR MyF(16);

        AddColumn(IIf(MyF(10),10,IIf(MyF(11),11,IIf(MyF(12),12,IIf(MyF(13),13,
        IIf(MyF(14),14,IIf(MyF(15),15,IIf(MyF(16),16,0))))))),"#DivG");

        Filter = Setup;
        ///////////////////////////////////////////

  8. Do you provide any AUM services for retail clients?? I am interested in investing with you…

  9. How do you backtest contractwise data on Amibroker in the absence of continuous data ,is there a way to stitch the data or is there anything else that can be done,please advice

  10. Hi Rajendran,

    Nice example of multi time frame code. Though it is working great, but I am unable to make the code working when I change the timeframe of supertrend, eg. I want to use the 1hr suprtrend in 5 mins chart. It is very very important to me and I am stuck to complete my strategy because of that. Will you please help me on this part ?
    I will be highly obliged if you can throw some light on this.

    Thanks & regards,
    Prady

  11. Dear All,

    Could anyone please help me out, “How can I put 15min Supertrend attach into 5min chart”.
    is there any same afl available ???

    With Regards
    Abhishek Nema

    1. Hi,

      The posted AFL code is open source. This means anybody can download and can modify it according to their requirements. It is a system trading strategy with a win rate of 40-45%.

      Don’t Expect predictions from Supertrend. A supertrend only makes money in trending markets and loses on sideways markets and it in the long run it generates returns.

Leave a Reply

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