Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get Bar duration

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

  • BrianARice
    replied
    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.

    Leave a comment:


  • koganam
    replied
    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.

    Leave a comment:


  • BrianARice
    replied
    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.

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    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.

    Leave a comment:


  • BrianARice
    replied
    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.

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    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.

    Leave a comment:


  • BrianARice
    started a topic How to get Bar duration

    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.

Latest Posts

Collapse

Topics Statistics Last Post
Started by TomTownsend, Yesterday, 10:12 PM
1 response
13 views
0 likes
Last Post NinjaTrader_Jason  
Started by rdeste911, Today, 02:04 AM
0 responses
5 views
0 likes
Last Post rdeste911  
Started by aligator, Yesterday, 04:32 PM
1 response
26 views
0 likes
Last Post NinjaTrader_Jason  
Started by zacharydw00, Yesterday, 05:14 PM
0 responses
12 views
0 likes
Last Post zacharydw00  
Started by shahabjet1, Yesterday, 04:47 PM
0 responses
24 views
0 likes
Last Post shahabjet1  
Working...
X