Traders' Tip text
Mr. Gardner presented legacy WealthScript code in the article, so we’ll provide WealthScript Version 6 C# code here. Not satisfied testing with the short history of the leveraged ETFs (DBC and DDM) since 2006, we ran 12-year (8/2000 to 8/2012) simulations on 10 Sector ETFs (IXP, XLB, XLE, XLF, XLI, XLK, XLP, XLU, XLV, and XLY) using 10% of equity sizing on $100,000 starting capital, optimizing on the moving average period. While all periods produced solid returns, a smooth profit peak occurred when using a 30-bar period. With a maximum equity drawdown of only -14.7%, annualized gain was 7.9% equating to a $147,896 net profit, which includes $15,475 in dividends. Only years 2002 and 2008 had negative returns of -1.0% and -2.4%, respectively.
Figure 1. The Buy and Hold comparison emphasizes how the strategy “rachets up” equity while evading multiple drawdown periods between May and October. (Inset: annual period returns.)
WealthScript Code (C#)
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
namespace WealthLab.Strategies
{
public class GardnerSeasonal : WealthScript
{
StrategyParameter _period;
public GardnerSeasonal()
{
_period = CreateParameter("Period", 50, 10, 100, 5);
}
protected override void Execute()
{
DataSeries sma = SMA.Series(Close, _period.ValueInt);
PlotSeries(PricePane, sma, Color.Blue, LineStyle.Solid, 2);
for(int bar = GetTradingLoopStartBar(5); bar < Bars.Count; bar++)
{
if (IsLastPositionActive)
{
Position p = LastPosition;
if (Date[bar].Month == 5)
SellAtMarket(bar + 1, p);
}
else
{
if (Date[bar].Month == 10 && Close[bar] > sma[bar] )
BuyAtMarket(bar + 1);
}
}
}
}
}
Robert Sucher
wealth-lab.com