[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hull Moving average



PureBytes Links

Trading Reference Links




The Hull Moving Average solves the age old dilemma of making a moving average more responsive to current price activity whilst maintaining
curve smoothness. In fact the HMA almost eliminates lag altogether and manages to improve smoothing at the same time.
To understand how it achieves both of these opposing outcomes simultaneously we need to start with an easily understood
frame of reference.

All codes are below;-)

Best regards,
Krzysztof




*********************************************************************

Type : Function, Name : jtHMA

{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;


*********************************************************


Type : Indicator, Name : jtHMA

{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);


***********************************************************










ChasW wrote:

December 2005 Trading Tips Newsletter
----- Original Message ----- From: Ensign Software
To: Ensign User
Sent: Friday, December 30, 2005 11:33 AM
Subject: Trading Tips Newsletter - December 2005 issue




Hull Moving Average
by Alan Hull
www.alanhull.com
The Hull Moving Average solves the age old dilemma of making a moving
average more responsive to current price activity whilst maintaining curve
smoothness. In fact the HMA almost eliminates lag altogether and manages to
improve smoothing at the same time. To understand how it achieves both of
these opposing outcomes simultaneously we need to start with an easily
understood frame of reference. The following chart contains a 16 week
simple moving average which constantly lags the price activity and has poor
smoothness.

Firstly, solving the problem of curve smoothing can be done by taking an
average of the average, i.e.. 16 period SMA(16 period SMA(Price)). The bad
news is that it causes a huge increase in lag as seen below.

Solving the problem of lag is a bit more involved and requires an
explanation with numbers rather than charts. Consider a series of 10
numbers from '0' to '9' inclusive and imagine that they are successive price
points on a chart with 9 being the most recent price point at the right hand
leading edge. If we take the 10 period simple average of these numbers
then, not surprisingly, we will determine the midpoint of 4.5 which
significantly lags behind the most recent price point of 9. Here's the
clever bit…first let's halve the period of the average to 5 and apply it to
the most recent numbers of 5,6,7,8, and 9, the result being the midpoint of
7.

Finally, to remove the lag we take the midpoint of 7 and add the difference
between the two averages which equals 2.5 (7 - 4.5). This gives a final
answer of 9.5 (7 + 2.5) which is a slight overcompensation. But this
overcompensation is very handy because it offsets the lagging effect of the
nested averaging. Hence the result of combining these 2 techniques is a
near perfect balance between lag reduction and curve smoothing.

The HMA manages to keep up with rapid changes in price activity whilst
having superior smoothing over an SMA of the same period. The HMA employs
weighted moving averages and dampens the smoothing effect (and resulting
lag) by using the square root of the period instead of the actual period
itself…as seen below.

WMA (2 x WMA(Price,Integer(Period/2)) -
WMA(Price,Period),Integer(SquareRoot(Period)))