Trading System: How to Code a Moving Average Crossover That Returned 28% per annum

Line1

Beginners Course  |  Intermediate Course  |  Amibroker Course Home

Ah, the humble moving average crossover trading system!  As one of the first (if not the first itself) trading systems created, and used by Richard Donchian and Ed Seykota as early as the late 1960s, you have probably heard of a moving average crossover in some shape or form during your time in the markets.

One of the most common is the “Golden Cross” and “Dead Cross”, where the 50 day moving average crosses above (or below) the 200 day moving average.

The one in this video is a 61 day and 93 day moving average crossover, in which we also add a 10% stop loss using the ApplyStop function in Amibroker.  This helps reduce the maximum draw down a little bit, to make the system a little more comfortable.  You could if you wanted to, even it out by using a 60 day and 90 day moving average – the results are similar.

Overall, the system returned an average of 28% per annum over the last 13 years.  Of course, as you know, this is not a guarantee of future performance, but can give you ideas for creating your own trading systems.

Check out the video below!

http://youtu.be/aq20CN7-0us

The Results:

The results of the Moving Average Crossover trading system:

  • On an ASX 200 list over 13 years:
  • Win Percent: 49%
  • Average Annual Return: 36% p.a.
  • Maximum System Drawdown: 45%
  • After Adding a 10% Stop Loss:
  • Win Percent: 41%
  • Average Annual Return: 28% p.a.
  • Maximum System Drawdown: 37%

Obviously, it is wise to test this trading system yourself, add parts or modify to suit your own needs, being aware of your maximum drawdown pain threshold and understanding the need to test on out-of-sample data.

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.

Like this post?  Leave a comment in the section below.

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)

July 7, 2013  Tags: , , , ,   Posted in: Amibroker, Amibroker Trading System, Trading System

6 Responses

  1. Arun Anand - April 19, 2015

    how to you test which single moving average best fits the data without having to do it one by one. i mean like the optimiziing system.

  2. Dave McLachlan - May 3, 2015

    Hi Arun,

    See the lesson “How to optimise a trading system”, here:

    http://www.asxmarketwatch.com/2012/06/lets-learn-amibroker-afl-how-to-optimize-a-trading-system/

    Hope this helps 🙂

    Dave

  3. Sumit - October 5, 2015

    Hello Dave,

    How do I read 34EMA value (hourly chart) of opening candle of 2 days before in a variable ..

    i.e if suppose today’s date is 30th I want to read 34ema value of the first candle on 28th..

    Thanks in advance..

  4. Dave McLachlan - October 19, 2015

    Hey Sumit!

    See the lesson “Using “Ref” to refer to previous Signals”, hopefully it will help:

    http://www.asxmarketwatch.com/2013/08/amibroker-trading-system-referring-to-previous-signals-for-upwards-moving-average/

    If not, you may need to code something around the Day() function?

    Good luck 🙂 – Dave

  5. Qualtar Demix - October 25, 2015

    Can we simply call this strategy to be:
    buy when macd(60,90) > 0
    and sell when macd(90,60) < 0

  6. Prakash Modak - April 21, 2016

    Hello Dave,

    if i am using 3MA’s i.e. MA5 , MA13, MA26 and if i want to find out a particular point from where 5 crossed 13 and 26 at a single point ( Not separately, its very rare ) how i can code the same.

    i.e. if 5MA crosses 13 & 26 down its SELL and vice versa. How i can plot the same?

    I have understood plotting of 5 crossing 13 for buy an sell as per video.

    Thanks for your videos.

    Prakash Modak

Leave a Reply