Retrieve Trading Sessions Date & Time
-
- Posts: 24
- Joined: 15 Sep 2013
- Has thanked: 6 times
- Been thanked: 3 times
Retrieve Trading Sessions Date & Time
Hi,
Is there method to retrieve trading session's date & time period for chart resolution lower than daily chart?
e.g. Broker's trading data is based on New York trading time, open at 5pm closes next day at 4.59pm. I'm currently at 5min timeframe chart and the bar time is 8pm and date is 11 Feb 2014. Basically, I want to retrieve trading opening and closing date & time i.e. Opening: 11 Feb 2014 5pm and Closing 12 Feb 2014 4.59pm via coding.
Cheers.
Victor
Is there method to retrieve trading session's date & time period for chart resolution lower than daily chart?
e.g. Broker's trading data is based on New York trading time, open at 5pm closes next day at 4.59pm. I'm currently at 5min timeframe chart and the bar time is 8pm and date is 11 Feb 2014. Basically, I want to retrieve trading opening and closing date & time i.e. Opening: 11 Feb 2014 5pm and Closing 12 Feb 2014 4.59pm via coding.
Cheers.
Victor
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2958 times
Re: Retrieve Trading Sessions Date & Time
Hello Victor,
In order to get the session settings of the instrument please check the SessionObject Members.
In order to get the session settings of the instrument please check the SessionObject Members.
-
- Posts: 24
- Joined: 15 Sep 2013
- Has thanked: 6 times
- Been thanked: 3 times
Re: Retrieve Trading Sessions Date & Time
Hi Henry,
The SessionObjects does not have date, only dayofweek, timespan and a bool to whether it endofsession. where can I retrieve the trading date?
Cheers.
The SessionObjects does not have date, only dayofweek, timespan and a bool to whether it endofsession. where can I retrieve the trading date?
Cheers.
Hello Victor,
In order to get the session settings of the instrument please check the SessionObject Members.
Re: Retrieve Trading Sessions Date & Time
Session definitions do not have a date and it probably makes no sense for a session to have a date. Session is a template for trading days, but not trading days them self. I hope that makes sense. To get a trading date, you just use Bars.Time[0]
With kind regards,
MK
With kind regards,
MK
-
- Posts: 24
- Joined: 15 Sep 2013
- Has thanked: 6 times
- Been thanked: 3 times
Re: Retrieve Trading Sessions Date & Time
Hi MK,
Thanks. I'm aware of Bars.Time[0] date. I'm interested in retrieving start trading date and end trading date. The SessionObject definitions include start and end trading time, and it does make sense to have start and end trading date in SessionObject, forex runs 24/5 or 24/7, start and end date for each trading session are different. With the date, application logic can use it to determine whether the logic is running on the correct trading session date/time. The logic to have session time in SessionObject would be the same for session date.
It does not makes sense for session to include session start and end time without start and end date.
Cheers.
Victor
Thanks. I'm aware of Bars.Time[0] date. I'm interested in retrieving start trading date and end trading date. The SessionObject definitions include start and end trading time, and it does make sense to have start and end trading date in SessionObject, forex runs 24/5 or 24/7, start and end date for each trading session are different. With the date, application logic can use it to determine whether the logic is running on the correct trading session date/time. The logic to have session time in SessionObject would be the same for session date.
It does not makes sense for session to include session start and end time without start and end date.
Cheers.
Victor
Session definitions do not have a date and it probably makes no sense for a session to have a date. Session is a template for trading days, but not trading days them self. I hope that makes sense. To get a trading date, you just use Bars.Time[0]
With kind regards,
MK
Re: Retrieve Trading Sessions Date & Time
I respectfully disagree. Having a date makes no sense to me. All that is needed is a TIME and DAY. Maybe you could give an example of your suggested session definition with a date for forex session. I run many forex symbols and have no issue with how the current session definitions are.
With kind regards,
MK
With kind regards,
MK
-
- Posts: 24
- Joined: 15 Sep 2013
- Has thanked: 6 times
- Been thanked: 3 times
Re: Retrieve Trading Sessions Date & Time
Maybe you have gotten use to the limitation of MC .Net and found ways around it? E.g. do you use barsback or do you use date to retrieve information from previous bars? In MC .Net, there is no in-built method to retrieve previous data using dates, users have to use barsback. Typically, users will use barsback, but what happens if the strategy required dates to retrieve previous info? And in typical case, users will just develop strategies around limitations of MC .Net, does that mean that MC .Net do not need to improve to provide in-built method to retrieve data based on date? Ok, this is just an example to explain what I've mentioned but I respect your opinion on the session trading dates.
I can use other ways too, but a more direct, dynamic and structured way of coding would be to use the session trading dates based on brokerage.
Henry,
Do you guys have method to retrieve the session trading dates?
Cheers.
Victor
I can use other ways too, but a more direct, dynamic and structured way of coding would be to use the session trading dates based on brokerage.
Henry,
Do you guys have method to retrieve the session trading dates?
Cheers.
Victor
I respectfully disagree. Having a date makes no sense to me. All that is needed is a TIME and DAY. Maybe you could give an example of your suggested session definition with a date for forex session. I run many forex symbols and have no issue with how the current session definitions are.
With kind regards,
MK
Re: Retrieve Trading Sessions Date & Time
It is not that I'm used to how MC.net do it. Every charting package of the more than 1/2 dozen that I have used define a symbol with just time and day - never date.
If you gave an example of a session definition for forex that uses DATES, maybe some one could give you some answers. I cannot see how a date definition would even work.
If you gave an example of a session definition for forex that uses DATES, maybe some one could give you some answers. I cannot see how a date definition would even work.
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Retrieve Trading Sessions Date & Time
If you have more than five days of historical data on your chart, you could store the session start and session end times for every historical day (Mon - Fri) in an array. Then determine some day in the future (for example 30 days from now), look up which weekday that is, and then pull the right times from the array.(...)
Do you guys have method to retrieve the session trading dates?
(...)
* * *
How do you guys retrieve the session start and end times, btw? Perhaps I've overlooked it, but I could not find it.
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2958 times
Re: Retrieve Trading Sessions Date & Time
Victor, what particular limitation are you referring to? What is your test case and what is your final goal?In MC .Net, there is no in-built method to retrieve previous data using dates, users have to use barsback. Typically, users will use barsback, but what happens if the strategy required dates to retrieve previous info? And in typical case, users will just develop strategies around limitations of MC .Net, does that mean that MC .Net do not need to improve to provide in-built method to retrieve data based on date? Ok, this is just an example to explain what I've mentioned but I respect your opinion on the session trading dates.
Re: Retrieve Trading Sessions Date & Time
I just use the SessionObject class accessed through Bars.SessionsIf you have more than five days of historical data on your chart, you could store the session start and session end times for every historical day (Mon - Fri) in an array. Then determine some day in the future (for example 30 days from now), look up which weekday that is, and then pull the right times from the array.(...)
Do you guys have method to retrieve the session trading dates?
(...)
* * *
How do you guys retrieve the session start and end times, btw? Perhaps I've overlooked it, but I could not find it.
-
- Posts: 24
- Joined: 15 Sep 2013
- Has thanked: 6 times
- Been thanked: 3 times
Re: Retrieve Trading Sessions Date & Time
Hi JoshM,
Here is how session object are retrieve,
Your idea is good, I'm actually working in the same line as your idea but rather than retrieving x days I only want current trading session date/time.
Regards,
Victor Yong
Here is how session object are retrieve,
Code: Select all
IROList<PowerLanguage.SessionObject> session = Bars.Sessions;
Regards,
Victor Yong
If you have more than five days of historical data on your chart, you could store the session start and session end times for every historical day (Mon - Fri) in an array. Then determine some day in the future (for example 30 days from now), look up which weekday that is, and then pull the right times from the array.(...)
Do you guys have method to retrieve the session trading dates?
(...)
* * *
How do you guys retrieve the session start and end times, btw? Perhaps I've overlooked it, but I could not find it.
-
- Posts: 24
- Joined: 15 Sep 2013
- Has thanked: 6 times
- Been thanked: 3 times
Re: Retrieve Trading Sessions Date & Time
Hi Henry,
MC's limitation wise, I'm speaking in general. But in specific, what irritate me the most is inability to backtest unmanaged orders, that limitation does not make sense the most. I would have expect that being able to code C# we would be able to do much more advance stuff/coding. In this particular aspect, MC is taking one step forward, two steps back (referring being able manage my own position but unable to do backtesting with unmanaged orders, which is one of the core attraction to MC's platform).
I hope there are plans to revamp the engine, to enable unmanaged orders backtesting in the near future. I believe many experience programmers would prefer such route compared to using managed orders. It would be great to have control over our orders/position with more structured coding from backtesting all the way to production level.
In terms of my actual test case, I'm unable to provide the codes. Since there are no methods to retrieve start and end session dates, I'll have to develop it or just code a workaround. But I can give a simple example of where it is needed as well,
e.g. a strategy below 1 day timeframe period that only allows one trade a day. Once the SL is trigger no orders are allow until the next trading day. In this case, it would be just easier to have start and end trading session dates & time, do an if statement to filter out the logic (of course filtering it out with the previous exit orders as well) , that would be simple, and direct. Unfortunately, a simple workaround for the logic is required when developing with MC using C#, I assume that this is the typical approach for many MC .Net users (I might be wrong, I'm new to MC .Net).
Regards,
Victor Yong
MC's limitation wise, I'm speaking in general. But in specific, what irritate me the most is inability to backtest unmanaged orders, that limitation does not make sense the most. I would have expect that being able to code C# we would be able to do much more advance stuff/coding. In this particular aspect, MC is taking one step forward, two steps back (referring being able manage my own position but unable to do backtesting with unmanaged orders, which is one of the core attraction to MC's platform).
I hope there are plans to revamp the engine, to enable unmanaged orders backtesting in the near future. I believe many experience programmers would prefer such route compared to using managed orders. It would be great to have control over our orders/position with more structured coding from backtesting all the way to production level.
In terms of my actual test case, I'm unable to provide the codes. Since there are no methods to retrieve start and end session dates, I'll have to develop it or just code a workaround. But I can give a simple example of where it is needed as well,
e.g. a strategy below 1 day timeframe period that only allows one trade a day. Once the SL is trigger no orders are allow until the next trading day. In this case, it would be just easier to have start and end trading session dates & time, do an if statement to filter out the logic (of course filtering it out with the previous exit orders as well) , that would be simple, and direct. Unfortunately, a simple workaround for the logic is required when developing with MC using C#, I assume that this is the typical approach for many MC .Net users (I might be wrong, I'm new to MC .Net).
Regards,
Victor Yong
Victor, what particular limitation are you referring to? What is your test case and what is your final goal?In MC .Net, there is no in-built method to retrieve previous data using dates, users have to use barsback. Typically, users will use barsback, but what happens if the strategy required dates to retrieve previous info? And in typical case, users will just develop strategies around limitations of MC .Net, does that mean that MC .Net do not need to improve to provide in-built method to retrieve data based on date? Ok, this is just an example to explain what I've mentioned but I respect your opinion on the session trading dates.
Re: Retrieve Trading Sessions Date & Time
The logic expressed above is simple to do. You just need to flag session end boundary by as I had said previously, using either session object or LastBarInSession property. I personally think sesison object approach is cleaner rather than checking if previous bar was the last bar in session, but this is probably personal taste.
Once you have the session boundary determining code done, wrap all your system logic within your if !hasNotTradedToday flag.
Once you have the session boundary determining code done, wrap all your system logic within your if !hasNotTradedToday flag.
-
- Posts: 24
- Joined: 15 Sep 2013
- Has thanked: 6 times
- Been thanked: 3 times
Re: Retrieve Trading Sessions Date & Time
Yes, you are correct on the solution. I actually gave an invalid example.. lol.. sessionobject's dayofweek and session time is good enough for the logic.
The logic expressed above is simple to do. You just need to flag session end boundary by as I had said previously, using either session object or LastBarInSession property. I personally think sesison object approach is cleaner rather than checking if previous bar was the last bar in session, but this is probably personal taste.
Once you have the session boundary determining code done, wrap all your system logic within your if !hasNotTradedToday flag.
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2958 times
Re: Retrieve Trading Sessions Date & Time
We are going to add this functionality in MultiCharts 9.1 with the new autotrading/backtesting engine.But in specific, what irritate me the most is inability to backtest unmanaged orders
You can also use DateTime.Now.DayOfWeek to get the current day of week and compare it with the Session object.Yes, you are correct on the solution. I actually gave an invalid example.. lol.. sessionobject's dayofweek and session time is good enough for the logic.
-
- Posts: 24
- Joined: 15 Sep 2013
- Has thanked: 6 times
- Been thanked: 3 times
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Retrieve Trading Sessions Date & Time
Thanks guys for how to retrieve the session times.
* * *
Which gives the following output:
Today is 15-2, so minus three days is indeed 12-2, and that was indeed Wednesday.
* * *
When exploring session information, I came across this (note: I found the 'SessionForDate' idea in Dru's TPO indicator):(...)
Do you guys have method to retrieve the session trading dates?
(...)
Code: Select all
if ((Bars.Status == EBarState.Close) && (Bars.LastBarOnChart))
{
DateTime pastTime = DateTime.Now.AddDays(-3);// or use - TimeSpan.FromDays(3);
var newSession = Bars.Sessions.SessionForDate(pastTime);
Output.WriteLine("Past date: {0}. Session start time: {1}, end time: {2}. Start day: {3} and end day: {4}",
pastTime.ToString("d-M HH:mm:ss"),
newSession.StartTime,
newSession.EndTime,
newSession.StartDay,
newSession.EndDay);
}
Code: Select all
Past date: 12-2 06:27:41. Session start time: 00:00:00, end time: 23:59:00. Start day: Wednesday and end day: Wednesday
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Retrieve Trading Sessions Date & Time
Is it also possible to retrieve multiple sessions per day? Currently, at least how I do it, is that 'StartTime' gives the time of the first session of the day, and 'EndTime' the time at which the trading day ended. However, some symbols (like ES) have multiple sessions per day.In order to get the session settings of the instrument please check the SessionObject Members.
For example, my ES symbol has two sessions per day. Output however gives:
Code: Select all
Monday, start time: 00:00:00, End time: 23:15:00
Tuesday, start time: 00:00:00, End time: 23:15:00
Wednesday, start time: 00:00:00, End time: 23:15:00
Thursday, start time: 00:00:00, End time: 23:15:00
Friday, start time: 00:00:00, End time: 23:15:00
Code: Select all
for (int i = 0; i < Bars.Sessions.Count; i++)
{
Output.WriteLine("{0}, start time: {1}, End time: {2}",
Bars.Sessions[i].StartDay,
Bars.Sessions[i].StartTime,
Bars.Sessions[i].EndTime);
}
-
- Posts: 24
- Joined: 15 Sep 2013
- Has thanked: 6 times
- Been thanked: 3 times
Re: Retrieve Trading Sessions Date & Time
I search and found a code that was develop by Dru,
http://www.multicharts.com/discussion/v ... sionobject
There are some limitation to the codes, but can be used to retrieve current trading session date & time.
http://www.multicharts.com/discussion/v ... sionobject
There are some limitation to the codes, but can be used to retrieve current trading session date & time.
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Retrieve Trading Sessions Date & Time
To tentatively answer my own question, apparently not. When using the EndOfSession property, which "Returns DateTime end of session (sess) that is nearest to specified DateTime (_dt) in the future.", only the closing time of the last session is returned:Is it also possible to retrieve multiple sessions per day?In order to get the session settings of the instrument please check the SessionObject Members.
Code: Select all
protected override void CalcBar()
{
Output.WriteLine("{0} - EndOfSession: {1}",
Bars.Time[0].ToString("d-M HH:mm:ss"),
Bars.Sessions[Math.Max((int)Bars.TimeValue.DayOfWeek - 1,0)].EndOfSession(Bars.TimeValue));
}
Code: Select all
7-2 10:45:00 - EndOfSession: 7-2-2014 16:15:00
7-2 11:00:00 - EndOfSession: 7-2-2014 16:15:00
7-2 11:15:00 - EndOfSession: 7-2-2014 16:15:00
7-2 11:30:00 - EndOfSession: 7-2-2014 16:15:00
7-2 11:45:00 - EndOfSession: 7-2-2014 16:15:00
7-2 12:00:00 - EndOfSession: 7-2-2014 16:15:00
7-2 12:15:00 - EndOfSession: 7-2-2014 16:15:00
7-2 12:30:00 - EndOfSession: 7-2-2014 16:15:00
7-2 12:45:00 - EndOfSession: 7-2-2014 16:15:00
7-2 13:00:00 - EndOfSession: 7-2-2014 16:15:00
7-2 13:15:00 - EndOfSession: 7-2-2014 16:15:00
7-2 13:30:00 - EndOfSession: 7-2-2014 16:15:00
7-2 13:45:00 - EndOfSession: 7-2-2014 16:15:00
7-2 14:00:00 - EndOfSession: 7-2-2014 16:15:00
7-2 14:15:00 - EndOfSession: 7-2-2014 16:15:00
7-2 14:30:00 - EndOfSession: 7-2-2014 16:15:00
7-2 14:45:00 - EndOfSession: 7-2-2014 16:15:00
7-2 15:00:00 - EndOfSession: 7-2-2014 16:15:00
7-2 15:15:00 - EndOfSession: 7-2-2014 16:15:00
7-2 15:45:00 - EndOfSession: 7-2-2014 16:15:00
7-2 16:00:00 - EndOfSession: 7-2-2014 16:15:00
7-2 16:15:00 - EndOfSession: 7-2-2014 16:15:00
9-2 17:15:00 - EndOfSession: 10-2-2014 16:15:00
9-2 17:30:00 - EndOfSession: 10-2-2014 16:15:00
9-2 17:45:00 - EndOfSession: 10-2-2014 16:15:00
9-2 18:00:00 - EndOfSession: 10-2-2014 16:15:00
9-2 18:15:00 - EndOfSession: 10-2-2014 16:15:00
9-2 18:30:00 - EndOfSession: 10-2-2014 16:15:00
9-2 18:45:00 - EndOfSession: 10-2-2014 16:15:00
9-2 19:00:00 - EndOfSession: 10-2-2014 16:15:00
9-2 19:15:00 - EndOfSession: 10-2-2014 16:15:00
9-2 19:30:00 - EndOfSession: 10-2-2014 16:15:00
9-2 19:45:00 - EndOfSession: 10-2-2014 16:15:00
9-2 20:00:00 - EndOfSession: 10-2-2014 16:15:00
9-2 20:15:00 - EndOfSession: 10-2-2014 16:15:00
9-2 20:30:00 - EndOfSession: 10-2-2014 16:15:00
9-2 20:45:00 - EndOfSession: 10-2-2014 16:15:00
9-2 21:00:00 - EndOfSession: 10-2-2014 16:15:00
9-2 21:15:00 - EndOfSession: 10-2-2014 16:15:00
9-2 21:30:00 - EndOfSession: 10-2-2014 16:15:00
9-2 21:45:00 - EndOfSession: 10-2-2014 16:15:00
9-2 22:00:00 - EndOfSession: 10-2-2014 16:15:00
9-2 22:15:00 - EndOfSession: 10-2-2014 16:15:00
9-2 22:30:00 - EndOfSession: 10-2-2014 16:15:00
9-2 22:45:00 - EndOfSession: 10-2-2014 16:15:00
9-2 23:00:00 - EndOfSession: 10-2-2014 16:15:00
9-2 23:15:00 - EndOfSession: 10-2-2014 16:15:00
9-2 23:30:00 - EndOfSession: 10-2-2014 16:15:00
9-2 23:45:00 - EndOfSession: 10-2-2014 16:15:00
10-2 00:00:00 - EndOfSession: 10-2-2014 16:15:00
10-2 00:15:00 - EndOfSession: 10-2-2014 16:15:00
10-2 00:30:00 - EndOfSession: 10-2-2014 16:15:00
10-2 00:45:00 - EndOfSession: 10-2-2014 16:15:00
10-2 01:00:00 - EndOfSession: 10-2-2014 16:15:00
10-2 01:15:00 - EndOfSession: 10-2-2014 16:15:00
10-2 01:30:00 - EndOfSession: 10-2-2014 16:15:00
10-2 01:45:00 - EndOfSession: 10-2-2014 16:15:00
10-2 02:00:00 - EndOfSession: 10-2-2014 16:15:00
10-2 02:15:00 - EndOfSession: 10-2-2014 16:15:00
10-2 02:30:00 - EndOfSession: 10-2-2014 16:15:00
10-2 02:45:00 - EndOfSession: 10-2-2014 16:15:00
10-2 03:00:00 - EndOfSession: 10-2-2014 16:15:00
10-2 03:15:00 - EndOfSession: 10-2-2014 16:15:00
10-2 03:30:00 - EndOfSession: 10-2-2014 16:15:00
10-2 03:45:00 - EndOfSession: 10-2-2014 16:15:00
(Session 1 from 17:00 to 15:15 and session 2 from 15:30 to 16:15).
Am I doing something wrong?
If not, when is this big limitation removed?* Even the regular MultiCharts allows retrieving times for multiple sessions (i.e. Sess1FirstBarTime, Sess2FirstBarTime).
*: But without code breaking changes if you don't mind me saying. For example, rather add something like 'Bars.Session[index weekday].FirstSessStart' and 'Bars.Session[index weekday].SecondSessStart'.
- Attachments
-
- scr.16-02-2014 08.12.09.png
- (32.89 KiB) Downloaded 3839 times
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2958 times
Re: Retrieve Trading Sessions Date & Time
JoshM, unfortunately that is not possible at the moment. This functionality will be added in MultiCharts .NET 9.0 Beta1Is it also possible to retrieve multiple sessions per day?