Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (opm), 778 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
How to limit strategy to only trade during market hours? #469052
11/04/17 12:44
11/04/17 12:44
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
When building a system for e.g. DAX, I want to limit the strategy to only trade during market hours. Reading about AssetMarket in the manual it says:

"Time zone of the currently selected asset, used for setting AssetFrame to a TimeFrame that skips all bars outside market hours in local time, but follows the BarPeriod inside market hours. The market hours are given by StartMarket and EndMarket."

Great, this looks just like what I want: Skip bars outside market hours.

So I add to the top of my strategy

Code:
set(LOGFILE+PARAMETERS);
	StartDate = 2004;
	EndDate = 2017;
	LookBack = 600;
	BarPeriod = 240;
	AssetMarket = UTC;
	StartMarket = 0800;
	EndMarket = 1645;
	
	vars close = series(priceClose());
	vars open = series(priceOpen());
	vars high = series(priceHigh());
	vars low = series(priceLow());
	vars price = series(price());

        ....



But still, after backtesting and looking at the trade log, I can see entries, stop losses and time stops being executed outside market hours.

So how can I limit the strategy to only execute entries and stops inside market hours?

Re: How to limit strategy to only trade during market hours? [Re: Dalla] #469131
11/06/17 09:12
11/06/17 09:12
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
I do not see where your script skips bars or skips trading outside market hours. You can find examples of skipping bars in the manual. The simplest way is just checking the time, f.i. if(between(ltod(0),930,1530)) enterLong();.

Re: How to limit strategy to only trade during market hours? [Re: jcl] #469143
11/06/17 10:43
11/06/17 10:43
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
The manual suggests that setting AssetMarket together with StartMarket and EndMarket will handle skipping bars for me.

Also, if(between(ltod(0),930,1530)) enterLong();. will help not with Stop and Lifetime I guess?

Re: How to limit strategy to only trade during market hours? [Re: Dalla] #469149
11/06/17 14:45
11/06/17 14:45
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
TimeFrame is used for skipping bars. My one line example did indeed not do Stop and lifetime - I know you as a seasoned script writer and did not assume that you needed help with that wink.

Re: How to limit strategy to only trade during market hours? [Re: jcl] #469162
11/06/17 20:32
11/06/17 20:32
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
Yeah yeah ;-)
Stop and LifeTime aside, there is clearly something here that I fail to understand.

Repeating myself; When reading about AssetMarket in the manual, it states:

"Time zone of the currently selected asset, used for setting AssetFrame to a TimeFrame that skips all bars outside market hours in local time, but follows the BarPeriod inside market hours. The market hours are given by StartMarket and EndMarket."

Like you said, there is an example of how to skip bars in the manual. At least I can find one here: http://www.zorro-trader.com/manual/en/barperiod.htm

This is what it says
Code:
// skip bars outside market hours (equivalent to AssetMarket) //////
// equivalent to AssetZone
static int SkippedBars = 0;
if(!market(ET,0)) {
   TimeFrame = 0;
   SkippedBars--; // count negative number of bars outside market hours
} else if(TimeFrame == 0) {
   TimeFrame = SkippedBars;
   SkippedBars = 0;
} else
  TimeFrame = 1;
vars PriceInMarketHours = series(price());



I don't understand how what this snippet and AssetMarket have in common?

Re: How to limit strategy to only trade during market hours? [Re: Dalla] #469172
11/07/17 09:18
11/07/17 09:18
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
You must set TimeFrame to 0 for skipping bars outside trading hours. Then, at trading start, set TimeFrame to the negative number of skipped bars. AssetFrame can be used to do that automatically. There are examples in the manual how to set TimeFrame from AssetFrame.

http://manual.zorro-project.com/assetzone.htm

Re: How to limit strategy to only trade during market hours? [Re: jcl] #469175
11/07/17 09:48
11/07/17 09:48
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
OK. One more question on this.

Can bar skipping not be used together with for example the ATR indicator?

Manual says "The function internally creates series when TimeFrame is > 1, and must then be called in a fixed order in the script."

If I use the snippet above together with something simple like
Code:
if(  price[0] > ATR(20 ))	{
    enterLong();
}



my script stops execution with a message along these lines
Bar 1212: 4 - Bar 1213: 1

I guess ATR does not like skipping bars?

Re: How to limit strategy to only trade during market hours? [Re: Dalla] #469182
11/07/17 12:41
11/07/17 12:41
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
No, the error message looks like inconsistent series. This has nothing to do with skipping bars, but could mean the ATR call itself is somewhere skipped.

Re: How to limit strategy to only trade during market hours? [Re: jcl] #469184
11/07/17 13:11
11/07/17 13:11
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
I don't think so. This simple reproducer also gives that same error message:

Code:
function run()
{
	set(LOGFILE+PARAMETERS);
	StartDate = 2016;
	EndDate = 2017;
	LookBack =600;
	BarPeriod = 60;
	AssetMarket = UTC;
	StartMarket = 0800;
	EndMarket = 1800;
	
	static int SkippedBars = 0;
	if(!market(UTC,0)) {
		TimeFrame = 0;
		SkippedBars--; // count negative number of bars outside market hours
	} else if(TimeFrame == 0) {
		TimeFrame = SkippedBars;
		SkippedBars = 0;
	} else
		TimeFrame = 1;

	vars prices = series(priceClose());
	LifeTime = 10;

	if (prices[0] > ATR(200))
		enterLong();

}


Re: How to limit strategy to only trade during market hours? [Re: Dalla] #469187
11/07/17 14:58
11/07/17 14:58
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
That's inconsistent series, but I must admit that it is a bit tricky.

ATR internally generates a series only when TimeFrame is different to 1. So, we have an inconsistent number of series, but the problem is indeed related to skipping bars.

This should fix it:

Code:
...
vars O = series(priceOpen()),
	H = series(priceHigh()),
	L = series(priceLow()),
	prices = series(priceClose());
if(prices[0] > ATR(O,H,L,prices,200))
	enterLong();
}



I have to mention this in the manual because a normal user has indeed no chance to see the reason of the problem.

Re: How to limit strategy to only trade during market hours? [Re: jcl] #469191
11/07/17 19:18
11/07/17 19:18
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
Thanks, that fixed the problem!

Re: How to limit strategy to only trade during market hours? [Re: Dalla] #474042
09/12/18 07:14
09/12/18 07:14
Joined: Apr 2017
Posts: 106
3
3dgamelight Offline
Member
3dgamelight  Offline
Member
3

Joined: Apr 2017
Posts: 106
What is the recommended way to set market hours when the market reopen on the same day?

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