Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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.
Can you help answer these questions from other members on NexusFi?
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?
There are two main features
A) Session Countdown Clock - This will create a countdown clock on the toolbar for each main trading centre around the world - Sydney, Tokyo, London & NYC.
If the clock is coloured red then the session is currently …
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.
// 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.