Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

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 Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

Algomojo Index Straddle/Strangle Execution Module with Intraday Stoploss

This tutorial focus on how to automate your index straddle/strangle strategy with intraday stop-loss levels with time-based entry and exits using Algomojo Platform and...
Rajandran R
7 min read

Learn How to Login into Algomojo Account using Amibroker

In the last tutorial, we learn how to automate the algomojo login process and in this video tutorial, we are going to learn with...
Rajandran R
1 min read

Amibroker Execution Module – Hedged Index Futures for Directional…

In the last tutorial, we learn the importance of Hedging Futures Position with OTM Options for Reduced Margin. This tutorial focus on how to...
Rajandran R
14 min read

25 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

Leave a Reply

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