Hull Moving Average buffer HMA Comes with formula, buffer calculation step and VBA code The Hull moving average for n periods is calculated as such HMA = WMA of (2 x WMA for last n/2 periods – WMA for last n periods) for last k periods , where k =square root of n rounded to a whole number n/2 is also rounded buffer to a whole number. and the WMA refers to a weighted moving average . Both n is specified by the user. A single WMA will often lag behind current prices if n is large. buffer On the other hand, too small a value of n will lead to an unsmooth moving average buffer which might give false signals. On closer observation, the HMA consists of 3 steps to reduce lags and smooth the kinks in a typical moving average. buffer Reduce the period by half using WMA for the last n/2 periods to reduce the lag effect. Make the HMA even more responsive by adding (WMA for last n/2 periods – WMA for last n periods) to the WMA for the last n/2 periods in step 1. Smooth the output of 2 by applying a WMA of square root n periods. VBA Code Method A The Hull moving average is a series of nested weighted moving averages. Using the WMA custom function for calculating weighted moving averages , the Hull moving buffer average can be calculated following the steps below without a custom function of its own. Calculate the n periodweighted moving average of a series "=WMA(price for n periods)" Calculate the n/2 period buffer weighted moving average of a series"=WMA(price for n/2 periods)". Round n/2 to the nearest whole number Create a time series with 2*WMA from Step 2 - WMA from Step 1 The HMA is the WMA of the series in Step 3. "=WMA(Step 3 outputs fo k period)" Method B Method B automates the entire process in Method A using sub routines. buffer It produces in 4 columns the respective outputs from Step 1 to Step 4 of Method A.
Sub Runthis() Dim close1 As Range, output As Range, n As Long Dim k As Long Set close1 = Range("E2:E11955") Set output = Range("H2:H11955") n = 5 'number of historical periods to look at 'needed for certain indicators k = 10 'number of historical periods to look at 'needed for certain indicators as slow average HMA_1 close1, output, n, k End Sub Sub WMA_1(close1 As Range, output As Range, n As Long) For a = 1 To n output(a, 1).Value buffer = a Next a numrange = Range(output(1, 1), output(n, 1)).Address pricerange = Range(close1(1, 1), close1(n, 1)).Address(False, False) output(n, 2).Value = "=sumproduct(" & numrange & "," & pricerange & ")/(" & n & "*(" & n & "+1)/2)" output(n, 2).Copy output.Offset(0, 1) Range(output(1, 2), output(n - 1, 2)).Clear End Sub Sub HMA_1(close1 As Range, output As Range, n As Long, k As Long) WMA_1 close1, output, n Dim j As Long j = WorksheetFunction.Round(n / 2, 0) WMA_1 close1, output.Offset(0, 2), j WMAn = output(n, 2).Address(False, False) WMAj = output(n, 4).Address(False, False) output(n, 5).Value = "=" & WMAn & "-" & WMAj output(n, 5).Copy output.Offset(0, 4) Range(output(1, 5), output(n - 1, 5)).Clear WMA_1 output.Offset(0, 4), output.Offset(0, 5), k End Sub
The objective buffer of Finance4Traders is to help traders get started buffer 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)
Please use this website in an appropriate and considerate manner. This means that you should cite Finance4Traders by at least providing a link back to this site if you happen to use any of our content. In addition, you are not permitted to make use of our content in an unlawful manner. You should also understand that our content is provided with no warranty and you should independently verify our content before relying on them. Do refer to the site content policy and privacy policy when visiting this site.
It looks like you have left out the '2*' from the vba statement above 'output(n, 5).Value = "=" & WMAn & "-" & WMAj'. It should read 'output(n, 5).Value = "=2*" buffer & WMAn & "-" & WMAj'. Your code has been of great assistance, buffer thanks. June 4, 2013 at 7:47 PM Anonymous said...
Good morning, I have to say that your website is very useful. Congratulations! I was looking for information about Hull Moving Average formulas to write a code in VBA (Excel) for entry signals. After doing some googling I have found your code. Apart for this I've found two more websites with EXcel formulas that builds the HMA formula. From here: (I think they are reliable as yours) 1) http://www.financialwisdomforum.org/gummy-stuff/MA-stuff.htm (must download) 2) http://traders.com/Documentation/FEEDbk_docs/2010/12/TradingIndexesWithHullMA.xls My purpose buffer was to contrast th
No comments:
Post a Comment