NexusFi: Find Your Edge


Home Menu

 





How to calculate Exchange Opening Time?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one baruchs with 5 posts (0 thanks)
    2. looks_two Fat Tails with 3 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 sharmas with 1 posts (0 thanks)
    1. trending_up 7,116 views
    2. thumb_up 0 thanks given
    3. group 4 followers
    1. forum 13 posts
    2. attach_file 1 attachments




 
Search this Thread

How to calculate Exchange Opening Time?

  #11 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103


sam028 View Post
Why are you using in variables instead of DateTime variables ?
You want to manipulate "the opening times of all exchanges", so it will be much easier to manipulate DateTime than int, as you have all the needed classes and methods to play with timezones.
See TimeZoneInfo class, ConvertTime, DateTimeOffset, ...
You know in which timezone are NY, Tokyo, ..., so you're also able to convert any date from a timezone to another one. And as these classes are "DST aware", I don't see where could be the problem to do what you want to do.

The conversion from different timezones does not work for .Net 2.0 / NinjaTrader 6.5. However, .Net 3.5 / NinjaTrader 7.0 are capable of doing the conversion. the session manager of Ninjatrader 7.0 uses this timezone conversion capability.

These are the steps to convert between different timezones:

(1) Define TimeZoneInfo variables which contain the timezoneinfo information. Here is an example to create a timezoneinfo variable for the Asian session (Tokyo time)

 
Code
private TimeZoneInfo tstZone // TST stands for Tokyo Standard Time
try
{
tstZone = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time"); 
}
catch (TimeZoneNotFoundException ex2)
{
throw new TimeZoneNotFoundException( String.Format("The time zone '{0}'cannot be found.", "Tokyo Standard Time"), ex);
}
(2) Next use the TimeZoneInfo variables for conversion. Let us assume that you have defined four variables tstZone, cetZone, gmtZone, estZone and that they contain the correct information collected from the class library. Now you also need your local timezone and the timezone of your session template:

Local timezone can be found as: TimeZoneInfo.Local
Session template timezone can be found as: Bars.Session.TimeZoneInfo

(3) To convert, use TimeZoneInfo.ConvertTime

For example to convert from TST to local Time ->

 
Code
time = TimeZoneInfo.ConvertTime(time, tstZone, TimeZoneInfo.Local)
Or to convert from session template to local time ->

 
Code
time = TimeZoneInfo.ConvertTime(time, Bars.Session.TimeZoneInfo, TimeZoneInfo.Local)
You can now easily code an indicator that prints the market hours on your chart.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
About a successful futures trader who didn´t know anyth …
Psychology and Money Management
How to apply profiles
Traders Hideout
ZombieSqueeze
Platforms and Indicators
Better Renko Gaps
The Elite Circle
Cheap historycal L1 data for stocks
Stocks and ETFs
 
  #12 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103

Here you can find an example, how to apply this. The chart shows today's FOREX sessions:

Session template (in Eastern Time): 3 sessions, Asian, European and US session. The Asian session includes Sydney and Tokio. The European session starts at 2:00 AM Est, which is correct for 49 weeks out of 52 weeks per year. The US session starts at 8:00 AM EST, the Asian session starts at 5:00 PM Est.

European open and London open is collected from the session template. The Tokyo open is generated via indicator, as the session template does only use EST, and is not aware of TST.

The opening range indicator uses TST for the Asian pre-session and CET for the European pre-session.

Created by applying the indicator twice to display both European and US opening range. The indicator is available here:




Reply With Quote
  #13 (permalink)
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009


Hi fat tails,
Thank you very much. I'll work with ETC conversion.
You are very helpful.

Baruch

Started this thread Reply With Quote
  #14 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800


sam028 View Post
Why are you using in variables instead of DateTime variables ?
You want to manipulate "the opening times of all exchanges", so it will be much easier to manipulate DateTime than int, as you have all the needed classes and methods to play with timezones.
See TimeZoneInfo class, ConvertTime, DateTimeOffset, ...
You know in which timezone are NY, Tokyo, ..., so you're also able to convert any date from a timezone to another one. And as these classes are "DST aware", I don't see where could be the problem to do what you want to do.

Interestingly I saw the source code for trading platform that did a similar thing, and it was billed as a performance enhancement (math on ints being less expensive than math on DateTimes, I guess), but I wonder if it merely code that originated back during .NET 2.0. Interesting factoid, Fat Tails. Thanks.

Reply With Quote




Last Updated on January 12, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts