Traders' Tip text
Because Hull Moving Average has been a part of the free “Community Indicators” library, driven by the Wealth-Lab user community, applying it to charts and strategies is as easy as drag n' drop. To run this Wealth-Lab 6 code that implements Gardner's RSI/HMA system for trading indexes, install the indicator library (or update to the actual version using the Extension Manager tool) from the wealth-lab.com site,
Extensions section.
Figure 1. A Wealth-Lab Developer 6.0 chart showing the system applied to Apple Inc. (AAPL, daily).
Plotted as a blue line on Figure 1, Hull Moving Average shows as a truly responsive one, providing timely short-term signals when it turns up. Depicted on the upper pane for comparison with the 9-day RSI of a 9-day HMA, the RSI of SMA with the same period (violet line) visibly lags its counterpart.
WealthScript Code (C#)
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Indicators;
namespace WealthLab.Strategies
{
public class TradersTips201012 : WealthScript
{
private StrategyParameter paramPT;
private StrategyParameter paramSL;
public TradersTips201012()
{
paramPT = CreateParameter("Profit Target %",10,1,100,1);
paramSL = CreateParameter("Stop Loss %",10,1,100,1);
}
protected override void Execute()
{
DataSeries ma = SMA.Series(Close, 50);
HullMA hma4 = HullMA.Series(Close,4);
DataSeries rsiHma = RSI.Series( HullMA.Series(Close,9), 9 );
Color tp = Color.Transparent;
LineStyle ls = LineStyle.Solid;
ChartPane paneRsi = CreatePane(35,true,true);
PlotSeries(PricePane,hma4,Color.Blue,LineStyle.Solid,1);
PlotSeries(PricePane,SMA.Series(Close,50),Color.Blue,LineStyle.Solid,2);
PlotSeriesOscillator( paneRsi, rsiHma, 50, 0,
Color.FromArgb( 50, Color.Red ), tp, Color.DarkGray, ls, 2);
PlotSeriesOscillator( paneRsi, rsiHma, 90, 0,
Color.FromArgb( 70, Color.Red ), tp, tp, ls, 2);
PlotSeries(paneRsi,RSI.Series(SMA.Series(Close,9),9),Color.Violet,ls,2);
DrawHorzLine( paneRsi, 90, Color.Blue, ls, 1 );
DrawHorzLine( paneRsi, 50, Color.Red, ls, 1 );
for(int bar = GetTradingLoopStartBar(60); bar < Bars.Count; bar++)
{
SetBackgroundColor( bar, Color.FromArgb( 10, Color.Cyan ) );
if (IsLastPositionActive)
{
Position p = LastPosition;
double Stop = p.EntryPrice * (1 - paramSL.Value / 100.0d);
double Target = p.EntryPrice * (1 + paramPT.Value / 100.0d);
bool hmaRsiOver90 = rsiHmabar > 90;
if( hmaRsiOver90 )
ExitAtMarket(bar + 1, p);
else if( !ExitAtStop(bar + 1, p, Stop ) )
ExitAtLimit(bar + 1, p, Target );
}
else
{
bool closeOverSMA = (Closebar > mabar);
bool hmaUpside = TurnUp(bar, hma4);
bool hmaRsiBelow50 = rsiHmabar <= 50;
bool closeOverOldClose = (Closebar > Closebar-59);
if ( closeOverSMA && hmaUpside &&
hmaRsiBelow50 && closeOverOldClose )
if( BuyAtMarket(bar + 1) != null )
LastPosition.Priority = -rsiHmabar;
}
}
}
}
}