logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
pumrysh  
#1 Posted : Wednesday, July 4, 2007 2:07:21 PM(UTC)
pumrysh

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/28/2004(UTC)
Posts: 110

All,

Seems we never tire of playing with moving averages. The other day I
discussed the DEMA and TEMA and how they were derived. Now I would
like to introduce the idea of using a mechanism/s to futher smooth
your moving averages.

One of the problems in performing the task is how to overcome the
problem of a variable input that metastock will not normally except.
In the past I've discussed the virtues of using a DLL. The purpose
of using a DLL was to overcome metastock's shortcoming of the
variable input value. Thus you could use an indicator and its
velocity or momentum value for your lookback periods and allow them
to change with the market. Great idea but I also want to introduce
you to one more method that I thought you might enjoy.

That method is the use of the LastValue function. Below you will
find some information about the Hull Moving average. I thought it
explained very well the reason for smoothing moving averages and how
that is accomplished. At the end of the discussion you will also see
three indicators. The first comes from the article and shows how you
write the formula for a manual input of the square root value. The
next is a DLL version which I wrote and automatically scales in the
square root value. The last is a version of the same indicator
written by Alan Hull and uses the LastValue function. Notice in this
version that I have commented in where you could insert another
indicator inplace of the square root.

Have fun and enjoy,


Preston



http://www.justdata.com.au/Journals/AlanHull/hull_ma.htm

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.

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

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.

Integer(SquareRoot(Period)) WMA [2 x Integer(Period/2) WMA(Price)
- Period WMA(Price)]

Unfortunately the MetaStock version of the indicator requires
the 'Integer part of the square root of the period' to be entered
manually as an input. For example, if the period is 25
then 'sqrtperiod' equals 5 and if the period is 30 then 'sqrtperiod'
also equals 5. ('sqrtperiod' increments up to 6 when period = 36 and
so on.)

MetaStock Formula
period:=Input("Period",1,200,20) ;
sqrtperiod:=Input("Square Root of Period",1,20,4);
Mov(2*(Mov(C,period/2,W))
-Mov(C,period,W),sqrtperiod,W);{end}


{Hull MA}
{dll version}
{written by Preston Umrysh}
{This indicator uses Dll software
developed by MetaStock Forum Crew}
{http://forum.equis.com)}
period:=Input("Period",1,250,20) ;
ExtFml( "ForumDLL.VarMOV",2*(Mov(C,period/2,W))
-Mov(C,period,W),Sqrt(period),W);{end}


{Hull MA}
{Lastvalue version}
period:=Input("Period",1,200,20) ;
sqrtperiod:= Sqrt(period);{another indicator could be used here}
HMA:=Mov(2*Mov(C,period/2,W)
-Mov(C,period,W),LastValue(sqrtperiod),W);
HMA;{end}

Found at http://trader.online.pl/MSZ/e-w-Hull_Moving_Average.html

minnamor  
#2 Posted : Thursday, July 5, 2007 12:49:33 AM(UTC)
minnamor

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/27/2005(UTC)
Posts: 126
Location: Italy

Could you please provide an example of the Hull MA Lastvalue Version in which another indicator (say momentum) is used in the following line:
sqrtperiod:= Sqrt(period);{another indicator could be used here}
thanks.
pumrysh  
#3 Posted : Thursday, July 5, 2007 8:48:55 AM(UTC)
pumrysh

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/28/2004(UTC)
Posts: 110

Sure!

{Hull MA}

{Lastvalue version}

period:=Input("Period",1,200,20) ;

sqrtperiod:= RSI(period);{another indicator could be used here}

HMA:=Mov(2*Mov(C,period/2,W)

-Mov(C,period,W),LastValue(sqrtperiod),W);

HMA;{end}

That's a quicky version. A more eloquent version would be:

{Lastvalue version}

(RSI version}

period:=Input("Period",1,250,20) ;

period2:=Input("Factor Smoothing Period",1,250,21) ;

factor:= RSI(period2);{another indicator could be used here}

HMA:=Mov(2*Mov(C,period/2,W)

-Mov(C,period,W),LastValue(factor),W);

HMA;{end}

By using the RSI you are using an indicator that is scaled from 0 to 100. Any indicator with similar scaling could be used in its place. Should you find that using a 0 to 100 scale provides too much overshoot you could change the scale to 0 to 10 by simply dividing the values by 10 like this:

factor:= RSI(period2)/10;

In the more eloquent version I have also given you the option of using a different lookback period for the smoothing factor.

Hope this helps,

Preston

Jose  
#4 Posted : Thursday, July 5, 2007 1:21:48 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
The LastValue()-based indicator code above produces hindsight-based dynamic outputs. i.e., past values change in retrospect as new data is loaded, giving the impression that the indicator produced some useful output in the past - when in fact, its actual plot value was very different at the time. It's common knowledge that one should take care with all hindsight-based functions, as this often results in a "fool's gold" type outcome. jose '-)
pumrysh  
#5 Posted : Thursday, July 5, 2007 2:41:22 PM(UTC)
pumrysh

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/28/2004(UTC)
Posts: 110

Jose,

Thanks! I didn't even think about that.

Since that's the case the DLL version should still work and the formula would be:

{Hull MA} {RSI factored}
{dll version}
{written by Preston Umrysh}
{This indicator uses Dll software
developed by MetaStock Forum Crew}
{http://forum.equis.com)}
period:=Input("Period",1,250,20) ;

period2:=Input("Factor Smoothing Period",1,250,21) ;

factor:= RSI(period2);{another indicator could be used here}
HMA:=ExtFml( "ForumDLL.VarMOV",2*(Mov(C,period/2,W))
-Mov(C,period,W), factor,W); HMA; {end}

Enjoy,

Preston

Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.