• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 Gunter, Today, 12:18 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by aslane, Today, 02:27 PM
        0 responses
        4 views
        0 likes
        Last Post aslane
        by aslane
         
        Started by dadarara, Yesterday, 06:38 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by jvanelli, Today, 01:19 PM
        1 response
        2 views
        0 likes
        Last Post jvanelli  
        Started by TrendFollowingCapital, Today, 05:45 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X