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 RookieTrader, Today, 09:37 AM
          3 responses
          15 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by kulwinder73, Today, 10:31 AM
          0 responses
          5 views
          0 likes
          Last Post kulwinder73  
          Started by terofs, Yesterday, 04:18 PM
          1 response
          23 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by CommonWhale, Today, 09:55 AM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by Gerik, Today, 09:40 AM
          2 responses
          7 views
          0 likes
          Last Post Gerik
          by Gerik
           
          Working...
          X