Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
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
6 registered members (AndrewAMD, Ayumi, degenerate_762, 7th_zorro, VoroneTZ, HoopyDerFrood), 1,268 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Questions regarding static int, NumYears #436482
01/27/14 20:24
01/27/14 20:24
Joined: Jan 2013
Posts: 68
I
ibra Offline OP
Junior Member
ibra  Offline OP
Junior Member
I

Joined: Jan 2013
Posts: 68
Hi,

The code I got questions about is in the following picture:
Code:
function run()
{
	BarPeriod = 240;
	StartDate = 2003;
	EndDate = 2012;
	set(PARAMETERS);
	
	var *Price = series(price());
	var *LP5 = series (LowPass(Price,5));
	var *LP10 = series(LowPass(Price, optimize(10,6,20)));
	var *RSI10 = series(RSI(Price,10));
	Stop = optimize(5,1,10) *ATR(30);
	
	static int crossed = 0;
	
	if(crossOver(LP5,LP10))
		crossed = 3;
		
	else if (crossUnder(LP5,LP10))
		crossed = -3;
	
   if(crossed > 0 && crossOver(RSI10, 50))
	{
		enterLong();
		crossed = 0;
	}

	else if(crossed < 0 && crossUnder(RSI10, 50))
	{
		enterShort();
		crossed = 0;
		
	}
	else crossed -= sign(crossed);
	
	plot ("RSI", RSI10[0], NEW, BLUE);

}



First off, I didn't create this strategy. At Babypips, a guy called LiftOff did the first version of the strategy, and then JCL helped him with the version I linked above (correct me if I'm wrong).

To the questions:

Why do you use NumYears and StartDate?
The manual says "Number of years of the simulation if no StartDate or EndDate is given (default: 6 years)."

But in the code, there are both?

And if anyone please could explain the use of static int? And why we give crossed the value 3/-3? Why not 1 or 2 instead?

Thanks in advance!

Ibra

Last edited by ibra; 01/28/14 11:09.
Re: Questions regarding static int, NumYears [Re: ibra] #436495
01/28/14 00:56
01/28/14 00:56
Joined: Jul 2013
Posts: 522
D
dusktrader Offline
User
dusktrader  Offline
User
D

Joined: Jul 2013
Posts: 522
Hi ibra,
try pasting code inside of the [ code ] and [ /code ] markers (without the space after the square brackets) -- that will maintain the format better.

liftoff is on this forum too, I think he recently joined btw.

I think it is optional to use starting and ending date parameters. If you specify them, then Zorro tries to accommodate. I prefer to use StartDate and EndDate, and that way I can be very specific. If you use just StartDate and NumYears, then Zorro will start the simulation at the StartDate and try to go NumYears into the future. If you leave a parameter off, it will use a default value.

Regarding static int... that is a type of global variable that is remembered between iterations of the script, unlike other variables which are normally initialized each time the run() function is executed.

Re: Questions regarding static int, NumYears [Re: dusktrader] #436518
01/28/14 10:15
01/28/14 10:15
Joined: Jan 2013
Posts: 68
I
ibra Offline OP
Junior Member
ibra  Offline OP
Junior Member
I

Joined: Jan 2013
Posts: 68
Originally Posted By: dusktrader

If you use just StartDate and NumYears, then Zorro will start the simulation at the StartDate and try to go NumYears into the future. If you leave a parameter off, it will use a default value.


Hi Dusk!

Thanks for replying. Could you please explicate what you mean with into the future stuff?

Thanks

Ibra

Re: Questions regarding static int, NumYears [Re: ibra] #436521
01/28/14 10:51
01/28/14 10:51
Joined: Jul 2013
Posts: 522
D
dusktrader Offline
User
dusktrader  Offline
User
D

Joined: Jul 2013
Posts: 522
Ahhh... bad choice of words, sorry. I meant... it will start the simulation at the StartDate and try to go NumYears further into your dataset history. I said "try" because if that history is not available, then it obviously could not achieve what you are asking.

For example if you specified StartDate 2013 and NumYears 7, then I think you'd only get about 1 year of test data.

I prefer to be very specific, based on the history .bar files I have downloaded, like this:
Code:
StartDate = 20080101;
EndDate = 20140122;
GapDays = 3; //alert if more than 3 days gap in data


(GapDays is a new feature that I also like to use.)

Re: Questions regarding static int, NumYears [Re: dusktrader] #436524
01/28/14 11:22
01/28/14 11:22
Joined: Jan 2013
Posts: 68
I
ibra Offline OP
Junior Member
ibra  Offline OP
Junior Member
I

Joined: Jan 2013
Posts: 68
Hi again,

You're the man! Thanks!

But I'm still a little confused about the static int part... especially the last piece of code:
Code:
else crossed -= sign(crossed);



I'm curious where the number 3 respective -3 comes from.
My "theory" about this, is that it is beeing used to control the "age" of the crossover/under signal. Can someone confirm this? And tell me what the number 3 does?

Re: Questions regarding static int, NumYears [Re: ibra] #436532
01/28/14 15:22
01/28/14 15:22
Joined: Jul 2013
Posts: 522
D
dusktrader Offline
User
dusktrader  Offline
User
D

Joined: Jul 2013
Posts: 522
I believe the code:
Code:
crossed -= sign(crossed);


is the same as:
Code:
crossed = crossed - sign(crossed);


and the function sign() returns -1, 0 or 1 (per manual)

does that help?
For what its worth, I'm also studying this strategy at the moment (HTC).

Re: Questions regarding static int, NumYears [Re: dusktrader] #436533
01/28/14 15:40
01/28/14 15:40
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The line adds or subtracts 1 from the "crossed" variable, dependent on its sign - and yes, the initial number 3 indeed controls the age of the crossover.

This method is equivalent to the "Sum(signals...)" method desribed in workshop 4. The workshop 4 method is better, though, and probably easier to understand.

Re: Questions regarding static int, NumYears [Re: jcl] #436573
01/29/14 07:47
01/29/14 07:47
Joined: Jan 2013
Posts: 68
I
ibra Offline OP
Junior Member
ibra  Offline OP
Junior Member
I

Joined: Jan 2013
Posts: 68
Hi,

What would I do without you guys?

Thanks!


Last edited by ibra; 01/29/14 07:47.

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