Trading System: How to Code Highest Highs As Used In 52 Week Highs Or Turtle Trading System

Line1

Beginners Course  |  Intermediate Course  |  Amibroker Course Home

Using the highest high value of the last “x” number of trading days has been a staple in trading systems for many decades.  Starting with the “Turtle Trading System” that used a version of 20 day highs and 10 day lows to create outstanding wealth, and going through to the common adage of 52 Week Highs being a sign of strength in the market, this Amibroker Trading System shows you how to code the Highest High idea in Amibroker Formula Language.

We take a slightly different approach, making 85 day highs and 35 day lows, with decent annual results but a large drawdown during 2008.  An index filter or other criteria can often be added to avoid the larger bear market drawdowns.

http://youtu.be/msKhes4DB04

The Results:

The results of the Highest High Breakout trading system discussed in the video:

  • On an ASX 200 list over 13 years:
  • Win Percent: 38%
  • Average Annual Return: 23% p.a.
  • Maximum System Drawdown: 41%
  • Adding An Index Filter of All Ords over 75 Day MA:
  • Win Percent: 45%
  • Average Annual Return: 23% p.a.
  • Maximum System Drawdown: 16%

As mentioned before, you might add other criteria to make it your own, but the Index Filter really brought the maxDD down a lot.  23% per annum with an 16% maximum drawdown is a great result for a medium term trading system as far as I’m concerned, and the equity curve looks a lot nicer.

  • Using Highest Highs for the Turtle Trading System would be simply a matter of using 20 day highs and 10 day lows – or approximately 250 day highs for a 52 week high trading system.

Still, it is a great example of how even a simple trading system can be profitable, which you can improve or take parts of for your own trading system!

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 30, 2013  Tags: , , , , , , ,   Posted in: Amibroker, Amibroker Trading System, Trading System

15 Responses

  1. vaibhav - July 6, 2013

    want to subscribe the feed about ami broker

  2. Dave McLachlan - July 7, 2013

    Hey Vaibhav – you can subscribe by email to the right, or you can subscribe to my YouTube channel – both will have any new Amibroker vids I do.

    Cheers – Dave

  3. Dave McLachlan - August 8, 2013

    So just an update – added an Index filter of our index (All Ordinaries in Australia) being over its 75 day Moving Average to make a trade, as well as the 85 day highs, 35 day lows.

    It brings the max drawdown to just 16 percent, while the average annual return is still 23 percent. A nice result!

  4. Andrew CR - November 25, 2013

    Hi Dave,
    Is there any chance you could show how to do a monte carlo test?

    Thanks

    Andrew

  5. Dave McLachlan - December 3, 2013

    Ah – ok I figured it out.

    Basically you can add this code (type it in) to the top of your existing code, and then click “optimize”:

    PS = Optimize(“Postion Score”,1,1,X,1);
    PositionScore = Random() * PS;

    Where “X” is the number of different tests you want to do. 1000 is usually pretty good for an EOD system.

    That will spit out “X” number of different (random) simulations! Awesome!

    – Dave

  6. Dave McLachlan - November 26, 2013

    Hey Andrew!

    I have looked at Monte Carlos, and all I remember is they were more complicated than I expected. I’m sure with a little grit they can be worked out though. I’ll have a look into it 🙂

    Dave

  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:
    Net Profit % 4336.64
    Exposure % 67.77
    Net Risk Adjusted Return % 6399.45
    Annual Return % 31.10
    Risk Adjusted Return % 45.89

    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.

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

    hhvalueDaysL = Optimize(“Highest High Value Days”,205,100,400,1);
    llvalueDaysL = Optimize(“Lowest low Value Days”,23,3,40,1);
    stoploss=9.4;

    Buy=Cross(Close,Ref(HHV(Close,hhvalueDaysL),-1)) AND Volume>10000 AND DayOfYear()<360;
    Sell=Cross(Ref(LLV(Close,llvalueDaysL),-1),Close) OR Cross(DayOfYear(),362);

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

    ApplyStop( stopTypeLoss, stopModePercent, stoploss, True );

    Plot(hhvalueDaysL,"hhvalueDaysL",colorWhite,1);
    Plot(llvalueDaysL,"llvalueDaysL",colorWhite,1);

    @Dave: I have a few questions:
    1. What would be the corresponding shorting strategy for this approach?
    2. What is the big fuss with Donchian?

    Again thanks for the awesome video. 🙂

  8. Dave McLachlan - May 19, 2015

    Awesome Qualtar! Love your work.

    Just use “Short” and “Cover” instead of buy and sell, with the relevant rules that you want, and shorting allowed in the settings.

    Donchian – from memory he was sort of regarded as one of the first systems traders, with a four week high / low strategy. I think Ed Seykota of Market Wizards fame referenced him. But this was in the 70s (or even before). We are light-years away from the world they had to work with then! Some of his fundamentals will still apply (I think he said “Let your winners run, and cut your losses”, but so did just about every other great trader).

    In the end, it’s about finding a positive expectancy strategy that suits your own temperament and time-constraints. At least, that’s what the tipping point was for me.

    Again, awesome work Qualtar 🙂 – Dave

  9. Qualtar Demix - May 20, 2015

    WOW…I am really surprised. You replied instantly on a two year old post. Actually Dave, I am quite comfortable with AFL. I have applied many shorting strategies using Short and Cover. However, for this particular approach of ‘Highest High’ and ‘Lowest Low’, I am not able to find a decent shorting strategy. The best that I came up with gave Annual Return of 5%. Can you please come up with a shorting strategy. Also, I am big fan of your work. Is there a way we can chat sometimes. My email id is : [email removed]. 🙂

  10. Dave McLachlan - May 28, 2015

    Haha Qualtar, thank you – I think we were just on at the same time! I’m not usually that quick.

    And yes, I should have taken a guess by your code – very nice! I’ve tried shorting strategies as well, coded with not much success. There are a few reasons, I think:

    1. The market goes up more than it goes down generally – because of inflation, survivorship bias (i.e. failed stocks get removed from top market lists), etc. Just look at any long term chart.

    2. When the market falls, it falls sharply, not steadily such as when it rises. It often bounces back just as sharply.

    3. General volatility (i.e. sharp ups AND downs) are increased during bear markets. Take a “Dead Cat Bounce”, for example.

    Anywho, I think I will stick to where the odds are in my favour. If you’re passionate about a Bear strategy though, don’t give up – I know you will find an answer.

    Cheers – Dave

  11. Yadi - August 16, 2015

    Hi Dave,
    I have downloaded the newest Amibroker (Trial version)and I have coded exactly the same AFL as shown above, but Amibroker shows there is no any single trades for the last 15 years. I am not sure what was going on here.

    Is it because I am using a free trial version?

    Any feedback is appreciated.

  12. Dave McLachlan - August 20, 2015

    Hey Yadi,

    It shouldn’t be the trial version causing the problem… As far as I know.

    You can paste the code here if you like – myself or others can have a look. Otherwise it could be your trade settings or your stock universe / data.

    Cheers – Dave

  13. Michael - February 27, 2017

    Hi,

    Thanks for your website Dave. Its proving to be very helpful as I come to terms with AB.

    I’ve just downloaded AB and have entered your code for Highest Highs strategy above.

    Unfortunately I’m getting this…error 30 syntax error unexpected identifier.

    This is in relation to this line of code…

    HighestValue = HHV(C, 20);

    Could it be something to do with the version of AB I’m using? Its version 6.10.0

    Many thanks for any help you can offer.

    All the best,
    Michael

  14. Michael - February 27, 2017

    Please ignore my previous post.

    My mistake…I’m an idiot.

    Thanks.

  15. David McLachlan - March 25, 2017

    Hey Michael,

    You are most certainly NOT an idiot! No silly questions here, otherwise I’d never ask any myself either 🙂

    If you share your solution, what you did to solve it, others can benefit too!

    Cheers – Dave

Leave a Reply