HMA is, in my humble view, the best MA there is out there. Load it! Use it!
The good news is it's there with NT7 (and I guess NT8).
I've had a peek at the code and this is it:
double value1 = 2 * WMA(Inputs[0], (int)(Period / 2))[0];
double value2 = WMA(Inputs[0], Period)[0];
diffSeries.Set(value1 - value2);
Value.Set(WMA(diffSeries, (int) Math.Sqrt(Period))[0]);
Alan Hull has done a great job in so few lines of code (a bit longer if you include the WMA, but that isn't complex). My gratitude to him.
There is, I believe, a tiny section that could be 'upgraded'.
In the final line, again below, please look at the section in red:
Value.Set(WMA(diffSeries, (int) Math.Sqrt(Period))[0]);
In NT7 (and obviously C# - and as it happens, Excel), (int) x gives the highest integer lower than or equal to the double (decimal) x (or floor x ). So:
(int) 6 = floor 6 = 6;
(int) 5.75 = floor 5.75 = 5;
(int) 5.25 = floor 5.25 = 5;
But what makes sense mathematically is for this section to give the rounded square root, not floor(square root).
So I've 'Saved As...' HMA to make me own editable script and I've tried to put something like:
Value.Set(WMA(diffSeries, Math.Round( Sqrt(Period))[0] ) );
I've tried a whole combination of 'int's and 'double's but the compiler likes none of them!
Could someone please tell how to to accomplish this!
Many thanks in advance.
Comment