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).
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to get Bar duration
Collapse
X
-
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. -
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
-
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
-
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
-
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
-
Originally posted by BrianARice View PostThe 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.
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
-
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 rbeckmann05, Yesterday, 06:48 PM
|
1 response
12 views
0 likes
|
Last Post
by bltdavid
Today, 05:43 AM
|
||
Started by llanqui, Today, 03:53 AM
|
0 responses
6 views
0 likes
|
Last Post
by llanqui
Today, 03:53 AM
|
||
Started by burtoninlondon, Today, 12:38 AM
|
0 responses
10 views
0 likes
|
Last Post Today, 12:38 AM | ||
Started by AaronKoRn, Yesterday, 09:49 PM
|
0 responses
15 views
0 likes
|
Last Post
by AaronKoRn
Yesterday, 09:49 PM
|
||
Started by carnitron, Yesterday, 08:42 PM
|
0 responses
11 views
0 likes
|
Last Post
by carnitron
Yesterday, 08:42 PM
|
Comment