A code for trading session hours for a given date
Author: gpwr
Creation Date: 5/25/2009 5:36 PM
profile picture

gpwr

#1
I have an intraday strategy that sometimes exits at the close of a trading session. Typically, it is 15:59. But, on days before the US holidays, it can be 12:59. I would like to find a code that would tell me the closing time of a session, both for the past and future dates. Thanks in advance.
profile picture

gpwr

#2
Got it working. The code
CODE:
Please log in to see this code.

profile picture

Cone

#3
You can make this quite a bit more robust by reading Application.UserAppDataPath + @"\Data\Markets.xml" to get the special hours info.
profile picture

kazuna

#4
Do you know why the day before July 4th isn't special hours but only 2009?
profile picture

Cone

#5
Not really, but my guess is that it's because the 4th, normally a market holiday, is on a Saturday this year.
profile picture

gpwr

#6
QUOTE:
You can make this quite a bit more robust by reading Application.UserAppDataPath + @"\Data\Markets.xml" to get the special hours info.

Thanks, but I did not understand. I am still learning WL5 scripting language and would appreciate if you explain what you mean by <<reading Application.UserAppDataPath + @"\Data\Markets.xml">>. If it is not too much trouble, can you please show a working code of getting the special hours info. Thanks in advance.
profile picture

Eugene

#7
This programming subject requires a little knowledge of XML processing in C#. Here's an example for you that will highlight shortened session dates. But firstly, make sure to click "References" and having checked "System.Xml" in the dialog. You'll need to do that for every strategy where you'd like this code to be used.
CODE:
Please log in to see this code.
profile picture

gpwr

#8
Great! Thanks a lot!
profile picture

Eugene

#9
An updated and revised version of the code is being included in Community.Components.
profile picture

pigo

#10
And how to modify this code, to get info about Holidays from Markets.xml file?
profile picture

Eugene

#11
Have you already tried and came up with something that we could correct?
profile picture

pigo

#12
CODE:
Please log in to see this code.
profile picture

Eugene

#13
Nice attempt. Especially considering that your trial has expired in May, and even a 'replacement' trial that you took under the name 'misirlou' - which we consider to be an unfair, cheater practice - has also expired in June.

Change this:
CODE:
Please log in to see this code.

To:
CODE:
Please log in to see this code.


And then, replace this line:
CODE:
Please log in to see this code.

With this one:
CODE:
Please log in to see this code.


Enjoy.
profile picture

pigo

#14
Thanks.

And is there a way to check if current day is short term session?


P.S.: I want to buy a license, as soon as I will be sure, that I can use it 100%.
profile picture

Eugene

#15
QUOTE:
And is there a way to check if current day is short term session?


This is just what this line of code does:
CODE:
Please log in to see this code.

Since "Today" stands for Bars.Count-1, you'll need to add a check for bar == Bars.Count-1.

As you understand, it applies to code in my message from 5/27/2009 4:14 AM (or in Community.Components).
profile picture

pigo

#16
Understand, thank you.