Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get Bar duration

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

    How to get Bar duration

    I'm having trouble finding the way to simply get the bar duration.

    I've seen Time[0] - Time[1]... but it seems like this would be a problem on the first bar after a break in trading (e.g. the weekend).
    Last edited by BrianARice; 08-29-2016, 10:50 AM.

    #2
    Hello BrianARice,

    Thank you for your note.

    To avoid the issue with the first bar of day, you could add the following statement above your code, which would return if the first bar of the session was the current bar.

    if (Bars.FirstBarOfSession == true) return;

    See the first bar of session section of our Helpguide,


    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      This is still not a reliable way to do this... I just ran a test on ZB 09-16 (IQFeed)... and the bar for 10:15am PST on 9/6/2016 is simply missing!

      So at 10:30am... My duration ends up being 30 minutes... instead of 15 minutes like every other bar.

      The missing bar may be a NinjaTrader 8 bug but I would imagine that bars missing from data might not be a completely uncommon thing... and if/when it does happen... completely screws up my calculation.
      Last edited by BrianARice; 09-09-2016, 04:49 PM.

      Comment


        #4
        Hello,

        I am able to replicate the missing 10:15 bar, which is the result of no trade occurring during that time, thus no plot is made. If you pull up a 1 minute chart you will see no trade took place. Lack of trading like this can occur as the contract comes into expiration.

        If you were to use the front month bond contract, ZB 12-16 you should have no issue as there is plenty of trades/data.

        Please let us know if you need further assistance.
        Last edited by NinjaTrader_AlanP; 10-03-2016, 10:49 AM.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          The point though is there should be a simple way to get the bar duration... because subtracting the current time from the previous time is simply not reliable, nor consistent.

          Comment


            #6
            Originally posted by BrianARice View Post
            The point though is there should be a simple way to get the bar duration... because subtracting the current time from the previous time is simply not reliable, nor consistent.
            That has long been documented, but must be understood for what it shows. It shows duration based on the definition of the bar type, not necessarily "time". Of course, that means that for time-based bars, it will show you the duration of the bar. It is the BarsPeriod.Value property of the bar.

            ref: http://ninjatrader.com/support/helpG...barsperiod.htm

            That means that on non-time based bars, one must calculate that duration based on the bar closing times, which is the only way to find said duration anyway, as that duration would not be a constant value in any event.

            Comment


              #7
              Great, thank you! That worked.

              Note: I did search for this and a number of forum posts had said the way to get this was to use Time[0] - Time[1]... for my needs the BarsPeriod.Value works far better.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by helpwanted, Today, 03:06 AM
              1 response
              7 views
              0 likes
              Last Post sarafuenonly123  
              Started by Brevo, Today, 01:45 AM
              0 responses
              7 views
              0 likes
              Last Post Brevo
              by Brevo
               
              Started by aussugardefender, Today, 01:07 AM
              0 responses
              5 views
              0 likes
              Last Post aussugardefender  
              Started by pvincent, 06-23-2022, 12:53 PM
              14 responses
              242 views
              0 likes
              Last Post Nyman
              by Nyman
               
              Started by TraderG23, 12-08-2023, 07:56 AM
              9 responses
              384 views
              1 like
              Last Post Gavini
              by Gavini
               
              Working...
              X