Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Range Bar Duration

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

    Range Bar Duration

    I'm a new user, and I need to get the duration of a range bar in seconds, or even better in microseconds. I believe that I will probably need to use a TimeSpan class, but have not been able to figure out how to code it.

    What I need is duration(time of close of current bar - time of close of bar [1])

    Thanks.

    #2
    Search the forums for bar timer.



    Originally posted by ninjaGeorge View Post
    I'm a new user, and I need to get the duration of a range bar in seconds, or even better in microseconds. I believe that I will probably need to use a TimeSpan class, but have not been able to figure out how to code it.

    What I need is duration(time of close of current bar - time of close of bar [1])

    Thanks.

    Comment


      #3
      Hello ninjaGeorge,

      Because you are only wanting the close time of each bar, this would be simple to find.

      To do this use the Time data series. For example:

      barTime = ToTime(Time[0]) - ToTime(Time[1]);


      Below is a link to the help guide on the Time data series.
      http://www.ninjatrader.com/support/h...s/nt7/time.htm
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_ChelseaB View Post
        Hello ninjaGeorge,

        Because you are only wanting the close time of each bar, this would be simple to find.

        To do this use the Time data series. For example:

        barTime = ToTime(Time[0]) - ToTime(Time[1]);


        Below is a link to the help guide on the Time data series.
        http://www.ninjatrader.com/support/h...s/nt7/time.htm
        This solution will not work for the first bar of the session as it will exaggerate the bar duration after a break. Below is a code snippet, which gets you the barDuration (here a DataSeries object is used to collect the value for each bar) in seconds.

        Code:
        if (CurrentBar < 1)
              return;
        Bars.Session.GetNextBeginEnd(Bars, 0, out sessionBegin, out sessionEnd);
              if (FirstTickOfBar)
              {
                  if (sessionBegin >= Time[1])
                       barStartTime = sessionBegin;
                  else
                       barStartTime = Time[1];
              }
              barDuration.Set((Time[0] - barStartTime).TotalSeconds);
        The NinjaTrader tick file format does not have microseconds granularity, so I would not try to have this calculated in microseconds. The result would change when you refresh via F5.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        574 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        332 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