Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to find the bars Opening time?

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

    How to find the bars Opening time?

    Time[0] gives the closing time of the bar. How to find out the time when this bar appeared on the chart (time of its opening)?

    By analogy with the MQL: iTime (_Symbol, _Period, 0) gives the opening time of the current bar. Is there anything similar in the NS?

    #2
    Hello webus,

    Thanks for your post and welcome to the NinjaTrader Forums!

    Ninjatrader does timestamp the end of the bar, other platforms timestamp the beginning of the bar.

    The beginning of the bar would be relatively the same time as the end of the previous bar. So the start time of the current bar would be equal to Time[0] - (Time[0] - Time[1]). Here is a print statement you could use to see this: Print ("Bar Start time: "+(Time[0] -(Time[0] - Time[1])).ToString()+ " Bar End time: "+Time[0]);

    A more precise way, on real time data, would be to add a 1 tick series and use Bars.IsFirstTickOfBar on the primary series and collect the time from the tick series bar.
    Reference: https://ninjatrader.com/support/help...ttickofbar.htm

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello webus,

      The beginning of the bar would be relatively the same time as the end of the previous bar. So the start time of the current bar would be equal to Time[0] - (Time[0] - Time[1]). Here is a print statement you could use to see this: Print ("Bar Start time: "+(Time[0] -(Time[0] - Time[1])).ToString()+ " Bar End time: "+Time[0]);
      Hi PaulH.
      I think I can not agree with you.
      For example, chart Minute 1. The trading week closed on Friday at 23:59 (closing time of the last bar). A new week began on Monday at 00:00 (00:01 the closing time of the first bar).
      According to your formula, the opening time of the first bar on Monday is Friday 23:59. This is not true and not what I need.
      I want to get 00:00 Monday in this case.


      Comment


        #4
        Hello webus,

        Thanks for your reply.

        If you are using time based bars (I was assuming you were not using time based bars), then (in the case of 1 minute bars) you can subtract 1 minute from the bars time stamp. Print ("Start time of bar: "+Time[0].AddMinutes(-1)+" End of Bar: "+Time[0]);

        Comment


          #5
          Originally posted by NinjaTrader_PaulH View Post
          Hello webus,

          Thanks for your reply.

          If you are using time based bars (I was assuming you were not using time based bars), then (in the case of 1 minute bars) you can subtract 1 minute from the bars time stamp. Print ("Start time of bar: "+Time[0].AddMinutes(-1)+" End of Bar: "+Time[0]);
          Hi PaulH.

          Thanks for the answer. At the moment I am using the same method. I thought that there is some more universal method (something like a dataseries).

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          89 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          48 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          31 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          34 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          69 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X