Saturday, April 7, 2012

thinkscript included: altucher's strategy

during the trader's expo this year james altucher mentioned a simple strategy for trading the markets that he says has produced positive results almost every year for the last decade. in a nutshell, his strategy is:

buy on four consecutive lower closes, sell on two consecutive higher closes
this is a long-only strategy and it uses only market orders - really quite remarkable. so i thought i'd use altucher's strategy to explore the thinkorswim strategies facility.

thinkorswim strategies are the equivalent of what have come to be known as expert advisors. an expert advisor will help you map out how a strategy has performed in the past. the thinkorswim ea's will notate entries and exits on tos charts and keep a running tally of the hypothetical (they are only automated advice, not live trading) profit and loss. they are programmed in thinkscript.  here's what my ea for the altucher strategy looks like:
spy with altucher's strategy, the p&l for the year is circled
sdi_altLE is where the strategy bought-to-open, and sdi_altLX is where the strategy sold-to-close.  this produced loss on spy but a small one considering that each trade is 100 shares - you didn't really think this would work all-the-time on any equity!? there's the rub, altucher's strategy works really well on a handful of equities and not so well on others. however, an ea can tell you in a flash which ones look rosey in the strategy's rearview mirror.

here's a more successful picture of the poster child, aapl:
aapl with altucher's strategy
a nice gain but it completely missed the run-up this spring. the ~15% return on aapl is a bit underwhelming when compared to the 50% run-up. this underscores the boundaries of utility in the altucher strategy. it seems to do well with equities that are in favor but not trending. it will buy on weakness and sell into the rise, generally a good thing as most equities spend far more time treading water than making a big splash.

altucher gets crushed if the equity falls out of favor and starts trending down without a breather but not always. take a look how altucher fared on fslr:
fslr with altucher strategy
fslr dropped from the 150's down to 20 and yet, this altucher strategy, trading only to the long side, produced a $1800 gain, an unlikely feat of scalping the bounces in a down trend.

there are two scripts for my implementation of the altucher expert advisor, one for entry and the other for exit. also, you will need to create strategies, not studies. if you cut 'n paste the code be sure to click the strategies tab in the edit studies dialogue to create a new one.

############
# sdi_altLE - altucher strategy long entry.
#hint: buy to open at market after four consecutive lower closes. source: smalldoginvestor.com rev:1.0
def condition = close<close[1] && close[1]<close[2] && close[2]<close[3] && close[3]<close[4] ;
addOrder(OrderType.BUY_AUTO, condition);
############


#############
#sdi_altLX - altucher strategy long exit.
#hint: sell to close at market after two consecutive higher closes. source: smalldoginvestor.com rev:1.0
def condition = close>close[1] && close[1]>close[2] ;
addOrder(OrderType.SELl_TO_CLOSE, condition);
##############


No comments:

Post a Comment