Saturday, October 11, 2014

thinkscript included: is trading the hull moving average a good strategy?

on tuesday, october 7th, on tastytrade's tech-tools segment, steve miller, aka slm, said he liked the hull moving average and encouraged his users to "play" with it. so i did. 

the hull moving average employs a smoothing technique that claims to reduce "lag" - a trading signal that comes a little too late. if you watched slm's presentation it clearly seems to do just that. the rollover of the hma certainly seems to occur way before some of the traditional moving average crossovers that investors watch - but can that make you money? 

it's really hard to eyeball a chart and make an assessment that is not subjective. first of all, the rising/falling color transition is not fully determined until the candle after the transition completes. this means that a trade entry would not occur until the open of the 2nd candle past the color transition.  the cumulative p&l of trades taken this way is something i wouldn't want to evaluate by eye. fortunately, there is the thinkscript strategy facility, with which i can simulate trading such signals and evaluate these things objectively. so here's a typical picture of the hull strategy at work:
simtrading $10k on spy via hull moving average signals compared to passive investment
the top graph shows when and at what price the hull strategy  bought, reversed and shorted $10,000 worth of spy, as indicated by the pink labeling and arrows. the pink number is the amount of shares transacted. when the dashed line connecting the reversals is colored cyan the trade made money and when the dashed line is colored red the trade lost money. the floating pl subgraph shows the day-by-day cumulative profit and loss for the strategy over the 1-year duration of the chart. the bottom subgraph shows the growth of $10,000 invested over the same period of time by the buy 'n hold method and by dollar-cost averaging (i.e. buying about $833 worth of spy every month.) so here we see that, as of Oct 8,14, that the hma strategy was down money while buy 'n hold showed a position improvement of +$1,650 and dollar-cost-averaging, +$372. this is very typical of the equities i looked at.

now the kinds of equities i tend to be interested in reflect that i tend to be a long trader. however, i did find that the hull strategy shined for equities in a long-term decline. take gld, for instance:

and even more impressively, slv:

so it seems that if you have a bearish opinion that was formed by some other method, that taking the bearish trades from the hma signal could be profitable.

here is the code (how to install):

# sdi_hullmastrat - plot results of trading the rollovers/unders of the hullMovingAvg 
#hint: shows the trade simulation of trading the hullMovingAvg rollovers / unders using a fixed amount of money. rev:1.0.0 
# author: allen everhart
# date: Oct 11, 2014
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale. 
# Help me get the word out about my blog by keeping this header
# in place.

input dollarsPerTrade=10000;
#hint dollarsPerTrade: controls the amount of money the simulation uses to trade. rev: 1.0.0 
input length=20;
#hint length: the number of charting periods passed to the hullMovingAvg calculation. 
def shareSize = Round(dollarsPerTrade / close, 0) ;
def ma=hullMovingAvg(length=length);
def buySig=ma crosses above ma[1];
def sellSig=ma crosses below ma[1];
addOrder(OrderType.BUY_AUTO, buySig,name="long", tradesize=sharesize);

addOrder(OrderType.SELL_AUTO, sellSig, name="short", tradesize=sharesize);


  1. The Hull strategy script is very useful. Is it possible to add an audible alert to trigger when the buy or sell signals are painted on the chart?

    1. hi ezduzit,

      yes, it is possible. would you possibly consider hiring me for that customization?