![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Nov 2005
Location: , Ontario, Canada
Posts: 400
Thanks: 0
Thanked 0 times in 0 posts
|
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 ); |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
|
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" );
}
|
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Nov 2005
Location: , Ontario, Canada
Posts: 400
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Correct. The code KBJ posted is a method you can use.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Nov 2005
Location: , Ontario, Canada
Posts: 400
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#7 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Nov 2005
Location: , Ontario, Canada
Posts: 400
Thanks: 0
Thanked 0 times in 0 posts
|
thanks all !
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |