Trading System: How to Code the Leap Of Faith (Gaps) Trading System That Returned 24% p.a.


Beginners Course  |  Intermediate Course  |  Amibroker Course

Trading Gaps in price has been used for many decades (if not over a century) by traders from all around the world to turn a profit.  But how successful is this method in today’s market?  Does it still apply and can we still use it to turn a profit?

In this video we create a trading system using Gaps in price – in other words the low of today’s bar is higher than the high of yesterday’s bar, creating a gap.  We also add a little code to ensure the Closing price is greater than the Opening price, meaning that the momentum followed through.

Then we add a condition for price to be above its 50 day Moving Average for a buy, or below its 100 day moving average for a sell, and to smooth out the drawdowns we add an Index Filter as well.

The trading system used five percent of its equity in each trade, with a maximum of 20 positions open at one time, using position sizing.  Entries were set at the open of the next trading day, to simulate a proper End of Day data scan when you are working full time and can’t check the markets during the day.

Check out the video below!

The Results:

The results of the moving average pointing up trading system:

  • On an ASX 200 list over 13 years:
  • Win Percent: 38%
  • Average Annual Return: 28% p.a.
  • Maximum System Drawdown: 39%
  • Adding an XAO Index Filter of 150 day moving average:
  • Win Percent: 41%
  • Average Annual Return: 24% p.a.
  • Maximum System Drawdown: 23%

Obviously, these are just ideas that you can use for your own trading systems – they are not complete trading systems themselves.  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 understand the need to test on out-of-sample data.

But it is a great look at another trading system, how to trade gaps and code them in Amibroker!

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

Happy trending,

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

August 11, 2013  Tags: , , , ,   Posted in: Amibroker, Amibroker Trading System, Trading System

8 Responses

  1. StephenK - August 12, 2013

    Hi Dave,

    Thanks for all the educational material on Amibroker.

    Have just gone through your 24% Gap video and for some reason, I get different results from you. Prior to application of the index filter and with back testing on the ASX200 using your date range, I get only 22.34% vice your 28.3%?

    Code below seems to be as per your video so can you suggest where I’m going wrong?

    Regards, Stephen

    SetPositionSize( 5 ,spsPercentOfEquity );
    SetOption( “MaxOpenPositions”, 20 );

    GapU = GapUp() AND C > O;
    GapD = GapDown() AND C = MovingAv1 AND GapU;
    Sell = C <= MovingAv2 OR GapD;

    Buy = ExRem( Buy, Sell );
    Sell = ExRem( Sell, Buy );

  2. StephenK - August 12, 2013

    Hi Dave,

    For some reason the code didn’t paste well; second attempt!

    SetPositionSize( 5 ,spsPercentOfEquity );
    SetOption( “MaxOpenPositions”, 20 );

    GapU = GapUp() AND C > O;
    GapD = GapDown() AND C = MovingAv1 AND GapU;
    Sell = C <= MovingAv2 OR GapD;

    Buy = ExRem( Buy, Sell );
    Sell = ExRem( Sell, Buy );

  3. StephenK - August 12, 2013

    Sorry; same problem. Code seems OK until I press the submit button?

  4. Dave McLachlan - August 13, 2013

    Hey Stephen!

    Hmm let’s have a look. Your code seems ok, from what came across.

    Is your trade delay set in settings? Mine is Buy Delay (1) and Sell Delay (1) at market open.

    Apart from that, make sure it is C >= MovingAv1. I’m sure it is, but cut out for some reason (darn blogging software).

    I checked it again just in case, and the results came out the same. They can vary though – different lists will produce different results. Also – have a play around with it! It is not meant to be truly complete, but more for ideas for your own trading systems.

    Hope this helps – Dave

  5. StephenK - August 14, 2013

    Hi Dave,

    I corrected the Buy and Sell Delay to (1) as indicated and got better results however still not close to yours. I am using ASX200 data from Norgate for the back test so still a little unsure as to why there is a difference. Shame I can’t upload the results as that would be the obvious way of discovering what I’m doing wrong.

    As an aside, I tried a backtest on the ASX300 without the Index Filter active and with a weekly cycle and achieved and amazing annual return of 49.37% with only 239 trades! Of course, the draw down was a little excessive however 12 million from only starting with $50,000 is pretty impressive. Just a shame that we could not duplicate that in the real world!

    Regards, Stephen

  6. Dave McLachlan - August 16, 2013

    Haha yes – with all the tests I’ve done as well, the ASX300 / ASX200 lists outperform the larger cap ones (ASX100 and ASX50). I guess that makes sense, with more small cap stocks that can really take off.

    Hmmm again on the difference – it’s got me beat. If you like, email me a .txt list of the stocks in your watch-list (right-click and export), I could compare them and see if they are similar if I get a few spare seconds…

    Amazingly – I got only similar results to the ASX200 list when using the ASX300 list, so maybe you’re on to a winner there!

  7. David R - October 13, 2016

    Hi David,

    Can I just say thanks so much for video course. I’ve found it just about the most helpful introduction to Amibroker online. It’s great that you take the time to explain the different elements of the code, how to use the different commands and variables and why you are coding each part the way you do. I’m not surprised your coaching course is full 🙂

    I did also have a question. I’ve tried to run the code you have included here on the current ASX200 (ie the ASX 200 as at October 2016) using all of the same parameters as you have used. That includes running the backtesting from Jan 2000 to Aug 2013. I can’t seem to get results even close to yours. I thought it may be the inclusion of a 0.25% commission on all of my trades, but even when I remove that I’m only seeing returns of about 15% (it’s around 5% if I allow a commission). Do you think this is just a reflection of the different make up of the current ASX200 or does it sound like I’ve got something else wrong? I am using delays of 1 for entry and exit and both are on the open the day after the signal.

    I appreciate that this is an old video and I don’t know if you still keep your eye on the comments. Either way, thanks for the course you have put together. It’s really generous to share it so openly.


  8. James Patterson - July 20, 2017

    Hey Dave great content please keep it up. I was curious if its possible to add a filter on the gap-ups where only if it gaps up on earnings?

Leave a Reply