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

DateTime vs DateTimeOffset

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

    DateTime vs DateTimeOffset

    Hey guys, i´ve recently read that as far as Time Zone is concerned, Microsoft recognized using DateTimeOffset instead of DateTime. How is this at NT8. is it there also better to use DateTimeOffset, or is NT alway calculating on custom Time Zone?

    thanks for your respond!

    #2
    Hello sane1111,

    Thanks for your post.

    You could use DateTime in a NInjaScript strategy or indicator if you would like to get your machine's time. For example, see the sample code below.

    Code:
    Print("Current machine time: " + DateTime.Now);
    You could use Time[0] to get the current bar time stamp value. For example, see the sample code below.

    Code:
    Print("Bar time stamp: " + Time[0]);
    See this help guide page for more information about Time[ ]: https://ninjatrader.com/support/help...eries_time.htm

    See this publicly available link for more information about DateTime: https://docs.microsoft.com/en-us/dot...e?view=net-6.0

    And, see the attached example script. The example script demonstrates using the above prints.

    Let me know if I may assist further.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Brandon for your reply,

      I´m asking because of the following example.

      Code:
      DateTime dt = DateTime.UtcNow;
      Print(dt.ToString("HH:mm"));
      
      string apiReturn = dt.ToString("o");
      
      DateTime apiValue = DateTime.ParseExact(apiReturn, "o", null);
      Print(apiValue.ToString("HH:mm")); //
      Last edited by sane1111; 08-10-2022, 09:03 AM.

      Comment


        #4
        Sorry, i`ve made a mistake, because DateTime.Now works fine. But in this case DateTime does not work correctly. this is the question i have, if we also should work more with DateTimeOffset.

        thanksin advance!

        Comment


          #5
          Hello sane1111,

          Thanks for your note.

          This would fall under C# education and would go beyond the support we could provide. It would be up to you to decide whether to use DateTime or DateTimeOffset in your script.

          Ultimately, DateTime is used when referencing the machine's time and Time[0] would be used to reference a bar's timestamp.

          See this help guide page for information about creating time comparisons: https://ninjatrader.com/support/help...imeComparisons

          You could create a time comparison condition in the Strategy Builder and click the 'View code' button to see the generated syntax. Note that DateTime is used for time comparisons.

          Let me know if I may assist further.
          Brandon H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Aviram Y, Today, 06:03 AM
          2 responses
          10 views
          0 likes
          Last Post Aviram Y  
          Started by FishTrade, Today, 03:42 PM
          0 responses
          1 view
          0 likes
          Last Post FishTrade  
          Started by Richozzy38, Today, 01:06 PM
          3 responses
          14 views
          0 likes
          Last Post Richozzy38  
          Started by ttrader23, Today, 09:04 AM
          2 responses
          12 views
          0 likes
          Last Post ttrader23  
          Started by geotrades1, Today, 07:54 AM
          10 responses
          26 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X