Market hours for Globex

Posted By: Zheka

Market hours for Globex - 12/08/17 17:37

What's the correct way to set-up in Zorro a Globex session - which starts at 1800 ET and ends at 1700 ET.?
Quote:
BarPeriod=20;
AssetMarket=ET;
StartMarket=1800;
EndMarket=1700;
does not work - market(ET,0) is always false.

Would be great if Zorro could internally recognize and correctly handle situations when StartMarket>EndMarket.

Quote:
BarPeriod=20;
FrameOffset=18*3;

AssetMarket=ET;
TimeFrame=AssetFrame;
does not work either.. regardless of FrameOffset market(ET,0) equals true for a period from 9:20 to 15:40..

Please help.
Posted By: jcl

Re: Market hours for Globex - 12/09/17 08:47

The start time must be earlier than the end time. You could work around the problem by selecting a different time zone where this is the case. Alternatively, set TimeFrame directly for skipping the hour at 17:00.
Posted By: Zheka

Re: Market hours for Globex - 01/09/18 20:43

JCL,
to work around the EndM>StartM limitation, I have played with StartMarket/EndMarket as follows:
Quote:
StartMarket=000;
EndMarket=1701;

if (time>=1716) { StartMarket= 1717; EndMarket=2359;}

AssetMarket=ET;
Weekend=1+8;

TimeFrame=AssetFrame;
It works and correctly handles 1700 ET close -> 1715 ET start transition. But then the first bar of the new day - 015 ET- is skipped for some reason.

Quote:
[490: Wed 16-05-11 03:55] (123.89)n AssetFrame=1 ET Time=2355, O= 123.93600, C= 123.89200

[491: Wed 16-05-11 04:15] (123.89)
[492: Wed 16-05-11 04:35] (123.86)n AssetFrame=-1 ET Time=35, O= 123.89200, C= 123.86300

[493: Wed 16-05-11 04:55] (123.82)n AssetFrame=1 ET Time=55, O= 123.86300, C= 123.81700


Interestingly, if I only leave the session as 000-1701, the first frame/bar is indeed 015, as expected.
Posted By: Zheka

Re: Market hours for Globex - 01/09/18 23:06

I added one debugging line to the above code:

Quote:
TimeFrame=AssetFrame;

if (time==016) printf("#TimeFrame: %i, ET Time: %i, StartMarket: %i, EndMarket: %i",TimeFrame,time,StartMarket,EndMarket);

Despite time being in between Start- and EndMarket, AssetFrame somehow is =0.
Quote:
[491: Wed 16-05-11 03:56] (123.88)n AssetFrame=1 ET Time=2356, O= 123.95100, C= 123.87800

[492: Wed 16-05-11 04:16] (123.89)TimeFrame: 0, ET Time: 16, StartMarket: 0, EndMarket: 1701

[493: Wed 16-05-11 04:36] (123.86)n AssetFrame=-1 ET Time=36, O= 123.87800, C= 123.85700

This looks incorrect.
Posted By: jcl

Re: Market hours for Globex - 01/10/18 11:14

It is not clear what you want to do. Do you want to skip bars outside market hours, or do you want not to trade outside market hours?

If you want to skip bars, then do not change StartMarket and EndMarket, or else you will of course get strange results when you do that in the middle of a frame. If you just want not to trade, then do not set TimeFrame, since that skips bars.

All about skipping bars and using TimeFrame can be read here: http://manual.zorro-project.com/barperiod.htm. You can skip any time period on any market condition that you want when you understood the mechanism.
Posted By: Zheka

Re: Market hours for Globex - 01/10/18 16:27

JCL,
I want to correctly construct bars and higher "timeframe" bars - this feeds all system calculations.

For a portfolio of systems with different bar periods, I need to set the BarPeriod to the "largest common divisor" of all systems and simulate the needed ones with timeframes. All my systems also need a secondary time frame (daily) in their calculations.

Now, for FX (IB), there are M1 bars from 1715 to 1700 ET, but I only want to base my calculations on data from 1716 to 1645(-58) ET.

After 2.5 days of trying, I am still unable to achieve what I want:

1) TF>1 just counts *TF number of bars*.
But because there are no M1 bars from 1700-1715 and because there is a bug with Weekend>2+ (it still creates a weekend bar) - all Frames get continuously shifted and are incorrect.

Also, there is still a bug with StartWeek: with Weekend=2-3, setting StartWeek<2200 does not work - week starts from 2200+ in any case

2) BarPeriod=5 - frameSync(4) almost works.
But there is an unneeded frame ending 1716 which covers 1656-1716. Skipping bars to avoid is not helping - frameSync somehow behaves unpredictably..
Quote:
[855: Wed 16-05-11 20:56] (123.88)n FrameOffset: 3, SkipBars: 0, AssetFrame=-3 ET Time=1656, O= 123.89500, C= 123.87600
[856: Wed 16-05-11 21:01] (123.90) Skiping.. Time= 1701, skipBars= -1
[857: Wed 16-05-11 21:16] (123.87) Skiping.. Time= 1716, skipBars= -2
[858: Wed 16-05-11 21:21] (123.93) Skiping.. Time= 1721, skipBars= -3
[859: Wed 16-05-11 21:26] (123.88) Skiping.. Time= 1726, skipBars= -4
[860: Wed 16-05-11 21:31] (123.92) Skiping.. Time= 1731, skipBars= -5

[861: Wed 16-05-11 21:36] (123.93)n FrameOffset: 3, SkipBars: -5, AssetFrame=-3 ET Time=1736, O= 123.87400, C= 123.93200

[862: Wed 16-05-11 21:41] (123.90)n FrameOffset: 3, SkipBars: 0, AssetFrame=-5 ET Time=1741, O= 123.95000, C= 123.90500- ?? WHY?

[863: Wed 16-05-11 21:46] (123.91)
[864: Wed 16-05-11 21:51] (123.91)
[865: Wed 16-05-11 21:56] (123.91)n FrameOffset: 3, SkipBars: 0, AssetFrame=-3 ET Time=1756, O= 123.93200, C= 123.91200


3) AssetFrame requires setting BarPeriod=desired TF, but can be suitable.
But AssetFrame doesnt work as expected. Start/EndMarket are just variables and changing them is ok and practically works.
Please review my previous message.

4) "Skipping bars mechanism does not work as intended

- Skipping bars only works when TF=1(BarPeriod).
Higher TF do not work in practice - see p1, nor using frameSync - see p2.

- there is a key bug with frame formation.
Open/highs/lows of skipped bars are not really skipped, still counted in the veeery long TF.
Please, answer my other post.

- most importantly and critically, setting a TF to a negative value after skipping bars technically creates a new frame (frame(0)=1). which has
open= close of previous frame (current,incorrect) or open of 'TimeFrame' minutes ago (correct)
close=current bar close;
High/Low = within the period from Open to close;

What shall one do with this extra Frame which covers unneeded hours? How can it be skipped?

May I suggest that setting TimeFrame to a negative number just starts the Frame and at this moment frame(0) returns 0?

Daily TF.
Assuming there are M1 data 24/5, what's the way to construct a series of *Daily* bars (as a secondary TF in a system with BarPeriod=5) which only cover Regular Trading Hours, say, from 8:30 to 15:30ET?

Your advise is highly appreciated.
Posted By: jcl

Re: Market hours for Globex - 01/11/18 12:01

Ok. For avoiding a complete confusion with your multitude of issues in as many threads, let's systematically address your problems one after the other, starting here with the first one.

>>1) TF>1 just counts *TF number of bars*. <<

Right.

>>But because there are no M1 bars from 1700-1715 and because there is a bug with Weekend>2+ (it still creates a weekend bar) - all Frames get continuously shifted and are incorrect.<<

Can you explain that "bug with Weekend>2+", possibly with a reproducible example?
Posted By: Zheka

Re: Market hours for Globex - 01/11/18 16:50

Ok!

This code
Quote:
function run()
{
set(LOGFILE);
BarOffset=1;
BarPeriod=5;

StartWeek=72000;
EndWeek=52100;


Weekend=1;
}

generates this output with Weekend=1
Quote:
[1868: Fri 16-05-13 20:56] (122.82)n FrameOffset: 0, timeFrame=1 ET Time=1656, O= 122.80200, C= 122.82400

[1869: Fri 16-05-13 21:01] (122.99)n FrameOffset: 0, timeFrame=1 ET Time=1701, O= 122.82400, C= 122.98700

[1870: Sun 16-05-15 21:21] (122.85)n FrameOffset: 0, timeFrame=1 ET Time=1721, O= 122.94500, C= 122.84800

[1871: Sun 16-05-15 21:26] (122.86)n FrameOffset: 0, timeFrame=1 ET Time=1726, O= 122.86400, C= 122.86400

and this - with Weekend=2;
Quote:
[1858: Fri 16-05-13 20:51] (122.80)n FrameOffset: 0, timeFrame=1 ET Time=1651, O= 122.80300, C= 122.80200

[1859: Fri 16-05-13 20:56] (122.82)n FrameOffset: 0, timeFrame=1 ET Time=1656, O= 122.80200, C= 122.82400

[1860: Sun 16-05-15 22:01] (122.87)n FrameOffset: 0, timeFrame=1 ET Time=1801, O= 122.82400, C= 122.87300

[1861: Sun 16-05-15 22:06] (122.85)n FrameOffset: 0, timeFrame=1 ET Time=1806, O= 122.84600, C= 122.84700


1) StartWeek with Weekend=2 keeps its default value of 2200.

2) There is indeed no extra weekend bar; must have been fixed in the new ver.

3) It will be very useful to have StartWeek/EndWeek precision down to a minute. Why not?

There needs to be an ability to "end the week" at the desired time: close all bars/timeframes at that time, not generate any bars nor timeframes during the weekend, and similarly start the week at StartWeek (start the first bar at StartWeek)
Would it be possible to add such a mode to Weekend?

Together with StartMarket/EndMarket, this would help emulate the concept of "Sessions" commonly used in other software.
Posted By: jcl

Re: Market hours for Globex - 01/12/18 10:19

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

The duration of a 5 minutes bar is 5 minutes. If it's weekend or if the history contains no prices, the bar ends at the next multiple of 5 minutes. I think for most users this is not very surprising. Nothing wrong with StartWeek. If you want a bar to start at a particular minute, use either 1 minutes bars, or a bar offset. For doing something exactly at market open, I would not tamper with bars anyway, but just compare the time.

Your next issue: >>BarPeriod=5 - frameSync(4) almost works.<<

This works not almost, it works not at all. frameSync() is for synchronizing to full hours. frameSync(4) is not a full hour. frameSync(12) would be a full hour. Again the manual is your friend: http://manual.zorro-project.com/frame.htm
Posted By: Zheka

Re: Market hours for Globex - 01/12/18 12:02

Let's finish with StartWeek.

The script sets StartWeek to 2000. The M1 bars are available from 2115 and Weekend=1 shows that.
Why with Weekend=2 the first bar on Sunday is 2201? And not 2116 or 2121?
Posted By: jcl

Re: Market hours for Globex - 01/12/18 13:13

I suppose because there are no prices before 2201. Check that with the history editor from the download page. If it has prices at 2115, you should normally be able to start the week at 2115. But if not, you can upload the historical data here and I'll look into the problem.
Posted By: Zheka

Re: Market hours for Globex - 01/12/18 17:18

I am copy-pasting from the message above.
There are bars from 21:15

Weekend=1
Quote:
Quote:
[1868: Fri 16-05-13 20:56] (122.82)n FrameOffset: 0, timeFrame=1 ET Time=1656, O= 122.80200, C= 122.82400

[1869: Fri 16-05-13 21:01] (122.99)n FrameOffset: 0, timeFrame=1 ET Time=1701, O= 122.82400, C= 122.98700

[1870: Sun 16-05-15 21:21] (122.85)n FrameOffset: 0, timeFrame=1 ET Time=1721, O= 122.94500, C= 122.84800

[1871: Sun 16-05-15 21:26] (122.86)n FrameOffset: 0, timeFrame=1 ET Time=1726, O= 122.86400, C= 122.86400

and this - with Weekend=2;

Quote:
[1858: Fri 16-05-13 20:51] (122.80)n FrameOffset: 0, timeFrame=1 ET Time=1651, O= 122.80300, C= 122.80200

[1859: Fri 16-05-13 20:56] (122.82)n FrameOffset: 0, timeFrame=1 ET Time=1656, O= 122.80200, C= 122.82400

[1860: Sun 16-05-15 22:01] (122.87)n FrameOffset: 0, timeFrame=1 ET Time=1801, O= 122.82400, C= 122.87300

[1861: Sun 16-05-15 22:06] (122.85)n FrameOffset: 0, timeFrame=1 ET Time=1806, O= 122.84600, C= 122.84700


Attached is also a screenshot from the history editor (look at top-right box).

Attached picture Zorro_1m_SW2115EW2100_160513-15.PNG
Posted By: jcl

Re: Market hours for Globex - 01/15/18 09:36

Thanks! If missing prices are not the reason, then it's possibly some limit to the earliest week start. I'll inquire. - Update: I learned the weekend has indeed a 2 days 'core' from Friday 22:00 til Sunday 22:00. It can be made longer, but not shorter than those 2 days. And yes, this limit can be probably removed in a future version. Setting up the weekend is the user's responsibility, so there's no real reason for a limit.
Posted By: Zheka

Re: Market hours for Globex - 01/16/18 16:12

OK. Similarly, there is no obvious reason for rounding off this settings to an hour; it should be at user's discretion.

Let's now fast forward our discussion to the "skipped bars"/ frame constructions.
Posted By: jcl

Re: Market hours for Globex - 01/17/18 10:23

>>- Skipping bars only works when TF=1(BarPeriod).
Higher TF do not work in practice<<

It's the other way around: TF = 1 does not skip bars, you need TF != 1 for skipping bars.

>>- there is a key bug with frame formation.
Open/highs/lows of skipped bars are not really skipped, still counted in the veeery long TF. <<

That's the very purpose of a time frame. What exactly is the problem?
Posted By: Zheka

Re: Market hours for Globex - 01/17/18 13:09

Quote:
Skipping bars only works when TF=1(BarPeriod). Higher TF do not work in practice

If BarPeriod=5 and desired trading TF is 20min (i.e. TF=4), then outside of "market hours":
- bars are skipped with TF=0,
- TF set to -N at start of a new frame, and then....
-...TF is to be set to what value?

Or do you suggest to construct each and every frame manually by checking the time?

Quote:
Open/highs/lows of skipped bars are not really skipped, still counted in the veeery long TF. - That's the very purpose of a time frame

I want to trade during "market hours" and I want to use a series of bars/frames that will ONLY contain information from that period.

I do not want to include in such a 20-min series an irregular, oversized frame that covers the "overnight/overweekend" period.

Is that a fair paradigm and expectation?
Posted By: jcl

Re: Market hours for Globex - 01/17/18 13:39

>>-...TF is to be set to what value?

For skipping 4 bars, have you tried the value 4?

>>I want to trade during "market hours" and I want to use a series of bars/frames that will ONLY contain information from that period.<<

What are you then doing with timeframes? If you only want to completely ignore bars outside market hours, then simply do not use their prices for your indicators and do not trade at that time.

Maybe the problem is some misconception of bars and time frames. I do not know what you want to achieve, but when you explain in more detail when and under what conditions you want to enter which trades, I can probably help better.
Posted By: Zheka

Re: Market hours for Globex - 01/17/18 15:02

Quote:
..TF is to be set to what value? For skipping 4 bars, how about the value 4?

Setting TF=4 will not produce correct frames - because TF just counts bars and lands at each TFx bar , regardless if it has been skipped or not.
So, for a Globex session ending 17:00 ET and starting 18:00 ET.
Quote:
[848: Wed 16-05-11 20:21] (123.91)
[849: Wed 16-05-11 20:26] (123.91)
[850: Wed 16-05-11 20:31] (123.88)
[851: Wed 16-05-11 20:36] (123.89)n FrameOffset: 3, timeFrame=4 ET Time=1636, O= 123.87600, C= 123.89500

[852: Wed 16-05-11 20:41] (123.91)
[853: Wed 16-05-11 20:46] (123.94)
[854: Wed 16-05-11 20:51] (123.94)
[855: Wed 16-05-11 20:56] (123.88)n FrameOffset: 3, timeFrame=4 ET Time=1656, O= 123.89500, C= 123.87600

[856: Wed 16-05-11 21:01] (123.90) Skiping.. Time= 1701, skipBars= -1

[857: Wed 16-05-11 21:16] (123.87) Skiping.. Time= 1716, skipBars= -2

[858: Wed 16-05-11 21:21] (123.93) Skiping.. Time= 1721, skipBars= -3

[859: Wed 16-05-11 21:26] (123.88) Skiping.. Time= 1726, skipBars= -4

[860: Wed 16-05-11 21:31] (123.92) Skiping.. Time= 1731, skipBars= -5

[861: Wed 16-05-11 21:36] (123.93) Skiping.. Time= 1736, skipBars= -6

[862: Wed 16-05-11 21:41] (123.90) Skiping.. Time= 1741, skipBars= -7

[863: Wed 16-05-11 21:46] (123.91) Skiping.. Time= 1746, skipBars= -8

[864: Wed 16-05-11 21:51] (123.91) Skiping.. Time= 1751, skipBars= -9

[865: Wed 16-05-11 21:56] (123.91) Skiping.. Time= 1756, skipBars= -10

[866: Wed 16-05-11 22:01] (123.94)n FrameOffset: 3, timeFrame=-10 ET Time=1801, O= 123.87600, C= 123.93900

[867: Wed 16-05-11 22:06] (123.92)n FrameOffset: 3, timeFrame=4 ET Time=1806, O= 123.91100, C= 123.92100

[868: Wed 16-05-11 22:11] (123.92)
[869: Wed 16-05-11 22:16] (123.93)
[870: Wed 16-05-11 22:21] (123.93)
[871: Wed 16-05-11 22:26] (123.92)n FrameOffset: 3, timeFrame=4 ET Time=1826, O= 123.92100, C= 123.92400

And no amount of tinkering will solve this with a current built-in mechanism.

Quote:
If you only want to completely ignore bars outside market hours, then simply do not use their prices for your indicators

Yes, I want to completely ignore prices outside market hours.
How can I construct a series of 20min bars(or frames) that would ONLY contain prices within the defined "session"?

In general, ALL other software I worked with -TS,MC,NT,SC,WL,MT5- have "sessions" as a basic concept ( most- per day), and bar construction is governed by session start/end settings.
Porting working, tested systems to Zorro, I would like to achieve 100% consistency.
Posted By: jcl

Re: Market hours for Globex - 01/17/18 15:46

For a series of prices only within market hours, just fill a static series only within market hours.

vars Prices = series(0,-100);
if(market(...)) shift(Prices,priceClose(),100);
Posted By: Zheka

Re: Market hours for Globex - 01/17/18 18:10

It just hit me that Skipped bars define the start of the frame! It is not at all necessary to set TF=Skipped bars after skipping bars - as one is conditioned by the manual.
You can set it to the number of bars(negative) back you really need the frame to span and that would only merge that number of bars! Urahh!

This explanation should be added to the manual!

One more question re bar() function:
- can you please give an example in the manual how Start and Time fields can be used?
- is it possible to add a return option that would "not start a bar"

Thank you.
Posted By: Zheka

Re: Market hours for Globex - 01/17/18 18:14


I also think it would be better if a Frame had been calculated by Zorro internally by the number of minutes, not the number of bars.
Bars can be absent for some reason in the historical data or in RT, but that should not be shifting frames..

Yes, one can code around this situation, but why would not Zorro take care of it by default?
Posted By: jcl

Re: Market hours for Globex - 01/18/18 14:38

I have no example of special bars that use Start and Time. For not starting a bar, return 4. - It's the same as with most software libraries: What's often used is the default, what's rare or unusual must be explicitely coded.
Posted By: Zheka

Re: Market hours for Globex - 01/18/18 15:11

Ensuring that the Timeframe always covers the intended period is on the side of "proofing" and "making the functionality more robust", rather than a "special request", I believe.
Posted By: Zheka

Re: Market hours for Globex - 01/18/18 16:13

Question:
when TimeFrame=0, what value will priceOpen() report? From which bar?
Posted By: jcl

Re: Market hours for Globex - 01/18/18 17:01

I guess from the current bar. But prices of a time frame are only defined at the end of the frame.
Posted By: Zheka

Re: Market hours for Globex - 01/18/18 17:34

It turns out, priceOpen will be equal to an open of the previously set TimeFrame bars ago.
E.g. if the usual/previous TF=4 and currently we are skipping bars (TimeFrame=0),
then priceOpen()=Open[4].
© 2024 lite-C Forums