Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 533 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Code help: Range of 1st hours trading. #432412
11/05/13 23:51
11/05/13 23:51
Joined: Apr 2013
Posts: 107
UK
G
Geek Offline OP
Member
Geek  Offline OP
Member
G

Joined: Apr 2013
Posts: 107
UK
I'm trying to code a simple trading system:


Quote:
Find the high low range of first hours trading:

Buy on the breakout of the lowest low or the highest high of that first hour.

Profit target is the range between the high and low of first hour.

Stop set in opposite of trade direction equal to first hours trading range.

Exit at end of day, if no stops or limits get hit.

Don’t trade if range is higher than 40 points:


Quote:

function run()
{

BarPeriod = 5;

LookBack = 30;

vars Price = series(price());

if(hour(UTC) >= 16.30) // Exit trade at end of the day if stop or target have not been met.
exitLong();


Stop = 40*PIP; // - Change this to the amount of the range in first hours trading.

TakeProfit = 40*PIP: // - Change this to the amount of the range in first hours trading.


Dont trade if range is > 40 PIP; // Set dont trade if the rage in higher than 40*PIP;


if (*Price > HH(30) && NumOpenLong <1 && hour(UTC) >9 && hour(UTC) < 16.30) // Buy on breakout outside of the first hours range.
enterLong();

else if (*Price > LL(30) && NumOpenShort <1 && hour(UTC) > 9 && hour(UTC) < 16.30) // Sell on breakout outside of the first hours range.

enterShort();


}






But am finding it difficult to get right code for finding out the high low range of first hours trading as the system uses this for stop and profit targets and my coding skills are not that great.

So looking to find the range of the first hours trading of hour(UTC) 8 to 9..

How so you do this?

???

Profit target is set from the the range (PIPS between the high and low of first hour trading)

TakeProfit = ???


Stop to be set in opposite of trade direction equal to first hours trading range..

Stop = ???


Also don’t trade if first hour range is higher than 40 points:

???


Would appreciate any help on the above as i'm stuck.

Thanks.








Last edited by Geek; 11/06/13 00:09.
Re: Code help: Range of 1st hours trading. [Re: Geek] #432669
11/11/13 09:21
11/11/13 09:21
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
For the high-low range of the first hour of a trading day, you can use the dayHigh and dayLow functions. In that case, set the EndMarket variable to 1030 so that the "market day" ends at 10:30, one hour after its begin.

http://manual.zorro-trader.com/day.htm

Re: Code help: Range of 1st hours trading. [Re: jcl] #432712
11/12/13 22:14
11/12/13 22:14
Joined: Apr 2013
Posts: 107
UK
G
Geek Offline OP
Member
Geek  Offline OP
Member
G

Joined: Apr 2013
Posts: 107
UK
Originally Posted By: jcl
For the high-low range of the first hour of a trading day, you can use the dayHigh and dayLow functions. In that case, set the EndMarket variable to 1030 so that the "market day" ends at 10:30, one hour after its begin.

http://manual.zorro-trader.com/day.htm


Thanks JCL.

I think the below code works for the Stop and TakeProfit, the only thing I am having trouble with is asking Zorro not to trade when the High and Low range exceeds 40*PIP; I'm getting an "illegal indirection" error?

Quote:


function run()
{

BarPeriod = 60;
LookBack = 100;
set(TICKS);
set(PEEK);

StartMarket = 800;
EndMarket = 900;

vars Price = series(price());

if(hour(UTC) >= 16.30)
exitLong();

if(hour(UTC) >= 16.30)
exitShort();

var DH = dayHigh (UTC,0);
var DL = dayLow (UTC,0);


asset("UK100");
Stop = DH-DL;
TakeProfit = DH-DL;

if (*DH-*DL > 40*PIP);
Lots = 0;


if (*Price > DH && NumOpenLong <1 && hour(UTC) > 9 && hour(UTC) < 16.30)
enterLong();

else if (*Price < DL && NumOpenShort <1 && hour(UTC) > 9 && hour(UTC) < 16.30)

enterShort();

Re: Code help: Range of 1st hours trading. [Re: Geek] #432732
11/13/13 15:00
11/13/13 15:00
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
A little puzzle to the users - who can find all mistakes in this code? Solution tomorrow.

Re: Code help: Range of 1st hours trading. [Re: jcl] #432748
11/13/13 18:18
11/13/13 18:18
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
The illegal indirections are the *DH and *DL. What are you trying to accomplish?

After that, there's an extra ";" leading to no statement for the if.

Then, you haven't ended the function. laugh

HTH.

Re: Code help: Range of 1st hours trading. [Re: DdlV] #432752
11/13/13 20:14
11/13/13 20:14
Joined: Apr 2013
Posts: 107
UK
G
Geek Offline OP
Member
Geek  Offline OP
Member
G

Joined: Apr 2013
Posts: 107
UK
Originally Posted By: DdlV
The illegal indirections are the *DH and *DL. What are you trying to accomplish?


HTH.



Thanks,

I'm trying to accomplish - if the range is higher than 40 Pips then do not trade.


Updated code below which runs but no trades are entered?

Quote:

function run()
{

BarPeriod = 60;
LookBack = 100;
set(TICKS);
set(PEEK);

StartMarket = 800;
EndMarket = 900;

vars Price = series(price());

if(hour(UTC) >= 16.30)
exitLong();

if(hour(UTC) >= 16.30)
exitShort();

var DH = dayHigh (UTC,0);
var DL = dayLow (UTC,0);

var Range = DH-DL;

asset("UK100");

Stop = Range;

TakeProfit = Range;

if (Range > 40*PIP)
Lots = 0;


if (*Price > DH && NumOpenLong <1 && hour(UTC) > 9 && hour(UTC) < 16.30)
enterLong();

else if (*Price < DL && NumOpenShort <1 && hour(UTC) > 9 && hour(UTC) < 16.30)

enterShort();

}

Re: Code help: Range of 1st hours trading. [Re: Geek] #432763
11/14/13 11:59
11/14/13 11:59
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Best next step, then, is to add printf's so you can see what various values are and what the code is consequently doing.

HTH.

Re: Code help: Range of 1st hours trading. [Re: DdlV] #432767
11/14/13 15:22
11/14/13 15:22
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
Some other problems that I noticed:

set(PEEK) - can render your results useless. NEVER set this flag unless you have a reason.

hour(UTC) - makes no sense, you probably mean lhour()?

16.30 - you have 60 minutes bars and hour() returns an integer anyway, so you can't compare with 16.30.


Re: Code help: Range of 1st hours trading. [Re: jcl] #432770
11/14/13 17:24
11/14/13 17:24
Joined: Apr 2013
Posts: 107
UK
G
Geek Offline OP
Member
Geek  Offline OP
Member
G

Joined: Apr 2013
Posts: 107
UK
Thanks guys, appreciate you pointing these things out!

When I do not set the PEEK flag, i get "error 045: Negative price offset at bar 1" ?

I know this is due to the following: It goes away when Peek is set.
Quote:

var DH = dayHigh (UTC,0);
var DL = dayLow (UTC,0);


I have set StartMarket and EndMarket - from 8am-9am.. As that's the first hours trading that this script is based on that the dayHigh and dayLow should work from. i do not want to set dayLow (UTC,1); for instance as this will based on yesterdays low..?

Anyway, I made some more changes to the code, i'd be interested to see how incorrect this is. I know it will be, but all this help me and any other learners to get to grips with the code.

Edit: i just noticed another error, I'm not sure what this error means exactly?

"Error in 'line 26:
Syntax error: Can't go to FALSEGOTO:DOUBLE::.
< if (Close) >

Thanks for your patience and for pointing out any inaccuracies.

Quote:

function run()
{

BarPeriod = 15;
LookBack = 1000;
set(TICKS);

StartDate = 2010;

vars Price = series(price());

StartMarket = 800;
EndMarket = 900;

var DH = dayHigh (UTC,0);
var DL = dayLow (UTC,0);

var Range = DH-DL;
var Close = timeOffset(UTC,0,16,30);
var Open = timeOffset(UTC,0,8,00);
var StartTrade = timeOffset(UTC,0,9,00);
var Now = timeOffset(UTC,0,0,00);

if (Close)
exitLong();

if (Close)
exitShort();

asset("UK100");

Stop = Range;

TakeProfit = Range;

if (Range > 40*PIP)
Lots = 0;

if (*Price > DH && NumOpenLong <1 && Now > StartTrade && Now < Close)
enterLong();

else if (*Price < DL && NumOpenShort <1 && Now > StartTrade && Now < Close)
enterShort();

}

Last edited by Geek; 11/14/13 19:28.
Re: Code help: Range of 1st hours trading. [Re: Geek] #432780
11/15/13 11:38
11/15/13 11:38
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
PEEK means that your system is peeking into the future. This in turn means that you will need a time machine for trading it. Therefore setting the PEEK flag is a bad idea if you don't have such a machine at hand.

Better find out the reason of the error 45, and fix it. In your case it's calling dayHigh/Low before the market day is over. You cannot know the high of a day already in the morning. Thus do not call those functions until the EndMarket hour is over.

The syntax error is a wrong condition in the if clause. "If" checks if something is true or false. A var has a floating point value and cannot be true or false. For doing something at a certain time, use the hour or lhour functions.

Page 1 of 3 1 2 3

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1