Hull Moving Average Trading System

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
wajodi
Posts: 6
Joined: 29 Jan 2006
Has thanked: 3 times

Hull Moving Average Trading System

Postby wajodi » 06 Nov 2007

Hi, Has anyone heard of this system? I would like to try it out, apparently it's based around a low lag Weighted Moving Average. I wrote to Alan Hull the original author of this moving average indicator and his reply is copied below.
Stanley do you think you could code it for me based on what Alan says in his email?, (shown below) I'm also attaching the PDF file Alan Hull sent to me in this email. I've also located some code written on another forum for MT I'm not sure if it will help but I'm attaching it in an TXT file also.

Thanks, hope you can assist me....... Wajodi

Email from Alan Hull Follows:
Hi Wayne

We only provide the intellectual property which is the attached article and it is up to the software providers to add it in to their products - I would suggest that you go back to your own software provider, Multi Charts, and ask if they will upgrade their program using the attached PDF article as a guide....

Regards,
Alan

ActVest Pty Ltd
ACN: 101 040 939
http://www.alanhull.com
Ph: +613 9778 7061
Fax: +613 9778 7062
Attachments
Hull Moving Average.pdf
(107.78 KiB) Downloaded 808 times
Hull Code from MetaTrader Indicators and Expert Advisors Forum .txt
(4.27 KiB) Downloaded 503 times

SP
Posts: 441
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 280 times

Postby SP » 08 Nov 2007

This is the code from atavachron from the TS forum:

Function: jtHMA

Code: Select all

{jtHMA - Hull Moving Average Function}
{Author: Atavachron}
{May 2005}      
   
Inputs: price(NumericSeries), length(NumericSimple);
Vars: halvedLength(0), sqrRootLength(0);
 
{
 Original equation is:
 ---------------------
 waverage(2*waverage(close,period/2)-waverage(close ,period), SquareRoot(Period)
 Implementation below is more efficient with lengthy Weighted Moving Averages.
 In addition, the length needs to be converted to an integer value after it is halved and
 its square root is obtained in order for this to work with Weighted Moving Averaging
}
 
if ((ceiling(length / 2) - (length / 2))  <= 0.5) then
   halvedLength = ceiling(length / 2)
else
   halvedLength = floor(length / 2);
 
if ((ceiling(SquareRoot(length)) - SquareRoot(length))  <= 0.5) then
   sqrRootLength = ceiling(SquareRoot(length))
else
   sqrRootLength = floor(SquareRoot(length));
 
Value1 = 2 * WAverage(price, halvedLength);
Value2 = WAverage(price, length);
Value3 = WAverage((Value1 - Value2), sqrRootLength);
 
jtHMA = Value3;


Indicator:

Code: Select all

{jtHMA - Hull Moving Average Indicator}
{Author: Atavachron}
{May 2005}
   
{
   Inputs:
   -------
   price: the time series being smoothed, usually Close, High, etc,
          but could be RSI(Close, 25) for example.
   length: the length of the MA, pretty meaningless in the normal sense
           of moving averages, as this quantity is heavily modified
         in the code.  You need to experiment, do not just use a setting
         of 20 because that is what works for you with Simple Moving Averages.
   zeroLine: if you are using this in an indicator pane, you might
             want to display a centre line of some sort, ths allows
             one to set its value
   zeroVisible: boolean variable, determines whether the centre line
               (zeroLine) is plotted.
   upColour: If you wish to differentiate upward movements by colour coding.
   downColour: If you wish to differentiate downward movements by colour coding.
   colourDeltaBar: Set this to 1 if you wish the colour change to be effective on
                   the actual bar where the direction change occurred.
               Set this to 0 for default behaviour.  All other values
                    are pretty meaningless.
}      
 
Inputs: price(Close), length(21),
      zeroLine(0.0), zeroVisible(false),
       upColour(Blue), downColour(Red), colourDeltaBar(1);
 
Value1 = jtHMA(price, length);
 
Plot1(Value1, "jtHMA");
 
If ZeroVisible = true then
   Plot2(zeroLine, "Zero");
 
{ Color criteria }
if (Value1 > Value1[1]) then 
   SetPlotColor[colourDeltaBar](1, upColour)
else if (Value1 < Value1[1]) then 
   SetPlotColor[colourDeltaBar](1, downColour);   


Strategy

Code: Select all

{ jtHMA strategy }
 
inputs: price(Close), jthmaLength( 21 ), upColour(Blue), downColour(Red);
variables: Avg(0), colour(0);
 
Avg = jthma( price, jthmaLength ) ;
 
if Avg > Avg[1] then colour = upColour;
if Avg < Avg[1] then colour = downColour;
 
 
{buy sell Criteria}
 
if colour[1] <> colour then
   if colour = upColour then
      Buy ( "jup" ) next bar at market ;
 
if colour[1] <> colour then 
   if colour = downColour then 
      sell short ( "jdn" ) next bar at market ;
 
 

itai007
Posts: 69
Joined: 14 Jun 2007

I cant compile this. pls help

Postby itai007 » 11 Dec 2007

could some1 post an actual code attachment to be downloaded and imported ?

Thanks
Itai

Laurent
Posts: 159
Joined: 20 Nov 2010
Location: France
Has thanked: 76 times
Been thanked: 32 times

Re: Hull Moving Average Trading System

Postby Laurent » 27 Jan 2011

The original version coded quickly, hope it helps.

Code: Select all

inputs:
   DataValue ( NumericSeries ),
   Length ( NumericSimple ) ;

Value1 = 2 * WAverage( DataValue, Length / 2 ) ;
Value2 = WAverage( DataValue, Length ) ;
Value3 = WAverage( Value1 - Value2, SquareRoot(Length) );

HMA = Value3 ;

vetrader
Posts: 3
Joined: 04 Dec 2009

Re: Hull Moving Average Trading System

Postby vetrader » 03 Jun 2011

Hi
I tried to compile the code given above but they all gave me errors (both function and indicator)....can someone help?

For the function i get this msg:
------ Compiled with error(s): ------
assignment is allowed only for variables or array elements
errLine 20, errColumn 0, errLineEnd 20, errColumnEnd 0

So for the indicator, i get an unknown function.....

Thanks
vetrader

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Hull Moving Average Trading System

Postby TJ » 03 Jun 2011

vetrader wrote:Hi
I tried to compile the code given above but they all gave me errors (both function and indicator)....can someone help?

For the function i get this msg:
------ Compiled with error(s): ------
assignment is allowed only for variables or array elements
errLine 20, errColumn 0, errLineEnd 20, errColumnEnd 0

So for the indicator, i get an unknown function.....

Thanks
vetrader

did you compile the function as a function?


ps. you need to compile the function before compiling the indicator.

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Hull Moving Average Trading System

Postby TJ » 03 Jun 2011

for those who are interested in different renditions of moving averages,
here's a collection to fuel your research:
look under Moving Averages & Trend Followers
http://www.tradersxchange.com/

vetrader
Posts: 3
Joined: 04 Dec 2009

Re: Hull Moving Average Trading System

Postby vetrader » 03 Jun 2011

Thks for the quick reply, TJ

Yes, i compiled it as a function. The full error msg:

------ Build started: ------
Study: "HMA" (Function)
Please wait ....
------ Compiled with error(s): ------
assignment is allowed only for variables or array elements
errLine 31, errColumn 0, errLineEnd 31, errColumnEnd 0

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Hull Moving Average Trading System

Postby TJ » 03 Jun 2011

vetrader wrote:Thks for the quick reply, TJ

Yes, i compiled it as a function. The full error msg:

------ Build started: ------
Study: "HMA" (Function)
Please wait ....
------ Compiled with error(s): ------
assignment is allowed only for variables or array elements
errLine 31, errColumn 0, errLineEnd 31, errColumnEnd 0


you have to compile it with the name "jtHMA" .

vetrader
Posts: 3
Joined: 04 Dec 2009

Re: Hull Moving Average Trading System

Postby vetrader » 03 Jun 2011

solved! Thks for your help, TJ!


Return to “User Contributed Studies and Indicator Library”