NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 06-28-2012, 10:39 AM   #1
onnb1
Member
 
Join Date: Sep 2011
Posts: 79
Thanks: 40
Thanked 2 times in 2 posts
Default Bars.GetDayBar - how to know I have enough data

hi, I am using the GetDayBar method. When the study loads, as the bars are being calculated, I get an "On Bar Update Error". I am guessing it is because I am referencing the Close values where GetDayBar is not returning an object because there is no 1 data one day back.

this is my code:
Code:
double previousDayClose = Bars.GetDayBar(1).Close;
How do I know that I have data to access the previous day bar? Can someone please share some code?

thanks,
Onn
onnb1 is offline  
Reply With Quote
Old 06-28-2012, 11:11 AM   #2
NinjaTrader_JC
NinjaTrader Customer Service
 
NinjaTrader_JC's Avatar
 
Join Date: Mar 2012
Location: Denver, CO
Posts: 1,183
Thanks: 130
Thanked 180 times in 179 posts
Default

Hello onnb1,
Correct, this error is because in OnBarUpdate() is trying to access the data series that does not have enough data to calculate. More information about making sure you have enough data can be found at the following link.
http://www.ninjatrader.com/support/f...ead.php?t=3170

This can be fixed by adding in a check to make sure we have enough data for the calculations in "OnBarUpdate()". Example:

Code:
protected override void OnBarUpdate()
{
	//Checks to make sure that there is a value for GetDayBar(1) before calculating
if (Bars.GetDayBar(1) != null)
{
	double previousDayClose = Bars.GetDayBar(1).Close;
}
}
Here is a link to our help guide that goes over GetDayBar() that you may read.
http://www.ninjatrader.com/support/h...?getdaybar.htm


Please let me know if I can be of further assistance.
NinjaTrader_JC is offline  
Reply With Quote
The following user says thank you to NinjaTrader_JC for this post:
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
GetDayBar - whats wrong nt2010 General Programming 31 05-30-2012 04:33 PM
GETDAYBAR and MAX Kentoes General Programming 9 05-05-2012 06:48 PM
Bars.GetDayBar on Multi Time Frame AntiMatter General Programming 6 04-23-2012 07:38 AM
Bars.GetDayBar(1).Close for multi-instrument adam081527 General Programming 5 02-24-2012 10:14 AM
Bars.GetDayBar(1).Time returning null drolles General Programming 9 01-18-2011 02:42 AM


All times are GMT -6. The time now is 05:32 AM.