Accessing Hull Moving average from other study

Shtick Hustler

Well-known member
Joined
Oct 15, 2020
Posts
105
Likes
46
On searching through the forums, I see there's no easy way to get values from another study.

And, some studies are broken out into Utility.java to enable access. I see that HMA is not among them.

Has anyone broken out the HMA into a custom utility class that they'd be willing to share?

If not, is it possible for the MW SDK team to add it to utility? Or, even better, as a convenience method of DataSeries?
Or is it too complex to be feasible?
 
Last edited:

Spin

Well-known member
Joined
May 22, 2019
Posts
477
Likes
191
I agree with you: it's a little bit sad that HMA cannot be accessed like all the other MA's.

Then again: HMA is a 'multilayered' MA: it uses MA's to calculate the end product.

Why exactly do you need to access the HMA ?
What are you planning to do with it ?

I coded my own version of the HMA, and allow the coloring of bars according to the HMA's values:
https://vb6.systems/studies/
I might be able to help ...

(Full disclosure: I am the maintainer of VB6.systems, and I put Studies up there for sale)
 

Shtick Hustler

Well-known member
Joined
Oct 15, 2020
Posts
105
Likes
46
Why exactly do you need to access the HMA ?
What are you planning to do with it ?

I'm porting an indicator from NS and would like to offer both EMA and HMA smoothing.

Not sure if I'll release it or just keep it for my own use.
 

Spin

Well-known member
Joined
May 22, 2019
Posts
477
Likes
191
Well, I believe you might want to put that indicator's value into a 'Study Value' first:
Java:
 series.setDouble(index, Values.Indic, nameIndic);

and then calculate the (H)MA of that value, using the settings your user desires (put this inside the "Calculate" class):
Java:
        int HMAperiod = getSettings().getInteger(HMA_PERIOD);
        Enums.MAMethod HMAmethod = getSettings().getMAMethod(HMA_METHOD);
        int HMAshift = getSettings().getInteger(HMA_SHIFT);
        input = series.getDouble(index, Values.Indic);

and later on :
Java:
        int HMAhalfperiod = (int) HMAperiod/2;
        Double ma1 = series.ma(HMAmethod, index, HMAhalfperiod, input);
        if (ma1 == null) return;
        ma1 = ma1*2;
        Double ma2 = series.ma(HMAmethod, index, HMAperiod, input);
        if (ma2 == null) return;
        series.setDouble(index+HMAshift, Values.HMA, ma1 - ma2);
 

Shtick Hustler

Well-known member
Joined
Oct 15, 2020
Posts
105
Likes
46
Got it working, Muchos gracias 👏

Was able to break the code out into a custom utility class method.
So, looks like it would be easy enough for MW to add it to the DataSeries interface.
 
Last edited:

MotiveWave_Joe

Moderator
Staff member
Joined
Mar 26, 2019
Posts
223
Likes
67
Hi,

Thanks for the submission. I will pass it on to development for consideration.
 

Shtick Hustler

Well-known member
Joined
Oct 15, 2020
Posts
105
Likes
46
Hi,

Thanks for the submission. I will pass it on to development for consideration.

On checking against the MW HullMA.java code (in complete studies package) I noticed a missing calculation.

Here's the corrected code:

Java:
         int HMAhalfperiod = (int) HMAperiod/2;
         int sqp = (int)Math.sqrt(period);
        Double ma1 = series.ma(HMAmethod, index, HMAhalfperiod, input);
       
        if (ma1 == null) return;
        ma1 = ma1*2;
        Double ma2 = series.ma(HMAmethod, index, HMAperiod, input);
        if (ma2 == null) return;
        series.setDouble(index+HMAshift, Values.HMA_TMP, ma1 - ma2);
       
        Double value = null;
        value = series.ma(HMAMethod, index, sqp, "HMA_TMP");
        if (value == null) return -1 ;

        if (shift >= 0) series.setDouble(last+shift, Values.HMA, value);
           else series.setDouble(last, Values.HMA, value);

I also noticed in MW's HullMA.java file that calculations are done both in OnBarUpdate and CalculateValues.

Wondering if there's something about how hull is computed that it can’t be done accurately in one pass via Calculate?
 
Last edited:

Shtick Hustler

Well-known member
Joined
Oct 15, 2020
Posts
105
Likes
46
On checking against the MW HullMA.java code (in complete studies package) I noticed a missing calculation.

Here's the corrected code:

Java:
         int HMAhalfperiod = (int) HMAperiod/2;
         int sqp = (int)Math.sqrt(period);
        Double ma1 = series.ma(HMAmethod, index, HMAhalfperiod, input);
      
        if (ma1 == null) return;
        ma1 = ma1*2;
        Double ma2 = series.ma(HMAmethod, index, HMAperiod, input);
        if (ma2 == null) return;
        series.setDouble(index+HMAshift, Values.HMA_TMP, ma1 - ma2);
      
        Double value = null;
        value = series.ma(HMAMethod, index, sqp, "HMA_TMP");
        if (value == null) return -1 ;

        if (shift >= 0) series.setDouble(last+shift, Values.HMA, value);
           else series.setDouble(last, Values.HMA, value);

I also noticed in MW's HullMA.java file that calculations are done both in OnBarUpdate and CalculateValues.

Wondering if there's something about how hull is computed that it can’t be done accurately in one pass via Calculate?

Just discovered a problem with using temporary series, like "HMA_TMP" above.

If you wrap this code in a utility function, and then call it to get data for MORE THAN ONE hull moving average, the temp series will corrupt the calculation for one of the data sets (i.e. you need a 21-period and 83-period HMA).

A quick kludge is to make sure to use unique names for the temp series for each different HMA period you need, like "HMA21_TMP", "HMA83_TMP".
 
Top