Trading System: Meb Faber Trading System Using Different Timeframes


Beginners Course  |  Intermediate Course  |  Amibroker Course Home

A really cool question came from reader Chris the other day, where he asked about creating a trading system that used different time-frames.

In particular, this one used a Monthly Moving Average, combined with a Daily Highest High value.  Chris created some test rules based on Meb Faber’s white paper.  Here are the rules:

  • Buy on a close above a 10 month Moving Average, and;
  • a close above the 65 day high.

The Sell signal has one twist:

  • Sell on a close below the 10 month Moving Average;
  • but only on the last day of the month.

The results of the trading system were decent, although I show you how to code it we didn’t delve too deeply into the validation (i.e. with Monte Carlo testing).

And I quickly optimised a few variables, giving some decent Out of Sample results of around 26% p.a. between 2012 and 2016.  Again, it would need to have a proper Monte Carlo test done, but we get to see what is possible with just a few lines of code!

Check it out below!

The main tools we use are:

  • TimeFrameSet, and;
  • TimeFrameRestore, and;
  • TimeFrameExpand.

I also use Day() >= 28 to make our trades at the end of the month.  If anyone has a better way to do this, please let me know in the comments, or by email.  I would love to hear from you!

This allows us to create rules in different timeframes, and then use those rules later on.  Very cool stuff – thank you Chris for your question!

Hope you enjoyed, and 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

February 14, 2016  Tags: , , , , ,   Posted in: Amibroker Trading System

9 Responses

  1. LP - February 19, 2016

    Dave, love your videos. But you made a mistake by using Day() >= 28 . The Day() returns a number from 1-31, but many of those days are weekends or holidays and no trading occurs. February 28 may fall on a weekend and thus not be a trading day.

    There is some complex code for the last trading day of the month here

    And other trading days are identified more easily here,

    For example counting the trading day of the month,
    // Counting the actual Trading Days each month
    // And just for an example exploring for the 3rd trading day
    // in any given month

    TradingDayThisMonth = BarsSince( Day() < Ref(Day(),-1) ) + 1;

    ThirdDay = TradingDayThisMonth==3;

    // in AmiBroker there are many ways to arrive at the same endpoint
    // the following code arrives at the same result as the above code

    alternateCode = BarsSince(Month() != Ref( Month(), -1) )+1;

    AddColumn(Close, "Close");
    AddColumn(TradingDayThisMonth, "TradingDayThisMonth", 1.0);
    AddColumn(alternateCode, "alternateCode",1, colorViolet);
    AddColumn( ThirdDay,"Third Day",1,colorBlue, IIf(ThirdDay, colorYellow,colorDefault));

  2. David McLachlan - February 21, 2016

    LP that is awesome! Thank you.

    I’m glad there is a better way. As always, my coding skills are very basic. I will check out that code and get my head around it – it might warrant a video on “Trading Days of the month” when I do 🙂

    Happy trending – Dave

  3. Tyrone Quintas - March 12, 2016

    The timing model was published only as a simple example.  There are considerable improvements that can be made to the model and we do not run client funds with the exact parameters in the white paper or book.

  4. Thiru - April 30, 2016


    How to scalein equity on every month.

    For example : equity should increase $5000 every month (This amount will be added to trading account monthly)

    The following code does not meet this condition.
    SIPAmount = 5000;
    MonthBegin = Month() != Ref( Month(), -1 );
    e0 = Equity()+SIPAmount ;
    networth = IIf( MonthBegin, e0, 0 );
    PositionSize = networth / PosQty;

    Can you help me on this ?


  5. Neha - September 21, 2016


    Good to see you trending high, are best wishes for the great videos you do. I had a question on this one. LP’s suggestion of the codes:
    “TradingDayThisMonth = BarsSince( Day() < Ref(Day(),-1) ) + 1;

    ThirdDay = TradingDayThisMonth==3;

    alternateCode = BarsSince(Month() != Ref( Month(), -1) )+1;"

    are very good to find out which trading day of the month it is. But how will you still know that the current day is the last trading day as there can be 20, 21 or 22, etc no of trading days in a month.

    In the given example, ThirdDay = TradingDayThisMonth==3; does the job because we are trying to findout the third trading day. Similarly, 1st, 2nd, 15th or 20th could be found. But again, how do we know that the given day would be the last as the no of trading days in a month is not a fixed no.

    If the answer lies in the links pasted above (i.e ) then sorry to bother you but nonmembers do not have access to those links.

    Thanks & Regards,

  6. Neha - September 21, 2016

    Hi Dave,

    This is in response to my previous post some time back. I think I figured out the answer to my own question.
    Check the following code:

    SecondLastDayOfMonth = IIf( (Month() == Ref( Month(), 1) AND (Month() != Ref( Month(), 2)) ), 1, 0);
    LastDayOfMonth = BarsSince(SecondLastDayOfMonth) + 1;
    LastDayOfMonth= ExRem(LastDayOfMonth, SecondLastDayOfMonth);
    PlotShapes(IIf(LastDayOfMonth, shapeUpArrow, shapeNone), colorYellow, 0, yposition = Low);

    Let me know and sorry for the trouble 🙂

    Happy Trending!


  7. john - December 20, 2016

    below is the code for golden and death crossover
    Could any one help me with my requirement?
    I want to findout which crossover it is currently in and when it happened. My time range will be “All quotes” and symbols will be “All symbols”

    Say below code will produce lot of golden crossover signals and lot of death crossover signals for a single stock. But what i want is that it should show only one signal either it is gold or death whatever it is currently in and when it happened

    Your help is really appreciated. Thanks

    Filter =Buy OR Sell;
    AddColumn (Buy,”Golden crossover”);
    AddColumn (Sell,”Death Crossover”);
    AddColumn (Close,”Close”);

  8. Joachim - January 22, 2017

    Hi Dave,
    thank’s for the great course.
    I have a very easy code for the last day of the month:

    Month() != Ref(Month,1);


  9. Michael - February 28, 2017

    Hi Dave,

    For last day of the month:

    LastDayOfMonth = IIf( Ref( Day(), 1) < Day(), True, False );

    Sell = LastDayOfMonth;

    PlotShapes( shapeDownArrow*Sell, colorRed, 0, High, -10 );



Leave a Reply