Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Converting timestamp to bar number ?

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

    Converting timestamp to bar number ?

    hi,

    is it is possible to convert a timestamp to its nearest barnumber on the chart ?

    thanks in advance

    #2
    Hello buylosellhi,

    You can work with GetBar() to return the # of bars ago that the specified date / time occurred.


    If you want to caputure the CurrentBar index at a specified date / time, you could use something like this:

    #region Variables
    private DateTime myDateTime;
    private int myCurrentBar;
    #endregion

    OnBarUpdate()
    if (Time[0] == myDateTime)
    myCurrentBar = CurrentBar;
    Last edited by NinjaTrader_RyanM1; 04-29-2011, 11:24 AM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan, thanks for your reply. does GetBar() look for an exact match to timestamp or does it return the nearest bar if an exact match is not found

      Comment


        #4
        It doesn't require an exact match. It will look for the closest.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          great, thats exactly what i was looking for.
          thanks for your reply.

          Comment


            #6
            GetBar help

            I've read this thread and want to make sure I am understanding---

            Lets assume I am wanting to mark on a 10 second chart where a hypothetical trade was entered (I am reading these hypothetical trades from a file)--and the trade is timestamped:

            entry time: 5/19/2011 8:00:19 AM

            assume my bars on a 10 second chart have the following times:

            Bar 100: 8:00:10 AM

            and

            Bar 101: 8:00:20 AM

            and

            Bar 102: 8:00:30 AM

            which (if any) bar # would it return?
            Jim-Boulder
            NinjaTrader Ecosystem Vendor - Elephant Tracks

            Comment


              #7
              Hi Jim,

              In this example, I would expect that GetBar() identifies bar 101 as the bar index. It's the first one (from left to right) that's newer than the time you're checking for.

              Returns the bar index of the 1st bar from oldest to newest that matches the time stamp based on the DateTime parameter passed in. If the time stamp passed in is older than the 1st bar, a bar index of 0 is returned. If the time stamp is newer than the last bar, the last bar index is returned.
              Ryan M.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              576 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              334 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              553 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              551 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X