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 CarlTrading, 05-11-2026, 05:56 AM
              0 responses
              34 views
              0 likes
              Last Post CarlTrading  
              Started by CarlTrading, 05-10-2026, 08:12 PM
              0 responses
              22 views
              0 likes
              Last Post CarlTrading  
              Started by Hwop38, 05-04-2026, 07:02 PM
              0 responses
              185 views
              0 likes
              Last Post Hwop38
              by Hwop38
               
              Started by CaptainJack, 04-24-2026, 11:07 PM
              0 responses
              344 views
              0 likes
              Last Post CaptainJack  
              Started by Mindset, 04-21-2026, 06:46 AM
              0 responses
              266 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Working...
              X