NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 11-16-2010, 03:45 AM   #1
AnotherTrader
Senior Member
 
Join Date: Aug 2009
Posts: 266
Thanks: 41
Thanked 8 times in 8 posts
Send a message via ICQ to AnotherTrader
Default null bars

I am programming (for NT 6.5) a 1-min bar NinjaScript strategy for an instrument that is quite likely to have less than 1 tick per minute during the time period of interest.

Say that in a 10-minute period there a three 1-min periods in which no tick occurs.

In relation to the above situation, if I reference Close[10] in my code will this refer to the close of the bar approx 10 minutes ago, or to the close of the bar approx 13 minutes ago (as there were three 1-min bars that had no OHLC, since no ticks occurred during the minute)?
AnotherTrader is offline  
Reply With Quote
Old 11-16-2010, 04:34 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 977 times in 960 posts
Default

AnotherTrader, NinjaTrader is event not time based, as such if there's no bar there's no Close price for you to 'grab' at that point - it would give you the close price of the bar 13 mins ago then.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 11-17-2010, 11:38 AM   #3
AnotherTrader
Senior Member
 
Join Date: Aug 2009
Posts: 266
Thanks: 41
Thanked 8 times in 8 posts
Send a message via ICQ to AnotherTrader
Default

OK, thanks.
So, when needing to know how many bars ago correspond with a particular point in time (e.g. say it’s now 13h00 EST, and I want know which bar corresponds to the bar which closed at 12h00 EST), it is not enough to make use of say Close[59] for the closing price of that bar; I guess I’ll need to do something like start a counter at 12h00 EST that updates on each OnBarUpdate, and then use Close[counter] for the bar that closed at 12h00 EST.
Is that what you would recommend?
AnotherTrader is offline  
Reply With Quote
Old 11-17-2010, 11:43 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 977 times in 960 posts
Default

You can use the GetBar() method for this task -

http://www.ninjatrader-support.com/H...V6/GetBar.html
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 11-17-2010, 11:48 AM   #5
AnotherTrader
Senior Member
 
Join Date: Aug 2009
Posts: 266
Thanks: 41
Thanked 8 times in 8 posts
Send a message via ICQ to AnotherTrader
Default

OK, thanks.

If the timestamp specifies a time after the first bar and before the last bar, but refers to a time at which no bar exists (for the reason previous, i.e. there were no ticks during that timeframe) what does GetBar() return?
AnotherTrader is offline  
Reply With Quote
Old 11-17-2010, 12:00 PM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 977 times in 960 posts
Default

It would then return the next bar satisfying it - for example I try getting todays 9:02 bar which would not exist in cash session on ES running on EST - so GetBar() returns then the 9:35 bar (on 5 min chart).
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 05-10-2011, 11:13 AM   #7
AnotherTrader
Senior Member
 
Join Date: Aug 2009
Posts: 266
Thanks: 41
Thanked 8 times in 8 posts
Send a message via ICQ to AnotherTrader
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
You can use the GetBar() method for this task -

http://www.ninjatrader-support.com/H...V6/GetBar.html

The above link references the following example:
Code:
 
// Check that its past 9:45 AM 
if (ToTime(Time[0]) >= ToTime(9, 45, 00)) 
{ 
// Calculate the bars ago value for the 9 AM bar for the current day 
int barsAgo = GetBar(new DateTime(2006, 12, 18, 9, 0, 0)); 

// Print out the 9 AM bar closing price 
Print("The close price on the 9 AM bar was: " + Close[barsAgo].ToString());
I need to modify the above to calculate the bars ago value of the prior day's 9AM bar, and to do this on a rolling basis. How would I modify the above?

Thanks.
AnotherTrader is offline  
Reply With Quote
Old 05-10-2011, 11:31 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 977 times in 960 posts
Default

You would for example use DateTime.Today.AddDays(-1) for yesterdays date, but you would need to introduce custom logic to cover weekends here.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 05-10-2011, 12:03 PM   #9
AnotherTrader
Senior Member
 
Join Date: Aug 2009
Posts: 266
Thanks: 41
Thanked 8 times in 8 posts
Send a message via ICQ to AnotherTrader
Default

How is DateTime.Today.AddDays(-1) inserted into the following in the simplest case (ie ignoring weekends and holidays)?

Code:
 
// Check that its past 9:45 AM 
if (ToTime(Time[0]) >= ToTime(9, 45, 00)) 
{ 
// Calculate the bars ago value for the 9 AM bar for the current day 
int barsAgo = GetBar(new DateTime(2006, 12, 18, 9, 0, 0)); 
 
// Print out the 9 AM bar closing price 
Print("The close price on the 9 AM bar was: " + Close[barsAgo].ToString());
AnotherTrader is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bars.GetDayBar(1).Time returning null drolles General Programming 9 01-18-2011 02:42 AM
Plots and Null Value TAJTrades General Programming 2 05-12-2009 05:28 AM
Bars == NULL oferr Strategy Analyzer 4 01-31-2008 07:57 AM
Testing for null zoltran General Programming 7 11-25-2007 05:09 PM
Determining if an indicator value is null newguy Indicator Development 4 10-16-2007 04:16 PM


All times are GMT -6. The time now is 12:32 PM.