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

How to add minutes to variable in ToTime format

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

    How to add minutes to variable in ToTime format

    Please provide a simple code example of how to add some number of minutes to the time when it is an integer in ToTime() format (hhmmss) . For example, what is the code to add 30 minutes (in integer format 003000) to the time 095000 (09:50:00) so that the result is 102000 (10:20:00) ? I'm not concerned about the date changing.

    Question - Is there a way to convert ToTime back to DateTime() format? As before the actual date is not important - just the Time.

    Thanks

    #2
    If you want to work with time at that level then I would use the DateTime structure that is returned from the Time[int barsAgo] array. ToTime() is just a method to make it easy for non-programmers to do time comparisons. Working with DateTime structures gives you complete access and flexibility.

    You could do something like:

    DateTime newTime = Time[0];
    newTime.AddMinutes(30); // Adds 30 minutes to the value of this instance

    DOC on the DateTime structure can be found here - http://msdn2.microsoft.com/en-us/lib....datetime.aspx
    RayNinjaTrader Customer Service

    Comment


      #3
      What I need is a specific time - the day session start time (0830 Central time) in DateTime format. Then I can use AddMinutes to compute a new DateTime and finally convert back to integer time with ToTime.

      How can I convert to DateTime format for today (or any day) at 0830 am such that I can add a variable number of minutes to it?

      Comment


        #4
        Please see the following documentation.



        This will give you an idea on how to create a specific instance of time.

        For example:

        DateTime newTime = new DateTime(2007, 6, 9, 8, 30, 0);
        RayNinjaTrader Customer Service

        Comment


          #5
          I'm good to go. Thanks for the prompt reply.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Aviram Y, Today, 05:29 AM
          0 responses
          2 views
          0 likes
          Last Post Aviram Y  
          Started by quantismo, 04-17-2024, 05:13 PM
          3 responses
          25 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by ScottWalsh, 04-16-2024, 04:29 PM
          7 responses
          34 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by cls71, Today, 04:45 AM
          0 responses
          6 views
          0 likes
          Last Post cls71
          by cls71
           
          Started by mjairg, 07-20-2023, 11:57 PM
          3 responses
          217 views
          1 like
          Last Post PaulMohn  
          Working...
          X