Gold Customer
Joined: 10/19/2004 Posts: 56

Guys: I've got a challenge for you. I'm trying to write a custom indicator/PCF that will plot a 20 period Hull Moving Average. The goal behind this type of average is to remove some of the lag inherent in traditional moving averages. Hull defines this average as:
Integer(SquareRoot(Period)) WMA [2 x Integer(Period/2) WMA(Price) Period WMA(Price)] (where WMA is the weighted moving average)
He provides the Metastock formula as: 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);
He also provides the SuperCharts formula as: Input: period (Default value 20) waverage(2*waverage(close,period/2)waverage(close,period), SquareRoot(Period))
Can a PCF be created for this? If you need more info on this type of moving average, just web search: "Hull moving average."
I've been struggling with this for a while. Any help would be greatly appreciated.
Thanks, Vas


Worden Trainer
Joined: 10/7/2004 Posts: 63,198

Please try the following as a Custom Indicator with Plot using price scale checked:
124 * C / 1155 + 92 * C1 / 525 + 4777 * C2 / 23100 + 79 * C3 / 385 + 401 * C4 / 2310 + 164 * C5 / 1155 + 17 * C6 / 154 + 13 * C7 / 165 + 109 * C8 / 2310 + 6 * C9 / 385  37 * C10 / 2310  191 * C11 / 5775  151 * C12 / 3850  4 * C13 / 105  C14 / 30  C15 / 35  C16 / 42  2 * C17 / 105  C18 / 70  C19 / 105  C20 / 210  C21 / 525  C22 / 2100
The same formula can be used as a Personal Criteria Formula.
You may be interested in the following:
Plotting Custom Indicators with Examples How to create a Personal Criteria Forumula (PCF) Handy PCF example formulas to help you learn the syntax of PCFs!
Bruce Personal Criteria Formulas TC2000 Support Articles


Registered User Joined: 1/1/2005 Posts: 2,645

The Hull Moving Average is of the form:
WMA(2*WMA(C,P)WMA(C,Q),R)
The lag of a WMA of Period P is (P1)/3. Combining lags as described in the references below, we find that the lag of the MA is:
2*(P1)/3(Q1)/3+(R1)/3
For Q = 2*P as in the Hull MA, the lag is (R2)/3. Notice that the inner MA:
2*WMA(C,P)WMA(C,Q)
is a ZeroLag MA if Q = 2*P1. If Q = 2*P, as in the Hull MA, the lag is 1/3.
Please notice the MA:
2*WMA(C,P)WMA(WMA(C,P),P)
is a ZeroLag MA. I do not at the moment know why the Hull MA might be preferred.
Please see:
Setting up a DEMA MACD
Lag Efficient Moving Average
Thanks, Jim Murphy


Gold Customer
Joined: 3/12/2005 Posts: 32

Very cool, I have been wondering if Worden could do this. Let me ask for one other twist...is it possible to have this HULL MA turn green when prices are above, and red when prices are below?
That is how my HULL script displays in Esignal.
Many thanks fot this thread! KingCAMBO


Registered User Joined: 1/28/2005 Posts: 6,048

This is the only technique I know of to make an indicator "change color" in telechart:
(not sure if you are using the blocks system)
Indicator Color, Visuals, and MACD.
Thanks diceman


Registered User Joined: 1/28/2005 Posts: 6,048

"The Hull Moving Average is of the form:
WMA(2*WMA(C,P)WMA(C,Q),R)"

bustermu
Which is the Hull length P or R?
Q is 2*P?
What is R's relationship to P,Q?
Thanks
diceman


Registered User Joined: 1/1/2005 Posts: 2,645

QUOTE (diceman) "The Hull Moving Average is of the form:
WMA(2*WMA(C,P)WMA(C,Q),R)"
diceman,
We can let P, Q, and R be any positive integers we please in the above moving average. If x is a positive real number, define INT( x ) to be the integer part of x. The above is a Hull Moving Average of Period Q if and only if:
P = INT(Q/2)
R = INT(SQR( Q ))
Why Q is called the Period, why the above relationships are imposed, and why one might prefer a Hull MA to some ZeroLag MA, I do not yet know.
Thanks,
Jim Murphy


Registered User Joined: 9/12/2010 Posts: 121

Hello. Could please construct this pcf for a 9 period? Thanks.


Worden Trainer
Joined: 10/7/2004 Posts: 63,198

Please try the following Indicator Formula:
(81 * C + 111 * C1 + 98 * C2 + 50 * C3 + 2 * C4  19 * C5  22 * C6  16 * C7  10 * C8  4 * C9  C10) / 270
Bruce Personal Criteria Formulas TC2000 Support Articles


Gold Customer
Joined: 12/21/2004 Posts: 35

The following formula gives percent change between 12 month price change and a front loaded, double three month plus 6 month price change calculation. The problem is when one or both elements is negative, it gives the wrong indication. For example; Front load gain 8.79, 12 month gain 32.44, Percent change returns 127.37. OR Front load gain 5.65, 12 month gain 1.84 =, Percent chande returns 206.49. Anyway around this? Here is the PCF:
((((C  C63) / (C63) * 100)*2 + ((C  C126) / (C126) * 100)  ((C  C252) / (C252) * 100)) / ((C  C252) / (C252) * 100))*100


Worden Trainer
Joined: 10/7/2004 Posts: 63,198

You can just subtract the two values:
100 * (2 * C / C63 + C / C126  C / 252  2)
But you shouldn't try to calculate the percent change.
Calculating a percent change in something that can cross through or equal zero pretty much shouldn't be done at all. Think about it, what is the percent change from 0 to 5?
(hint, it is not 100%, think what happens when you divide by zero)
Bruce Personal Criteria Formulas TC2000 Support Articles


Registered User Joined: 10/7/2004 Posts: 1,072

Hi Bruce,
This was presented as a Hull 20Period:
124 * C / 1155 + 92 * C1 / 525 + 4777 * C2 / 23100 + 79 * C3 / 385 + 401 * C4 / 2310 + 164 * C5 / 1155 + 17 * C6 / 154 + 13 * C7 / 165 + 109 * C8 / 2310 + 6 * C9 / 385  37 * C10 / 2310  191 * C11 / 5775  151 * C12 / 3850  4 * C13 / 105  C14 / 30  C15 / 35  C16 / 42  2 * C17 / 105  C18 / 70  C19 / 105  C20 / 210  C21 / 525  C22 / 2100
And, this was offered as a Hull 9Period:
124 * C / 1155 + 92 * C1 / 525 + 4777 * C2 / 23100 + 79 * C3 / 385 + 401 * C4 / 2310 + 164 * C5 / 1155 + 17 * C6 / 154 + 13 * C7 / 165 + 109 * C8 / 2310 + 6 * C9 / 385  37 * C10 / 2310  191 * C11 / 5775  151 * C12 / 3850  4 * C13 / 105  C14 / 30  C15 / 35  C16 / 42  2 * C17 / 105  C18 / 70  C19 / 105  C20 / 210  C21 / 525  C22 / 2100
Yet, they both are identical. So, I assume they are both the Hull 20Period.
Then, later you said try this:
(81 * C + 111 * C1 + 98 * C2 + 50 * C3 + 2 * C4  19 * C5  22 * C6  16 * C7  10 * C8  4 * C9  C10) / 270
Plotted on the same price chart as the Hull 20Period, the above moves faster. Can you please explain exactly what the above is. Thanks, Bruce.


Worden Trainer
Joined: 10/7/2004 Posts: 63,198

The first formula in your post is the 20Period Hull Moving Average.
The second formula in your post was not offered as a 9Period Hull Moving Average, it is just a quote of the 20Period Hull Moving Average in a question from julian1000 asking for a 9Period Hull Moving Average.
The third formula in your post is in the response to that question and actually provides the 9Period Hull Moving Average.
Bruce Personal Criteria Formulas TC2000 Support Articles


Registered User Joined: 10/7/2004 Posts: 1,072

How about PCFs for Hull 9Period crossing up Hull 20Period  and also crossing down?


Worden Trainer
Joined: 10/7/2004 Posts: 63,198

The cross up would be:
40050 * C + 49038 * C1 + 32467 * C2 + 2560 * C10 + 6876 * C11 + 8154 * C12 + 7920 * C13 + 6930 * C14 + 5940 * C15 + 4950 * C16 + 3960 * C17 + 2970 * C18 + 1980 * C19 + 990 * C20 + 396 * C21 + 99 * C22 > 4160 * C3 + 34550 * C4 + 44150 * C5 + 39890 * C6 + 28700 * C7 + 17510 * C8 + 6320 * C9 AND 40050 * C1 + 49038 * C2 + 32467 * C3 + 2560 * C11 + 6876 * C12 + 8154 * C13 + 7920 * C14 + 6930 * C15 + 5940 * C16 + 4950 * C17 + 3960 * C18 + 2970 * C19 + 1980 * C20 + 990 * C21 + 396 * C22 + 99 * C23 <= 4160 * C4 + 34550 * C5 + 44150 * C6 + 39890 * C7 + 28700 * C8 + 17510 * C9 + 6320 * C10
And the cross down would be:
40050 * C + 49038 * C1 + 32467 * C2 + 2560 * C10 + 6876 * C11 + 8154 * C12 + 7920 * C13 + 6930 * C14 + 5940 * C15 + 4950 * C16 + 3960 * C17 + 2970 * C18 + 1980 * C19 + 990 * C20 + 396 * C21 + 99 * C22 < 4160 * C3 + 34550 * C4 + 44150 * C5 + 39890 * C6 + 28700 * C7 + 17510 * C8 + 6320 * C9 AND 40050 * C1 + 49038 * C2 + 32467 * C3 + 2560 * C11 + 6876 * C12 + 8154 * C13 + 7920 * C14 + 6930 * C15 + 5940 * C16 + 4950 * C17 + 3960 * C18 + 2970 * C19 + 1980 * C20 + 990 * C21 + 396 * C22 + 99 * C23 >= 4160 * C4 + 34550 * C5 + 44150 * C6 + 39890 * C7 + 28700 * C8 + 17510 * C9 + 6320 * C10
Bruce Personal Criteria Formulas TC2000 Support Articles


Gold Customer
Joined: 3/3/2013 Posts: 56

Please, if you could write a PCF for the Hull 20 Xing it's own moving avg 2 in either direction.


Gold Customer
Joined: 3/3/2013 Posts: 56

Please also include the Hull 9 Xing it's own moving avg 2 in either direction.


Worden Trainer
Joined: 10/7/2004 Posts: 63,198

A 20 period Hull moving average crossing through its own 2 period simple moving average in either direction can be written as follows.
SGN(2480 * C + 1568 * C1 + 729 * C2  37 * C3  730 * C4  730 * C5  730 * C6  730 * C7  730 * C8  730 * C9  730 * C10  394 * C11  142 * C12 + 26 * C13 + 110 * C14 + 110 * C15 + 110 * C16 + 110 * C17 + 110 * C18 + 110 * C19 + 110 * C20 + 66 * C21 + 33 * C22 + 11 * C23) <> SGN(2480 * C1 + 1568 * C2 + 729 * C3  37 * C4  730 * C5  730 * C6  730 * C7  730 * C8  730 * C9  730 * C10  730 * C11  394 * C12  142 * C13 + 26 * C14 + 110 * C15 + 110 * C16 + 110 * C17 + 110 * C18 + 110 * C19 + 110 * C20 + 110 * C21 + 66 * C22 + 33 * C23 + 11 * C24)
A 9 period Hull moving average crossing through its own 2 period simple moving average in either direction can be written as follows.
SGN(81 * C + 30 * C1  13 * C2  48 * C3  48 * C4  21 * C5  3 * C6 + 6 * C7 + 6 * C8 + 6 * C9 + 3 * C10 + C11) <> SGN(81 * C1 + 30 * C2 + 13 * C3 + 48 * C4 + 48 * C5 + 21 * C6 + 3 * C7 + 6 * C8 + 6 * C9 + 6 * C10 + 3 * C11 + C12)
Bruce Personal Criteria Formulas TC2000 Support Articles


Guest1 