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 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.
          BertrandNinjaTrader Customer Service

          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 geddyisodin, Today, 05:20 AM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by Max238, Today, 01:28 AM
              3 responses
              32 views
              0 likes
              Last Post Max238
              by Max238
               
              Started by timko, Today, 06:45 AM
              2 responses
              13 views
              0 likes
              Last Post NinjaTrader_ChristopherJ  
              Started by habeebft, Today, 07:27 AM
              0 responses
              6 views
              0 likes
              Last Post habeebft  
              Started by Tim-c, Today, 03:54 AM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Working...
              X