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-18-2007, 08:36 PM   #1
zoltran
Senior Member
 
Join Date: Nov 2005
Location: , Ontario, Canada
Posts: 400
Thanks: 0
Thanked 0 times in 0 posts
Default Testing for null

Is there a specific way to test for a null entry in a data series?
For example .. the following is standard code to color an indicator.
How would I test if 'Above0' wasn't 'Set'

Code:
				if( zz >= 0 )
					Above0.Set( zz );
				else
					Below0.Set( zz );
TIA
zoltran is offline  
Reply With Quote
Old 11-18-2007, 10:08 PM   #2
KBJ
Senior Member
 
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
Default

Check the part of the description of a DataSeries in the help where it talks about a "null" value (see: http://www.ninjatrader-support.com/H...taSeriesObject)

Also, to just test for an unassigned value, you could do this:

Code:
if (!double.IsNaN( Above0[0] ))
{
   Print( "Above0[0] is defined" );
}
KBJ is offline  
Reply With Quote
Old 11-23-2007, 06:13 AM   #3
zoltran
Senior Member
 
Join Date: Nov 2005
Location: , Ontario, Canada
Posts: 400
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks KBJ. I did read that part of the doc.

So, given what it says there .. I can test a 'Reset' or un-assigned dataseries for '0' .. and it should work?
zoltran is offline  
Reply With Quote
Old 11-23-2007, 08:06 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Correct. The code KBJ posted is a method you can use.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-25-2007, 12:50 PM   #5
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

A better approach in NT6.5 is to use the provided method "ContainsValue(int barsAgo)". It returns a true or false value.

Code:
if (Above0.ContainsValue(0) == true)
    // Do something
NinjaTrader_Ray is offline  
Reply With Quote
Old 11-25-2007, 01:44 PM   #6
zoltran
Senior Member
 
Join Date: Nov 2005
Location: , Ontario, Canada
Posts: 400
Thanks: 0
Thanked 0 times in 0 posts
Default

Arg I am being particularly thick sculled.... So .. let me see if I understand now.

Assuming Above0[0] was never set....

1- Above0.ContainsValue(0) will return false ? Because it was never set

2 if (double.IsNaN( Above0[0] )) will return true .. as it is a 'Nan' at this point (unset). (removed the !not from KGB's example)

3 if (Above0[0] == 0) will return false ..as it's not really '0' stored.. and can't be tested with the == operator.


Part of my confusion comes from the discussion on Reset in the help.
To me, this is saying i can test for 0 if I use Reset() 1st.

Calling the Reset() method is unique and can be very powerful for custom indicator development. DataSeries objects can hold null values which simply means that you do not want to store a value for the current bar. Mathematically, you can correctly assign a value of zero however if the DataSeries was the primary DataSeries of an indicator whose values would be used for plotting, you may NOT want a zero value plotted. Meaning, you want a zero value for proper calculations but not a zero value for chart visualization. The Reset() method allows you to reset the current bar's DataSeries value to a zero for calculation purposes but NinjaScript would ignore this value when it plotted it on a chart.
zoltran is offline  
Reply With Quote
Old 11-25-2007, 04:57 PM   #7
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

1- Above0.ContainsValue(0) will return false ? Because it was never set
If you used Reset() I believe it will return true.

2 if (double.IsNaN( Above0[0] )) will return true .. as it is a 'Nan' at this point (unset). (removed the !not from KGB's example)
It will evaluate to true.

3 if (Above0[0] == 0) will return false ..as it's not really '0' stored.. and can't be tested with the == operator.
It will evaluate as false.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-25-2007, 05:09 PM   #8
zoltran
Senior Member
 
Join Date: Nov 2005
Location: , Ontario, Canada
Posts: 400
Thanks: 0
Thanked 0 times in 0 posts
Default

thanks all !
zoltran 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
Determining if an indicator value is null newguy Indicator Development 4 10-16-2007 04:16 PM
Testing for a color Mike Winfrey Indicator Development 6 09-19-2007 05:08 AM
Testing and Playback guy Indicator Development 2 03-18-2006 01:44 AM
End-to-End Testing of a System aspTrader Automated Trading 0 12-02-2005 02:28 AM
Re Back testing John_Aus Miscellaneous Support 6 03-15-2005 01:54 AM


All times are GMT -6. The time now is 02:19 PM.