Trading System: How to Code a Moving Average Channel That Made 23% p.a

Line1

Beginners Course  |  Intermediate Course  |  Amibroker Course Home

Creating a winning trading system can seem daunting at first, but it can be made easier by looking at existing trading systems.

In this video we will go through how to code a Moving Average Channel trading system that turned $50,000 into $1 Million dollars over 13 years, averaging 23% per annum (not including dividends).

We also go through how to improve it, how to test it with in and out of sample data, adding an index filter, and system drawdowns.

Being a typical trend following system, it has a low Winning Percentage of between 32% and 43%.  However the many small losses are made up for with the few large gains.

The Results:

The results of the Moving Average Channel trading system:

  • On an ASX 200 list over 13 years:
  • Win Percent: 32%
  • Average Annual Return: 20% p.a.
  • Maximum System Drawdown: 48%
  • Adding the Index Filter:
  • Win Percent: 42%
  • Average Annual Return: 23% p.a.
  • Maximum System Drawdown: 29%

Obviously I would not recommend trading this system at all, before you test it thoroughly yourself on Out of Sample Data.  Also, this system would not be easy to stick to for most traders, as it still has a relatively low win percentage.

But it is a great look at another trading system and how to code it in Amibroker!  We can also see the back testing results within seconds, instead of testing it ourselves and taking weeks or months.

These are the great benefits of automatic testing!  Fast, free and easy.

I hope this helps, happy trending and enjoy.

– Dave McLachlan

Beginners Course  |  Intermediate Course  |  Amibroker Course Home

Videos in the FREE Amibroker Course:

  1. Amibroker: How To Import A Watchlist With A CSV File
  2. Amibroker: How To Backtest A Single Stock Or Index
  3. Amibroker: How To Backtest a Portfolio or Group of Stocks
  4. Amibroker: How To Optimize A Trading System
  5. Amibroker: How To Scan The Market For Buy And Sell Signals
  6. Amibroker: How To Use Explore To Find And Filter Stocks
  7. Amibroker: How To Add Position Sizing Using AFL
  8. Amibroker: How to Add An Index Filter To Your Trading System Using AFL
  9. Amibroker: How To Plot Your Trading System On A Chart (incl. Buy/Sell Arrows)
  10. Amibroker: How to Use the If, Then Else Function (IIF)
  11. Amibroker: How to Code the ATR Trailing Stop (Chandelier) using ApplyStop
  12. Amibroker: How to Plot ApplyStop on a Chart
  13. Amibroker: How to Code Van Tharp Position Sizing (Fixed Fractional)
  14. Amibroker: How to “Scale In” to Positions (1) – Buying Once a Month
  15. Amibroker: How to “Scale In” to Positions (2) – Pyramiding Three Times
  16. Amibroker: How to Use “Cross”, When One Thing Crosses Another
  17. Amibroker Advanced: How to Compare Equity Curves

FREE Trading System Video Lessons:

  1. 7 Free Trading Systems and Their Returns From The Last 13 Years
  2. Seven Full Trading Systems Revisited, With Completely New Data
  3. Trading System: How to Create A Buy and Hold Trading System
  4. Trading System: How to Code “Sell In May And Go Away”
  5. Trading System: How to Code a Moving Average Channel That Made 23% p.a
  6. Trading System: How to Code Highest Highs As Used In 52 Week Highs Or Turtle Trading System
  7. Trading System: How to Code a Bollinger Band Breakout Trading System
  8. Trading System: How to Code a Moving Average Crossover That Returned 28% per annum
  9. Trading System: How to Refer to Previous Signals For MAup Trading System
  10. Trading System: How to Code the Leap Of Faith (Gaps) Trading System That Returned 24% p.a.
  11. Trading System: How to Code a Short Selling System (Plus Results)
  12. Trading System: Meb Faber Trading System Using Different Timeframes
  13. Trading System: How to Code the Three Billion Dollar Trading System

FREE Amibroker Q & A Videos:

  1. Amibroker Q & A: How To Do A Monte Carlo Test? (on ALL versions)
  2. Amibroker Q & A: Visualising Monte Carlo Data with Histograms and Scatter Plots
  3. Amibroker Q & A: How to Create the 52 Week High/Low Index with AddToComposite
  4. Amibroker Q & A: How to Code Trend Pilot: Five Consecutive Days Above or Below a Moving Average
  5. Amibroker Q & A: Three “Hacks” To Improve Your Coding Skills
  6. Amibroker Q & A: How to Remove Excess Signals

Read Related Articles:




  And, subscribe for free to stay in touch and receive the latest updates:

Enter Your Email Address:

.
(Check Your Junk Mail, Just In Case)

June 16, 2013  Tags: , , , ,   Posted in: Amibroker, Amibroker Trading System, Trading System

10 Responses

  1. Andrew CR - July 1, 2013

    Hi Dave,

    I just discovered your website and it looks great. Coincidentally I have also just bought AmiBroker. Now I am very much a novice when it comes to Amibroker but I was trying to replicate your “amazing long term system of awesomeness” but have got very different results. Could you give me an idea of what I may have done differently? Your help would be really appreciated as I would like to generate a bit of confidence that I am using AmiBroker correctly before I put any faith in what I am getting out.

    Thanks

    Andrew

  2. Dave McLachlan - July 2, 2013

    Hi Andrew – Absolutely. And it’s always good to check that I’ve done the right thing myself – I’m only human after all.

    What were the results? Better? …Worse?

    There are a few possible things – the position sizing (mine was 5 percent per trade and 20 positions max), the fact that I set my entry to the open of the next day after the signal (do this in settings – this emulates an EOD system that you might check at nights and enter the next day). Or, the watch-list itself may contain different stocks or data.

    Anyways – keep me posted! Cheers – Dave

  3. Jea - September 26, 2013

    I must say you have done a great job with this. It’s simple, yet effective. A lot of times it’s very difficult to get that “perfect balance” between superb usability and results. In addition, the blog loads very quick for me on Firefox. Superb Blog!

  4. tm - September 27, 2013

    Great work! This is the kind of info that are supposed to be
    shared across the internet.

    Thanks =)

  5. Prashant Kulkarni - January 1, 2015

    Dave;
    Awesome work..I was struggling to LEARN about AFL which at last found on your website.
    Is it possible to code Stochastic divergence in Amibroker ?
    Thanks
    Prashant Kulkarni
    [number removed]

  6. mehdi - March 17, 2015

    hi 

    in ichimoku when kijensen is flat for 1 to 20 day ago and in the 1 to 20 day ago tekensen croosed kijensen.

    and last candle kijensen will uptrend.

    i want this program 

    for example

    i want to get signal in codition 2

    codition1:   cross (tenkensen, kijensen);    // max 20 candle ago

    codition2:   kijensen > ref (kijensen , -1) ;  //  last candle  today

    i want to get signal in condition 2 

    i write this whit “exrem”

    but this has a lot of  mis.

    program must be check today to 2o day ago for cross(tenkensen,kijensen); and get signal when kijensen is uptrend

    plz help me and send afl program for this .

    thank you so much

     

  7. Qualtar Demix - May 19, 2015

    Great video Dave,

    I have applied your strategy on Indian markets (NSE – Nifty), and the results are pretty good:
    Initial capital 100000.00
    Ending capital 1268378.64
    Net Profit 1168378.64
    Net Profit % 1168.38
    Exposure % 81.03
    Net Risk Adjusted Return % 1441.89
    Annual Return % 19.89
    Risk Adjusted Return % 24.54

    My assumptions:
    1. Start the trade on 1 January.
    2. Close all trades on 28 December.
    3. Trading fees on each trade is 0.5%.
    4. Volume of the stock involved must be greater than 10000.
    5. Start the trade with 100000.
    6. Buy each stock for 20000.
    7. Put the stoploss at 9.4%.

    My strategy in AFL:
    numberOfShares = 20000/Close;
    SetPositionSize( numberOfShares, spsShares );

    percentageRise = Optimize(“Percentage rise”,0.02,0.01,0.15,0.01);
    maDays=Optimize(“MA days”,482,10,600,1);

    percentageAbove = Close + (Close*percentageRise);

    movingaverageabove = ma(percentageAbove,maDays);
    movingaverage = ma(c,maDays);

    buy=Cross(Close,movingaverageabove) AND Volume>10000 AND DayOfYear()<360;
    sell=Cross(Close,movingaverage) OR Cross(DayOfYear(),362);

    stoploss=9.4;
    ApplyStop( stopTypeLoss, stopModePercent, stoploss, True );

    @Dave: I have a few questions:
    1. What would be the corresponding shorting strategy for this approach?

    Again thanks for the awesome video. 🙂

  8. Dave McLachlan - May 19, 2015

    Nice one Qualtar!

    It’s been a while, but I believe the shorting strategy would use “short” to open the position instead of “buy”, and “cover” to close the position instead of “sell”. Then just assign the rules you want.

    Lastly, make sure you allow shorting, in the settings, before you click Backtest.

    In my experience, short systems don’t always work as well as their long counterparts, but I’d be interested to hear how it goes!

    Cheers, Dave

  9. Alex Kennedy - November 26, 2015

    Hi,
    I’d like to consider a membership to your website so can you advise when these may become available again? In regard to the 7 systems I don’t seem to be able to find something to download. Has this capability gone or am I missing the obvious?

  10. Dave McLachlan - November 27, 2015

    Hey Alex,

    Sure thing – there’s no timeframe yet, I’m still considering what it will look like. I’m pretty sure I will add new content if it was to open again :). For the 7 Systems – it is just the article with the system details and results. Each one has a link to the original system article too, with a video. Nothing to download – it’s all in the articles or on YouTube 🙂

    Happy Trending – Dave

Leave a Reply