NexusFi: Find Your Edge


Home Menu

 





Trading multiple time zones


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one DarkPoolTrading with 4 posts (0 thanks)
    2. looks_two traderwerks with 1 posts (1 thanks)
    3. looks_3 Fat Tails with 1 posts (1 thanks)
    4. looks_4 baruchs with 1 posts (0 thanks)
    1. trending_up 3,769 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 8 posts
    2. attach_file 0 attachments




 
Search this Thread

Trading multiple time zones

  #1 (permalink)
 
DarkPoolTrading's Avatar
 DarkPoolTrading   is a Vendor
 
Posts: 1,036 since May 2012
Thanks Given: 1,244
Thanks Received: 1,326

Hi All,

I trade different time zones to where I live. This is not a problem when doing discretionary trading because I can just look at a world clock and know what the relevant time zone of the instrument im trading is. However what I would like to do is implement parameters into my strategies so that I can enter the relevant trading hours depending on what instrument im trading.

For example my local time is 6 hours ahead of New York. If I want a strategy to only trade New York time 09:00 to 16:00 that will be 15:00 to 22:00 my local time. So because NinjaTrader displays the local time from my PC, I will need to code NinjaScript to only trade between 15:00 to 22:00. Is that correct so far?

Now my problem comes in with day light savings and time changes. This is because my local time does not change (no day light savings here). Therefore instead of the system using 15:00 to 22:00 it must use 16:00 to 23:00 for example.

I would like to specify in code that between month X and month Y each year, the strategy should use a certain time frame (eg: 15:00 to 22:00). But from month A to month B, use a different time frame.

Is there a way to code that?

Any advice is much appreciated.

Follow me on Twitter Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Are there any eval firms that allow you to sink to your …
Traders Hideout
ZombieSqueeze
Platforms and Indicators
Better Renko Gaps
The Elite Circle
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
 
  #3 (permalink)
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009



Quoting 
Is there a way to code that?

May be. My solution was to change my computer TZ to CT. This is because here in Israel we have a bigger problem, our day light savings are irregular.

Baruch

Reply With Quote
  #4 (permalink)
 
DarkPoolTrading's Avatar
 DarkPoolTrading   is a Vendor
 
Posts: 1,036 since May 2012
Thanks Given: 1,244
Thanks Received: 1,326

Ok, thanks for the reply. It's not a huge issue if this is not possible.

Follow me on Twitter Started this thread Reply With Quote
  #5 (permalink)
 
DarkPoolTrading's Avatar
 DarkPoolTrading   is a Vendor
 
Posts: 1,036 since May 2012
Thanks Given: 1,244
Thanks Received: 1,326

I've just been thinking about this problem a bit more, and this is going to affect all back testing results on instruments in different time zones which have daylight savings if your local time does not have daylight savings.

This is because from the end of March to the end of October, the local trading time should be 09:00 to 17:30 to correspond to the foreign market. But for the other 6 months of the year, trading will from 10:00 to 18:30 local time to correspond to the foreign market.

Without being able to specify in code what time's should be used for certain times of the year, the results will not be accurate. Surely someone else has realised this and found a way around it with their back tests? Is there some sort of Month parameter that can be created?

thanks.

Follow me on Twitter Started this thread Reply With Quote
  #6 (permalink)
 traderwerks   is a Vendor
 
Posts: 692 since Jun 2009
Thanks Given: 436
Thanks Received: 465


DarkPoolTrading View Post
I've just been thinking about this problem a bit more, and this is going to affect all back testing results on instruments in different time zones which have daylight savings if your local time does not have daylight savings.

This is because from the end of March to the end of October, the local trading time should be 09:00 to 17:30 to correspond to the foreign market. But for the other 6 months of the year, trading will from 10:00 to 18:30 local time to correspond to the foreign market.

Without being able to specify in code what time's should be used for certain times of the year, the results will not be accurate. Surely someone else has realised this and found a way around it with their back tests? Is there some sort of Month parameter that can be created?

thanks.

Does this help


Quoting 
NinjaTrader 7 has conversion between time zonens. I hear the code below won't run on on NT6.5. I am not sure, I haven't been doing any thing serious on 6.5 since the NT7 beta came out in 2009. If you are still using NT6.5, please stop. Really.

You can access the local timezone ( of the machine you are using )

 
Code
TimeZoneInfo.Local
You can acces the TimeZone infor the the time zone in question by looking it up via the string.

 
Code
private string exchange_timezone = "Central European Standard Time" ;
private TimeZoneInfo time = TimeZoneInfo.ConvertTime(time, tstZone, TimeZoneInfo.Local);
cet_timezone = TimeZoneInfo.FindSystemTimeZoneById(exchange_timezone );
Now that yo have the timezone of where you are and the timezone of where you are trading and your local time, you can convert, using TimeZoneInfo.ConvertTime

 
Code
time = TimeZoneInfo.ConvertTime(time, cet_timezone , TimeZoneInfo.Local)


Math. A gateway drug to reality.
Reply With Quote
Thanked by:
  #7 (permalink)
 
DarkPoolTrading's Avatar
 DarkPoolTrading   is a Vendor
 
Posts: 1,036 since May 2012
Thanks Given: 1,244
Thanks Received: 1,326

Great, thanks for the reply. Ill give that a try tonight, but at first look I think it's gong to work.

Follow me on Twitter Started this thread Reply With Quote
  #8 (permalink)
 Traderji 
Australia
 
Experience: Advanced
Platform: NinjaTrader, Multicharts
Trading: Spot Forex, Gold, Silver
Posts: 176 since Oct 2010
Thanks Given: 114
Thanks Received: 114

Have a look at the code from in my indicator. It's fairly straightforward to get/convert timezone in C#


Reply With Quote
  #9 (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,102


DarkPoolTrading View Post
Hi All,

I trade different time zones to where I live. This is not a problem when doing discretionary trading because I can just look at a world clock and know what the relevant time zone of the instrument im trading is. However what I would like to do is implement parameters into my strategies so that I can enter the relevant trading hours depending on what instrument im trading.

For example my local time is 6 hours ahead of New York. If I want a strategy to only trade New York time 09:00 to 16:00 that will be 15:00 to 22:00 my local time. So because NinjaTrader displays the local time from my PC, I will need to code NinjaScript to only trade between 15:00 to 22:00. Is that correct so far?

Now my problem comes in with day light savings and time changes. This is because my local time does not change (no day light savings here). Therefore instead of the system using 15:00 to 22:00 it must use 16:00 to 23:00 for example.

I would like to specify in code that between month X and month Y each year, the strategy should use a certain time frame (eg: 15:00 to 22:00). But from month A to month B, use a different time frame.

Is there a way to code that?

Any advice is much appreciated.


Trading multiple time zones is easy with the .Net Framework 3.5, as all methods are implemented to convert from one time zone to another. NinjaTrader has the local timezones of the exchange implemented via the session template. All you need to do is to apply the proper session template, for eexample if you want to trade CL with Eastern Time, then you should take the session template "NYMEX Energy". The session always starts at 6:00 PM EST, irrespectively of your local daylight savings schedule.

You can then use a TimeSpan variable as an offset to define your trading start time. First check for the start of the new trading day with "GetTradingDayFromLocal()", then add the TimeSpan accounting for the difference between your trading start time (9:00 AM) and the session start time (6:00 PM). In this case the offset to be stored in the TimeSpan would be 15 hours.

A note on segmented session templates: There is a known NinjaTrader bug, which will hit you, if you use a session template, which divides the day into several subsessions. NinjaTrader tends to confuses the session break (between night and day session) and the break of the trading day. This also applies to stop and limit orders with the setting DAY. As some brokers do not accept the setting GTC, I have coded strategies with the setting DAY, and NinjaTrader will cancel all stop orders at the session break between night and RTH session, taking this for the day break. Therefore I do not recommend to use segmented session templates for use with a strategy, but rather suggest to stay with a single session template and define the start time of your session via a TimeSpan offset relative to the start of the trading day.

Below is a sample code to determine the trading start time. It takes into account how to find the correct session date, as this is not necessarily identical with your local date.

 
Code
// catch the current session end of the instrument you trade
DateTime sessionStartTimeLocal;
DateTime sessionEndTimeLocal;
Bars.Session.GetNextBeginEnd(Bars,0, out sessionStartTimeLocal, out sessionEndTimeLocal);
// to catch the correct trading date, convert the session end time to exchange time and extract the date
DateTime instrumentSessionDate = 
    TimeZoneInfo.ConvertTime(sessionEndTimeLocal, TimeZoneInfo.Local, Bars.Session.TimeZoneInfo).Date;
// enter your trading start time in exchange time, for example 9:00 AM
TimeSpan tradeStartTime = new TimeSpan (9,0,0);
// add that start time to the instrument session date
DateTime tradeStartTime = instrumentSessionDate.Add(tradeStartTime);
// convert the tradeStartTime to local time
DateTime tradeStartTimeLocal = 
    TimeZoneInfo.Convert(tradeStartTime, Bars.Session.TimeZoneInfo, TimeZoneInfo.Local);
// you have now obtained your tradeStartTime in local time

I have used a similar approach for the Opening Range indicator.

Reply With Quote
Thanked by:




Last Updated on May 17, 2012


© 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