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.
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?
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.