View Full Version : Controlling the start time of bars for data series added
01-17-2012, 08:46 PM
I want to know how to control the start times of bars NT trader uses as this can have very large impacts to do with opening and closing times of markets.
My specific question relates to a strategy. Let's say in the init function we have added several data series to the strategy, for example:
Let's also say, imported data into NT is one minute data, and imported correctly with reference timezone -5 (eastern USA).
When the strategy runs, in particular the OnBarUpdate() function, I check for which bar in particular is calling the function, eg:
if (BarsInProgress == 2) // run this for our **** minute timeframe only
// stuff to run for 3rd dataseries...
What I need to be sure of, or force NT to do somehow, is to define what the default start time of bars should be. For example, let's say for the 240 minute bars I wanted to have them starting at 0200, 0600, 1000, 1400, 1800, 2200 each day,
such that when I call the open of bar each day, I would be getting the price at 0200, and the close would be the price just before the next open (say around 0559)
This is very important for the intraday timeframe bars.
thanks in advance
01-18-2012, 06:21 AM
PolarBear, NT would generally stamp the bars witht the closing time - what times are used is controlled by the session template applied to your charts / series. You can edit / create templates with custom times as needed yourself under Tools > Session Manager.
01-18-2012, 02:52 PM
Hi thanks for the Reply. can you please clarify which close you are referring to? I'm using1 minute data, and talking about 240 bars that I create in the strategy as mentioned below
01-18-2012, 03:26 PM
Hi Polar Bear,
The closing time Bertrand mentions is when the bars ends.
So a 240 minute bar time stamped at 12:00 PM consists of trading activity between 8:00 AM - 11:59:59.
More information on this is available here:
The starting and ending time of the series is controlled by the session template (http://www.ninjatrader.com/support/helpGuides/nt7/using_the_session_manager.htm) selected. For added series, see below the rules that determine which session template is used:
If a multi-series script adds an additional Bars object that already exists on the chart, the script will use the preexisting series instead of creating a new one to conserve memory. This includes that series' session template as applied from the chart. If the Bars object does not exist on the chart, the session template of the added Bars object will be the session template of the primary Bars object. If the primary Bars object is using the "<Use instrument settings>" session template then the additional Bars objects will use the default session templates as defined for their particular instruments in the Instrument Manager.
01-18-2012, 04:21 PM
Thanks. In relation to the quote below in your post, if primary bars are 1 minute bars, and I add a 240 minute (PeriodType.Minute, 240) is that counted as the same as the primary (as it's based on 1 minute data) or as a new bar object? I suspect a new one, but can you confirm.
Also, I know what closing time means, I was referring to how you control it, which you have tried to explain. I don't quite understand though, because from the definition given, it seems that the newly created 240 minute bar object will "be the session template of the primary Bars object.".
What does this mean?? the open and close of 1 minute data will be every minute, how does this let me control when the open and close of the 240 minute bar will be.
From the session manager and related help, from what I can see it seems to just be controlling the start / end time each day. How does this then effect the 240 minute bar I'm creating?
Perhaps can you reply with a specific solution for the 240 minute case, rather than copy and paste from the manual which I have tried to understand but it is still unclear.
01-19-2012, 04:06 AM
It would be then using the same hours as the primary series, as it's the same instrument for your chart / script.
The session template used will define what time range of data is generally available on an intraday chart in NinjaTrader.
Let's get to a more practical example to help simplify matters : you would control the start and end time of the bars by defining when your session template would enable the bars to be created for the day....
If you define Template1 starting your session at 8 AM >> the 240 min bar would close at 11:59:59
If you define Template2 starting your session at 8:30 AM >> the 240 min bar would close at 12:29:59
Hope that helps,