6 registered members (AndrewAMD, Ayumi, degenerate_762, 7th_zorro, VoroneTZ, HoopyDerFrood),
1,268
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Questions regarding static int, NumYears
#436482
01/27/14 20:24
01/27/14 20:24
|
Joined: Jan 2013
Posts: 68
ibra
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2013
Posts: 68
|
Hi, The code I got questions about is in the following picture:
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: dusktrader]
#436518
01/28/14 10:15
01/28/14 10:15
|
Joined: Jan 2013
Posts: 68
ibra
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2013
Posts: 68
|
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
dusktrader
User
|
User
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:
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
ibra
OP
Junior Member
|
OP
Junior Member
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:
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
dusktrader
User
|
User
Joined: Jul 2013
Posts: 522
|
I believe the code:
crossed -= sign(crossed);
is the same as:
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: jcl]
#436573
01/29/14 07:47
01/29/14 07:47
|
Joined: Jan 2013
Posts: 68
ibra
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2013
Posts: 68
|
Hi,
What would I do without you guys?
Thanks!
Last edited by ibra; 01/29/14 07:47.
|
|
|
|