forex software

Create and Test Forex Strategies

forex software

Skip to forum content

Forex Software

Create and Test Forex Strategies

You are not logged in. Please login or register.


Forex Software → Technical Indicators → New indicator: "HMA" : Hull Moving Average

Pages 1

You must login or register to post a reply

RSS topic feed

Posts: 7

Topic: New indicator: "HMA" : Hull Moving Average

The famous "Hull Moving Average" is now available in your favorite FSB...
smile

Download it from the repository here:

http://forexsb.com/repository/repositor … ng-average

Enjoy!

Sq

Re: New indicator: "HMA" : Hull Moving Average

Did you convert Krog's HMA or coded your own?

Re: New indicator: "HMA" : Hull Moving Average

Hi footon,


I didn't even know about Krog's HMA... roll
I couldn't find any in the Repository, so i decided to code my own based on MACD.cs

Following your remark, i searched in the forum and found this one:
http://forexsb.com/forum/post/5266/#p5266

I was curious to see how Krog coded the data deries using the MovingAverage() function.

I used MACD as the basis because MACD is already a sum (well, difference, to be precise) of 2 MAs.

But i encountered some "newbie FSB coder" issues when i tried to code HMA into a single combination of MovingAverage() calls like this:

            double[] adMA = MovingAverage((int)Math.Sqrt(period), shift, maMethod, 2*MovingAverage((int)(period/2), shift, maMethod, Price(price)) - MovingAverage(period, shift, maMethod, Price(price)) );

hehe... doesn't work like this!

So i cut this into 3 separate steps, just like MACD does, with a loop on each Bar and so on...
Not very nice, and probably somewhat heavier in both memory and cpu load.

Krog's HMA calculation code is quite interesting because it calculates HMA in 1 line without the need for loops, by using maMethod():

            double[] adMA = MovingAverage(2 * maMethod(Price, (int)(period / 2)) - maMethod(Price, period), (int)(Math.Sqrt(period)));

However, this code does not compile with me...
It says "maMethod is a variable but is used both as a method".
If Krog would step-in and explain how to use maMethod() like this, i would be happy!

I did not load the FSB source code yet, so i don't have the source code for the indcators classes and methods, that also explins why i am not able to properly use them...
I will load the source code and study all this.

Sq

Re: New indicator: "HMA" : Hull Moving Average

Squalou wrote:

Krog's HMA calculation code is quite interesting because it calculates HMA in 1 line without the need for loops, by using maMethod():

            double[] adMA = MovingAverage(2 * maMethod(Price, (int)(period / 2)) - maMethod(Price, period), (int)(Math.Sqrt(period)));

However, this code does not compile with me...
It says "maMethod is a variable but is used both as a method".
If Krog would step-in and explain how to use maMethod() like this, i would be happy!

You're sure about this?

I see 1 for loop and and 3 MovingAverage() functions:

int iSqrtN = (int)Math.Sqrt(iPeriod);
            int iHalfN = (int)iPeriod/2;

            adWmaFullN = MovingAverage (iPeriod, 0, maMethod, adPrices);
            adWmaHalfN = MovingAverage (iHalfN, 0, maMethod, adPrices);

             for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                 adDiff[iBar] = (2*adWmaHalfN[iBar]) - adWmaFullN[iBar];
            }
            adHMA = MovingAverage (iSqrtN, 0, maMethod, adDiff);

Stacking functions together - as a professional coder do you think it should work? The case being it is not working - is it a limitation of C# or more to do with how FSB is built?

Re: New indicator: "HMA" : Hull Moving Average

footon wrote:
Squalou wrote:

Krog's HMA calculation code is quite interesting because it calculates HMA in 1 line without the need for loops, by using maMethod():

            double[] adMA = MovingAverage(2 * maMethod(Price, (int)(period / 2)) - maMethod(Price, period), (int)(Math.Sqrt(period)));

However, this code does not compile with me...
It says "maMethod is a variable but is used both as a method".
If Krog would step-in and explain how to use maMethod() like this, i would be happy!

You're sure about this?

I see 1 for loop and and 3 MovingAverage() functions:

int iSqrtN = (int)Math.Sqrt(iPeriod);
            int iHalfN = (int)iPeriod/2;

            adWmaFullN = MovingAverage (iPeriod, 0, maMethod, adPrices);
            adWmaHalfN = MovingAverage (iHalfN, 0, maMethod, adPrices);

             for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                 adDiff[iBar] = (2*adWmaHalfN[iBar]) - adWmaFullN[iBar];
            }
            adHMA = MovingAverage (iSqrtN, 0, maMethod, adDiff);

Stacking functions together - as a professional coder do you think it should work? The case being it is not working - is it a limitation of C# or more to do with how FSB is built?

Well, this code is not the one that i pointed in my post;
Here it is again:
http://forexsb.com/forum/post/5266/#p5266
The HMA.cs that is posted there does not use the loop, but the single-line that i quoted.
It is not an FSB limitation, it's just that perhaps Krog has some modified version of the MaMethod Class, i cannot tell.

Again, i did not download the FSB source code yet, so i don't know how the MovingAverage() function works exactly, nor maMethod, so i am just guessing from what i read in the code.

MovingAverage() is apparently returning an array of values, and the Class it belongs to seems to have a overloaded "-" and "+" operators, as i understand it, which allow to "add" and "subtract" them directly on the same statement using the "+" and "-" signs, however the actual operations are performed by the  implementation of those "add and "subtract" operators overload, most probably as a loop anyway, as this operation applies to each individual entry of the data arrays.

A simple and clear "+" operator overloading example is given here, for whoever is interested:
http://msdn.microsoft.com/en-us/library … 71%29.aspx

In order to perform the single-line version of the HMA, there would need to have an overloaded "*" operator implementation in the Class to allow "multiplying" the array by an integer (or a double).

This is only coding techniques details anyway, nothing to worry about.
My version of the HMA works just fine.

Where did you get your version from (the one you are quoting here) ?

Sq

Re: New indicator: "HMA" : Hull Moving Average

This is funny! big_smile The code sample you quote as Krog's is actually mine. To be precise it is my first try at coding whatsoever! As you experienced it doesn't work. Krog was nice enough to take my abortive solution and turn it into a working indi. It's in this post: http://forexsb.com/forum/post/5273/#p5273

Re: New indicator: "HMA" : Hull Moving Average

lol lol lol

all right....... 
looks like i did not read too far down then......

Oh, well, at least it gave me a chance to go deeper into understanding the coding principles in FSB.
We learn new things everyday!

Posts: 7

Pages 1

You must login or register to post a reply

Forex Software → Technical Indicators → New indicator: "HMA" : Hull Moving Average

Similar topics in this forum