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 cmoran13, 04-16-2026, 01:02 PM
              0 responses
              43 views
              0 likes
              Last Post cmoran13  
              Started by PaulMohn, 04-10-2026, 11:11 AM
              0 responses
              25 views
              0 likes
              Last Post PaulMohn  
              Started by CarlTrading, 03-31-2026, 09:41 PM
              1 response
              162 views
              1 like
              Last Post NinjaTrader_ChelseaB  
              Started by CarlTrading, 04-01-2026, 02:41 AM
              0 responses
              98 views
              1 like
              Last Post CarlTrading  
              Started by CaptainJack, 03-31-2026, 11:44 PM
              0 responses
              158 views
              2 likes
              Last Post CaptainJack  
              Working...
              X