• 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

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,
    http://ninjatrader.com/support/helpG...rofsession.htm

    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 psquare, Today, 03:11 PM
              4 responses
              14 views
              0 likes
              Last Post psquare
              by psquare
               
              Started by ballboy11, Today, 03:20 PM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by tonynt, Today, 02:18 PM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_JoshG  
              Started by denalek2419, Today, 01:46 PM
              3 responses
              12 views
              0 likes
              Last Post NinjaTrader_ChristopherJ  
              Started by REI140205, Today, 12:58 PM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_Jim  
              Working...
              X