Trading System: How to Code the Three Billion Dollar Trading System


Beginners Course  |  Intermediate Course  |  Amibroker Course Home

Last week we looked at a really cool trading system, which was traded by such market royalty as Linda Raschke and Tony Crabel.

While we looked at the results of that system last week, a few people asked how to code it.  I wasn’t particularly attached to the code, and it was a good opportunity to give a few new lessons in Amibroker Formula Language that we hadn’t covered before, so here is a video on how to code the “Three Billion Dollar Trading System”.

You’ll see how I include a bit of slippage in the price – and the results of not doing so as well.  You see how we make sure we buy at our trigger level – something that might normally be done with a “buy stop” in the real world.

And we look at a few ways to plot the things we want on our chart.

Check it out!

The main tools we use are:

  • Average True Range (ATR) to determine the smallest range of the last 7 days
  • Ref, to refer to previous days
  • BuyPrice and SellPrice, to ensure we are buying and selling at the trigger level we want.

Hope you enjoyed, and happy trending 🙂

– Dave McLachlan

Beginners Course  |  Intermediate Course  |  Amibroker Course Home

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

March 6, 2016  Tags: , , , , ,   Posted in: Amibroker Trading System

11 Responses

  1. Rod - March 6, 2016

    Dave, I think there is a small flaw in your code logic which distorts the results, but I may be wrong since I don’t use Amibroker. Your Buy code includes reference to MoveUp which refers to the High on the day of the buy. It is not possible to know the High until the day is closed. Perhaps you could use Open instead of High because the Open is known before the end of the day or you could use another Ref function to use the High of the previous day. By using High of the same day you get results that are positively biased because the is a better than average chance the Close will be higher than the Open or previous High (which is referenced correctly in BuyPrice). Excellent work & thought provoking. Keep it up. 🙂 Rod

  2. David McLachlan - March 6, 2016

    Hey Rod,

    Thank you so much! Hmmm, good thinking too.

    You know, the reason I used the High being above yesterday’s high, was that I just needed ANY price to be above yesterday’s high. That meant that if I set had a “Buy Stop” in the morning at the high of yesterday’s bar, then it would have been filled at some point today. As long as that was true, then I could “BuyPrice” at the higher of the Open or the high of yesterday’s bar, which should be (correctly) detrimental to the result.

    I don’t think there’s a “future leak” in there, but I could be wrong.

    The system does have a 62% win rate, which is better than average, so maybe… I’d be keen to know what you, and others, think about it!

    Happy trending,


  3. Nick Radge - March 10, 2016

    Are you using the S&P 500 cash? I assume you are due to the the length of the backtest.

    Unfortunately that’s unrealistic as it’s not a tradable so the results are a mute point.

    Use the SPY ETF, and yes, it’s only been around since 1993, but it’s a more accurate gauge of performance – which you’ll note is a losing proposition – as it is on almost every tradable you test.

    This is a good reason to question any results that looks too good too be true and also a reason why using a cash index as a proxy for an ETF is erroneous.

    As an exercise plot the equity growth of the $SPX (cash) against that of the $SPY (tradable)….


  4. David McLachlan - March 11, 2016

    Ah – Nick thank you!

    Hey it’s really great to have you here.

    And to everyone – this is what happens when an idea is looked at by a master trader. Nick puts the lens of reality and experience on it, in a gracious and teachable way.

    Nick, I definitely appreciate your input and I hope others do too. There might be a video in that SPY/SPX difference, I think 🙂

    Happy trending – Dave

  5. Riccardo Ronco - March 11, 2016

    I second Nick’s suggestion here and, if I may add, the ETF moves are quite different from what the index does. A classic point is August 24, 2015. Check the candle on the etf and on the index. So testing on the sp cash is not ideal if one is tying to use s/t volatility breakouts because… the trade may not actually really happen or bring a totally different result if applied to the etf. I take this opportunity to thank you for the great work you do on Amibroker. Riccardo

  6. David McLachlan - March 13, 2016

    Hi Riccardo,

    Thank you! For your great comment and for your appreciation 🙂 I’m definitely enjoying the conversation that these videos bring about.

    I was thinking about the SPX / SPY difference. I’m no expert on Futures, but does anyone know how Futures go in relation to the S&P500/SPX?

    Is there a contract that tracks it closely / directly? That could be interesting.

  7. keith toghill - March 18, 2016


    Does anyone have the book by Howard Band “ Modelling-trading-system-performance” for sale or alternatively, perhaps someone might have a PDF of the same book if one was once available.

    I think this website is just great. It certainly has made me realise there is so much more to learn about trading shares and so has inspired me to learn more.
    Please contact me at [email removed].

    Thanks Keith

  8. Thiru - April 30, 2016

    Hello Dave,

    I will be adding $5000 on beginning of every month to my trading account.

    My equity curve should add this amount.

    Can you help me to code this ?


  9. Leng - September 21, 2016

    Hi Dave,

    Thanks for your video it was interesting and I am pretty new to Amibroker and I manage to get it working and I did some backtest and it shows some good results.

    The question is that when I put the arrow on the signal generating is at the buying the date therefore there is no way to know that we need to buy today. Unless it returns the arrow to display yesterday or so.

    How do we know today’s high unless it’s end of the day right?

    MoveUp = H > ref (H, -1); // how to know this today’s highest till market close ???
    Buy = Ref(PreCondition, -1) AND MoveUp;

    It will work in the backtest but I am not sure how to manage to make it work in real world if I would like to place the trade manually when the signal is generated.

    Hope to hear advice from you

    Again many thanks


  10. john - November 2, 2016

    Is Amibroker backtest realiable..? how do print trade positions…? it only says long in the trade tab no short or sells and my plot arrow is not plotted in the chart… it only applys as an indicator below… pls help thanks…

  11. Matt Griffiths - February 3, 2018

    Hi Dave,

    Just an observation, in Day Trading with Short Term Price Patterns, Crabel defines an NR7 as the smallest range of the last 7 days. By using ATRs, your setup conditions will not strictly match Crabel’s, although the general concept of range expansion is still there.

    I haven’t done the testing, but assume your approach will result in more frequent signals which may not be a bad thing – less restrictive, more robust? Have you looked at some of Crabel’s other ideas on ASX stocks – as Nick suggested above, the edge has deteriorated markedly more recently, but may still be something there?

    Thanks for your site and videos/lessons – Nick referred me. Some great AB pointers in there – keep up the good work!


Leave a Reply