Sharing investing and trading ideas. Helping traders get started.
Advertisement

Friday, June 19, 2009

Welles Wilder's Moving Average

Welles Wilder's Moving Average WWMA
Comes with formula, calculation steps and VBA code

The Welles Wilder's moving average, WWMA is computed as follows.

WWMAt=[Pricet + WWMAt-1 x (n-1)] / n
WWMAt=1/n x Pricet + (1-1/n) x WWMAt-1

, where n is specified by the user.

It becomes apparent that the Welles Wilder's moving average is an approximation of the exponential moving average, which is shown below as

EMAt= α x Pricet+(1-α) x EMAt-1

, where α=2/(n+1)

Click here to read more about the exponential moving average.

VBA Code
Method A uses functions, while Method B uses sub procedures to calculate CMF. Method B is faster and more flexible.

Method A

'Paste this code into your ThisWorkBook code window in VBA. Right Click This WorkBook in Project Explorer and click View Code.
Private Sub Workbook_Open()
AddUDF
End Sub

'The rest belong to any module
Sub AddUDF()
'Tells Excel to includes these in list of functions, add descriptions to them and create a new category called Technical Indicators.
Application.MacroOptions macro:="WWMA", _
Description:="Returns Welles Wilder's Moving Average" & Chr(10) & Chr(10) & _
"Select last period's EMA or last period's price if current period is the second observation." & Chr(10) & Chr(10) & _
"Followed by current price and n.", _
Category:="Technical Indicators"

Public Function WWMA(WWMAYesterday, price, n)
WWMA = (price + (n - 1) * WWMAYesterday) / n
End Function

Once you are done with the above, you can compute the moving average by typing into any cell "=WWMA([Last Period WWMA],[Current Price],[n])". Enter last period price as last period WWMA if you are computing the first WWMA of your dataset.

Method B
To run Method B, you have to copy the Runthis sub of Method B from the page on Accumulation/Distribution Line into your module. You also must run WWMA from the Runthis sub.

'Copy the following line into the Runthis sub
'Just before the line End Sub
'Disable all other macros that Runthis will call e.g. CLV, ADL, by
'marking them out as comments with single quotes
WWMA_1 close1, output, n

'Followed by the following new sub
Sub WWMA_1(close1 As Range, output As Range, n As Long)
output(0, 1).Value = "WWMA"
close0 = close1(1, 1).Address(False, False)
close1a = close1(2, 1).Address(False, False)
output1 = output(1, 1).Address(False, False)
output(2, 1).Value = "=(" & close1a & "+(" & n & "-1)*" & output1 & ")/" & n
output(2, 1).Copy output
output(1, 1).Clear
output(2, 1).Value = "=(" & close1a & "+(" & n & "-1)*" & close0 & ")/" & n
End Sub

Other References

http://fxtrade.oanda.com/learn/graphs/indicators/adx.shtml#atr


Like what you have just read? Digg it or Tip'd it.
The objective of Finance4Traders is to help traders get started by bringing them unbiased research and ideas. Since late 2005, I have been developing trading strategies on a personal basis. Not all of these models are suitable for me, but other investors or traders might find them useful. After all, people have different investment/trading goals and habits. Thus, Finance4Traders becomes a convenient platform to disseminate my work...(Read more about Finance4Traders)

0 comments:

Post a Comment