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

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 algospoke, Yesterday, 06:40 PM
        2 responses
        19 views
        0 likes
        Last Post algospoke  
        Started by ghoul, Today, 06:02 PM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        45 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        20 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        180 views
        0 likes
        Last Post jeronymite  
        Working...
        X