1 registered members (opm),
778
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
Dalla
OP
Senior Member
|
OP
Senior Member
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
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: jcl]
#469162
11/06/17 20:32
11/06/17 20:32
|
Joined: Feb 2017
Posts: 369
Dalla
OP
Senior Member
|
OP
Senior Member
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.htmThis is what it says
// 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: jcl]
#469175
11/07/17 09:48
11/07/17 09:48
|
Joined: Feb 2017
Posts: 369
Dalla
OP
Senior Member
|
OP
Senior Member
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
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]
#469187
11/07/17 14:58
11/07/17 14:58
|
Joined: Jul 2000
Posts: 27,977 Frankfurt
jcl
Chief Engineer
|
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:
...
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.
|
|
|
|