Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Time Zones - remote server question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Time Zones - remote server question

    I'm developing a strategy that is only intended to be used during CME open market hours. In Denver (Mountain Time Zone), that falls between 7:30 am and 2:15 pm. However, I'd like to deploy this strategy on a virtual remote server which is located in Chicago. Chicago, of course, is in the Central Time Zone, where the market's open from 8:30 am to 3:15 pm.

    So my problem is: the time zones for my development machine and my deployment machine are different. Is there a programmatic way to handle time and time zones? Can you specify a time zone - say, tell your strategy "I want you to be active between 8am and 2pm, Central Standard Time" - and have NinjaTrader be aware of the time zone of the machine it's currently running on?

    Right now, I'm actually making code changes before uploading my strategy to my remote server, but that's not terribly good coding practice.

    #2
    Hello pbailey19,

    Thank you for the question I will be happy to assist.

    If you are looking to create a condition based on the time zone you could use

    Code:
    Bars.Session.TimeZoneInfo.Id
    This returns the time zone name as a string for the selected session template. You could use that in an if statement to determine what time zone and adjust the times accordingly.

    Alternatively you could get the session template information as DateTime objects. There is a great example of this located in the help guide located here: http://www.ninjatrader.com/support/h...xtbeginend.htm

    The first portion of the example will give you the start time and end time of the selected session template and you could base the times off of that.

    Code:
    private DateTime sessionBegin;
    private DateTime sessionEnd;
     
    protected override void OnBarUpdate()
    {
        if (Bars.FirstBarOfSession)
             Bars.Session.GetNextBeginEnd(BarsArray[0], 0, out sessionBegin, out sessionEnd);
     
        Print("Session Start: " + sessionBegin + " Session End: " + sessionEnd);
    }

    Here is some more documentation on both of the above examples
    http://www.ninjatrader.com/support/h...ml?session.htm

    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      So I quick edited one of my strategies to use "Bars.Session.TimeZoneInfo.Id". It prints out "Central Standard Time", even though I'm currently located in the Mountain Time Zone.

      Now, I am running the test against the ES instrument, which is traded by the CME in Chicago, so that's why (I assume) I'm seeing a value of "Central Standard Time". But what I *need* to know is the current time zone of the computer that's running NinjaTrader. In other words, I need a method that returns "Mountain Standard Time" when it's being run on a machine in Denver, and "Central Standard Time" when it's run on a machine in Chicago.

      Comment


        #4
        Hello pbailey19,

        The Bars.Session.TimeZoneInfo.Id will return the timezone of the selected session template rather than the computers current timezone.

        In NinjaScript you have access to the DateTime component of C# so you are able to access the local machines DateTime.

        You could use something like to to display the computers timezone name

        Code:
        TimeZone localZone = TimeZone.CurrentTimeZone;
        Print(localZone.StandardName);
        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by mattdowns1234, Today, 06:57 PM
        0 responses
        14 views
        0 likes
        Last Post mattdowns1234  
        Started by dgee949, Today, 06:26 PM
        0 responses
        24 views
        0 likes
        Last Post dgee949
        by dgee949
         
        Started by dgee949, Today, 05:58 PM
        0 responses
        30 views
        0 likes
        Last Post dgee949
        by dgee949
         
        Started by thepcmd, Today, 05:14 PM
        0 responses
        33 views
        0 likes
        Last Post thepcmd
        by thepcmd
         
        Started by xmess777, Today, 04:58 PM
        0 responses
        23 views
        0 likes
        Last Post xmess777  
        Working...
        X