Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, Ayumi, ozgur), 650 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
HULL MA script help #410662
11/06/12 20:37
11/06/12 20:37
Joined: Nov 2012
Posts: 19
B
Boris Offline OP
Newbie
Boris  Offline OP
Newbie
B

Joined: Nov 2012
Posts: 19
Thank you to all the developers of Zorro
I am new to programming and I wanted to add an HMA script to the indicators.c section so I can use this MA.

I have entered the following code into indicators.c but it is not working and I am not sure whats wrong besides ceiling and floor functions not being indentified. I was wondering if someone could help me fix this HMA script or let me know whats missing:

// HMA PriceSeries( NumericSeries ), Period( NumericSimple );
var HMA(var* Data,int Period)
{
Vars:
var * WMA = series(*Data, Period);
var * halvedLength;
var * sqrRootLength;
var * Value1;
var * Value2;
var* Value3;


if ((ceiling(Period / 2) - (Period / 2)) <= 0.5) then
halvedLength = ceiling(Period / 2)
else
halvedLength = floor(Period / 2);

if ((ceiling(SquareRoot(Period)) - SquareRoot(Period)) <= 0.5) then
sqrRootLength = ceiling(SquareRoot(Period))
else
sqrRootLength = floor(SquareRoot(Period));

Value1 = 2 * series(WMA(*Data, halvedLength));
Value2 = series(WMA(*Data, Period));
Value3 = series(WMA((Value1 - Value2), sqrRootLength));

HMA = Value3;
}

Re: HULL MA script help [Re: Boris] #410663
11/06/12 20:51
11/06/12 20:51
Joined: Oct 2012
Posts: 22
G
Guiom Offline
Newbie
Guiom  Offline
Newbie
G

Joined: Oct 2012
Posts: 22
Hi Boris,
A couple of things that I think are wrong but I haven't tested them:
- your function doesn't return anything, the last line should be return Var3; instead of HMA = Value3;
- SquareRoot(Period) should be sqrt(Period)
- what's that first line in your function - Vars: Should that be a comment?

I am also learning so if I am not right please someone correct me.

Guiom

Last edited by Guiom; 11/06/12 20:52.
Re: HULL MA script help [Re: Guiom] #410664
11/06/12 21:02
11/06/12 21:02
Joined: Nov 2012
Posts: 19
B
Boris Offline OP
Newbie
Boris  Offline OP
Newbie
B

Joined: Nov 2012
Posts: 19
Made changes, currently looks like this:
// HMA PriceSeries( NumericSeries ), Period( NumericSimple );
var HMA(var* Data,int Period)
{
var * WMA = series(*Data, Period);
var * halvedLength;
var * sqrRootLength;
var * Value1;
var * Value2;
var* Value3;


if ((ceiling(Period / 2) - (Period / 2)) <= 0.5) then
halvedLength = ceiling(Period / 2)
else
halvedLength = floor(Period / 2);

if ((ceiling(sqrt(Period)) - sqrt(Period)) <= 0.5) then
sqrRootLength = ceiling(sqrt(Period))
else
sqrRootLength = floor(sqrt(Period));

Value1 = 2 * series(WMA(*Data, halvedLength));
Value2 = series(WMA(*Data, Period));
Value3 = series(WMA((Value1 - Value2), sqrRootLength));

return Value3;
}

For the ceiling and floor functions any ideas on whether I can code it using
int(period/2) and int((sqrt(period)) instead of halvedlength and sqrRootLength?

Re: HULL MA script help [Re: Boris] #410692
11/07/12 10:20
11/07/12 10:20
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Some remarks:

- do not enter code in indicators.c. Better enter it into your script. indicators.c is updated with any new Zorro version and your code will then be overwritten.

- When you have only positive values, (var)((int)x) is the same as floor(x) and (var)((int)(x+1)) is the same as ceil(x).

- Vars and series are wrong used in your code - you're defining a pointer where you need a var, and you're using a var where you need a series. Best check out the tutorial lessons 1 and 4, there are both explained.

Re: HULL MA script help [Re: jcl] #412411
11/27/12 00:13
11/27/12 00:13
Joined: Nov 2012
Posts: 19
B
Boris Offline OP
Newbie
Boris  Offline OP
Newbie
B

Joined: Nov 2012
Posts: 19
jcl

Do you think you will be add a HULL code to the 1.04 version of Zorro? I have gotten the work down to this:

// HMA PriceSeries( NumericSeries ), Period( NumericSimple );
var HMA(var* Data,int Period)
{
var * WMA = series(*Data, Period);
var halvedLength;
var sqrRootLength;
var * Value1;
var * Value2;
var * Value3;


if ((ceiling(Period / 2) - (Period / 2)) <= 0.5) then
halvedLength = ceiling(Period / 2)
else
halvedLength = floor(Period / 2);

if ((ceiling(sqrt(Period)) - sqrt(Period)) <= 0.5) then
sqrRootLength = ceiling(sqrt(Period))
else
sqrRootLength = floor(sqrt(Period));

Value1 = 2 * series(WMA(*Data, halvedLength));
Value2 = series(WMA(*Data, Period));
Value3 = series(WMA((Value1 - Value2), sqrRootLength));

return Value3;
}

and I also tried this for an actual strategy but neither worked:
function run()
{
var *ClosePrice = series(priceClose());
var *WMA8 = series(WMA(ClosePrice,8));
var *WMA16 = series(WMA(ClosePrice,16));
var *WMA18 = series(WMA(ClosePrice,18));
var *WMA36 = series(WMA(ClosePrice,36));
var *HMA16= series(WMA(WMA(WMA8() - WMA16()),4));
var *HMA36 = series(WMA(WMA(ClosePrice,18) - WMA(ClosePrice,36),6));


if(crossUnder(HMA16,HMA36))
enterShort();
if(crossOver(HMA16,HMA36))
enterLong();
}

Im sorry im a total beginner, my friend who coded left so I have been trying to teach myself. This is the only thing I am trying to figure out all else I did through trial and error. I would really appreciate your input.

-Boris

Re: HULL MA script help [Re: Boris] #412422
11/27/12 09:51
11/27/12 09:51
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
I first need to understand what you want to do at all. What is a HULL code? Is this a special indicator?

Re: HULL MA script help [Re: jcl] #412449
11/27/12 15:13
11/27/12 15:13
Joined: Nov 2012
Posts: 19
B
Boris Offline OP
Newbie
Boris  Offline OP
Newbie
B

Joined: Nov 2012
Posts: 19
Thank you very much for answering so promptly

Yes its a modified moving average with minimal lag created by Allen Hull. Here is a website that describes it more detail incuding the formula for it:

http://www.istockanalyst.com/article/viewarticle/articleid/3019836

Its the only moving average that tracks prices well enough to be profitable with just crossovers without any further filtering. All you need is a stop.

The easiest formula I found is from the website, with n being the number of periods:

HMA(n) = WMA(2*WMA(n/2) – WMA(n)),sqrt(n))
with n/2 and sqrt(n) being rounded to the nearest whole number

The easiest way to program an HMA crossover program if there is no compiled HMA indicator for the predetermined periods(36 and 18) to me is this:

function run()
{
var *ClosePrice = series(priceClose());
var *WMA8 = series(WMA(ClosePrice,8));
var *WMA16 = series(WMA(ClosePrice,16));
var *WMA18 = series(WMA(ClosePrice,18));
var *WMA36 = series(WMA(ClosePrice,36));
var *HMA16= series(WMA(2*WMA8() - WMA16(),4));
var *HMA36 = series(WMA(2*WMA18() - WMA36(),6));


if(crossUnder(HMA16,HMA36))
enterShort();
if(crossOver(HMA16,HMA36))
enterLong();
}

The problem is these expressions: series(WMA(2*WMA8() - WMA16(),4));
Zorro doesn't want to put expression (2*WMA8()-WMA16() as the series veriable for the function WMA. I tried breaking it up several different ways but no success.

For an indicator I would assume it would look something like this:
HMA(Period) = WMA(2*WMA(int(Period/2)) – WMA(Period)),int(sqrt(Period))) but again the syntax is not acceptable

Same with this variation:
Value1 = 2 * series(WMA(*Data, int(Period));
Value2 = series(WMA(*Data, Period));
Value3 = series(WMA((Value1 - Value2), int(sqrt(Period));

return Value3;
}

The reason I wanted an HMA in the indicators is because I often use it in other functions like MACD. I really think its a worthwhile indicator and I think many others would find it useful when they play around with it. I would greatly appreciate any advice on getting my simple crossover program to work and if its possible getting an HMA indicator in Zorro so its as simple to use as a WMA for people like me. Thanks again.

Re: HULL MA script help [Re: Boris] #412467
11/27/12 17:57
11/27/12 17:57
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Your HMA in lite-C would look like this:

Code:
var HMA(var* data,int n)
{
  return WMA(series(2*WMA(data,0.5*n+0.5)-WMA(data,n)),sqrt(n)+0.5);
}



The "+0.5" is for rounding to the nearest integer. I don't think that this indicator can come close to real low-lag indicators such as the lowpass filter from the tutorial, but it can indeed be better than a straight WMA in some cases. I'll add it to the indicator collection.

Re: HULL MA script help [Re: jcl] #412540
11/28/12 19:46
11/28/12 19:46
Joined: Nov 2012
Posts: 19
B
Boris Offline OP
Newbie
Boris  Offline OP
Newbie
B

Joined: Nov 2012
Posts: 19
Thanks for your help. I plugged in the formula into Zorro like this:

function run()
{
var *ClosePrice = series(priceClose());
var *HMA17 = WMA(series(2*WMA(ClosePrice,0.5*17+0.5)-WMA(ClosePrice,17)),sqrt(17)+0.5);
var *HMA35 = WMA(series(2*WMA(ClosePrice,0.5*35+0.5)-WMA(ClosePrice,35)),sqrt(35)+0.5);



if(crossUnder(HMA17,HMA35))
enterShort();
if(crossOver(HMA17,HMA35))
enterLong();
}

But I am getting syntax error CONV:DOUBLE::POINTER

Two other questions:
Dont you need int(sqrt(n) + .5) to round

Besides adding your code into my indicators.c id there anything else needed to be done since Zorro still wont recognize it as an indicator?

Thanks so much and I apologize for so many questions
As for following trends, yes there are much tighter indicators but ofcourse you also get more whipsaws but I will def look into them during optimization.

Re: HULL MA script help [Re: Boris] #412563
11/29/12 08:39
11/29/12 08:39
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The syntax error tells you that you attempted to use vars (the return values from the WMA function) where you need series (for your HMA17 and HMA35 series). Vars and series are two different things. I see from your posted codes that you have not yet 100% understood what they are used for and when you need which. Please look again in lesson 4 of the tutorial - there it is explained.

The correct code would have been, when you include my code above for the HMA:

Code:
function run() 
{
var *ClosePrice = series(priceClose());
var *HMA17 = series(HMA(ClosePrice,17));
var *HMA35 = series(HMA(ClosePrice,35));

if(crossUnder(HMA17,HMA35))
  enterShort();
if(crossOver(HMA17,HMA35)) 
  enterLong();
}



- You don't need int(sqrt(n) + .5) to round because the WMA function expects an int for the time period, so the int conversion happens automatically when calling that function. C automatically converts basic variables. It does not automatically convert complex objects, though, such as a var to a series.

Page 1 of 2 1 2

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1