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


    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 rocketman7, Today, 02:12 AM
        5 responses
        22 views
        0 likes
        Last Post rocketman7  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        7 responses
        28 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by samish18, 04-17-2024, 08:57 AM
        17 responses
        66 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by briansaul, Today, 05:31 AM
        1 response
        15 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by PaulMohn, Today, 03:49 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X