Joined Nov 11, 2007
1,458 Blog Posts

AmiBroker Code for TransDow System

I have been trying to replicate ETF HQ’s TransDow strategy. It is a neat idea, and the simplicity appeals to me. Beyond that, I’ve been working with AmiBroker to get better at coding in multiple time frames. Because this strategy uses weekly closes, I thought it would be good practice. The problem is that I cannot get my results to be any where near ETF HQ’s results. My guess is that my code has an error, but for the life of me, I cannot figure it out.

After emailing with ETF HQ, I was able to determine that their coding has the week close on Monday while my code uses Friday as the last day of the week. This should not make that much of a difference.

The AmiBroker code is below. I have put it within the WordPress quote function, so it should be able to be cut and pasted without error.

*Update* It will not cut and paste without error. The problem seems to stem from the quotation marks. I’ll leave the code here so that others can peruse it. Email me woodshedder73 at google mail and I’ll send the .afl file as an attachment.

/*TransDow as described by Derry Brown: http://etfhq.com/blog/2013/05/04/market-timing-through-market-dominance-transdow/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+EtfHq+%28ETF+HQ%29

//Boilerplate options
SetTradeDelays( 0, 0, 0, 0 );

SetOption( “InitialEquity”, 10000 );
SetOption( “MinShares”, 1 );
SetOption( “MinPosValue”, 0 );
SetOption( “FuturesMode”, False );
SetOption( “AllowPositionShrinking”, True );
SetOption( “ActivateStopsImmediately”, False );
SetOption( “ReverseSignalForcesExit”, False );
SetOption( “AllowSameBarExit”, False );
SetOption( “CommissionMode”, 3 );
SetOption( “CommissionAmount”, 0.0 );
SetOption( “InterestRate”, 0 );
SetOption( “MarginRequirement”, 100 );
SetOption( “MaxOpenPositions”, 1 );
SetOption( “UsePrevBarEquityForPosSizing”, True );

RoundLotSize = 1; // 0 for Funds, 100 for Stocks
TickSize = 0; // 0 for no min. size
MarginDeposit = 0;

Totalpositions = 1;
PositionSize = -100/TotalPositions;

// Weekly Bars //
DJI=Foreign(“$DJI”, “C”);
DJT=Foreign(“$DJT”, “C”);





Plot(Ratio, “Ratio”,colorYellow,styleLine);
Plot(Ratio10, “Ratio10”,colorGreen,styleLine);
AddColumn(Ratio, “Ratio”,1.5);
AddColumn(Ratio10, “SMA10″,1.5);
AddColumn(Buy, “Buy”);
AddColumn(Sell, “Sell”);

Let me know in the comments if there are any questions about the code. My data provider uses $DJI for the Dow Jones Industrial Average and $DJT for the Dow Jones Transportation Index. These symbols may have to replaced with whatever symbol your data provider uses for the $DJI and $DJT.

If you enjoy the content at iBankCoin, please follow us on Twitter


  1. Bozo on a bus

    Oh no! Not something else to think about. The TransDow is on my list, but I’m still working on stuff from at least six posts ago. At this rate I can never catch up 🙂

    • 0
    • 0
    • 0 Deem this to be "Fake News"
    • Woodshedder

      Well, pursuit and follow-through to the nth detail was never my strong suit. I jump around until I find something that I really want to spend a lot of time with. So I understand having lots of irons in the fire!

      • 0
      • 0
      • 0 Deem this to be "Fake News"
  2. Bozo on a bus

    Well, I figured this shouldn’t take too long… wrong.
    Downloaded DJIA and DJT data from Dow Jones back to 1928, and quickly discovered that the weekly data (which I had never used) also includes monthly close data. Except when the month end is a holiday, then you get the last trading day of the month. And probably contaminated by all kinds of market closings. Won’t be so easy to filter all this stuff out to just get weekly closes. It should get easier then.

    • 0
    • 0
    • 0 Deem this to be "Fake News"
  3. Lars Bech

    Has recently been covered by CXO Advisory. Subscriber-only reading, but this is the link:

    • 0
    • 0
    • 0 Deem this to be "Fake News"
  4. Bozo on a bus

    Well, so far I can’t get this system to work at all. It underperforms the DJT from the beginning. I am using the closest trading day to Friday for the weekly close; buy at that day’s close when the signal is positive and hold for the week, otherwise in cash. I honestly don’t know what a 4% stop-loss means under these conditions – don’t buy again until the system cycles through a complete set of in-out signals, or just sit out a week if the signal is still positive, or what?

    • 0
    • 0
    • 0 Deem this to be "Fake News"
    • Bozo on a bus

      Still can’t make this work.

      I should add that weekly closes (based on DJ data) are usually Saturdays up to about 1945; sometimes Saturday and sometimes Friday until 1952, and Fridays after that. Except for days the market was closed on Fridays, or Saturdays, or Thursdays, or two or three days. And except for a couple of events like 9/11, when the weekly close was the prior Monday. Giving us one three day week, two five day weeks, many six and eight day weeks, two nine day weeks, and one 13 day week. 🙂

      Find all kinds of interesting stuff looking at 5000 lines of data. But probably not the main reason I can’t get it to work.

      • 0
      • 0
      • 0 Deem this to be "Fake News"
      • Woodshedder

        Wow, that is a mess! Thanks for all this work. It is very interesting.

        As for the exact rules, they are in the ETF HQ post, but they are not spelled out with extreme clarity. They are still discernible.

        • 0
        • 0
        • 0 Deem this to be "Fake News"
  5. W. Roth

    I don’t know anything about AmiBroker, but it looks to me like the stop rule isn’t implemented correctly. My interpretation of the ETFHQ post is “sell at end of week if the low of the week exceeds a 4-percent loss for the trade”, which doesn’t seem to be what’s written here (again, I don’t know the AmiBroker APIs so it’s possible I just don’t see it).

    On another note, has anyone tested this as a long/short strategy? I can’t find any short-transports ETFs, but DOG might work as a surrogate.

    • 0
    • 0
    • 0 Deem this to be "Fake News"