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

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 MGHORBEL, Today, 06:25 AM
              0 responses
              8 views
              0 likes
              Last Post MGHORBEL  
              Started by knowmad, Yesterday, 03:52 AM
              4 responses
              44 views
              0 likes
              Last Post knowmad
              by knowmad
               
              Started by Bogdan097, Yesterday, 03:25 PM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by MSerag, 05-06-2024, 11:52 PM
              5 responses
              30 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by Aviram Y, Today, 06:03 AM
              0 responses
              5 views
              0 likes
              Last Post Aviram Y  
              Working...
              X