Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I return the date and Time of bars

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

    How do I return the date and Time of bars

    Hi all,

    Maybe a newbie question but I would like to return the Date and Time of different historical bars meeting specific conditions in my output window.

    Is there an easy way to code that ?



    Bernard

    #2
    Hi Bernard, NinjaTrader stores time information just like it stores high and low information. You can access Time[0] for the current bar's timestamp. Time[nBarsBack] will return a DateTime object, which may be difficult to work with. NinjaTrader comes with a functions to make working with time easier.

    Functions:
    ToTime()
    ToDay()
    Time[]

    If the current bar's time is 1:59:00 PM July 31, 2009:
    Code:
    Print(ToTime(Time[0])); // returns int value of 135900
    Print(ToDay(Time[0])); // returns int value of 20090731
    Print(Time[0].ToString()); // returns string "7/31/2009 1:59:00 PM" depending on localization settings
    AustinNinjaTrader Customer Service

    Comment


      #3
      Easy enough !

      Great

      Thank you Austin

      Comment


        #4
        is there a function to format the time value to pad with leading zeros?
        eg ToTime(Time[0]) returns 53000 for 5:30am I would prefer 053000

        Comment


          #5
          Freddo, no unfortunately not.

          Comment


            #6
            is there any date format masks at all, ie hh:mm:ss hh:mm or hhmm?

            Comment


              #7
              Freddo,

              You would want to work directly with the DateTime object then. Unfortunately this is outside the scope of what we can cover, but there is a lot of documentation on this over on MSDN and on Google.
              Josh P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              581 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              338 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              554 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              552 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X