Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Testing for null

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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

    #2
    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" );
    }

    Comment


      #3
      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?

      Comment


        #4
        Correct. The code KBJ posted is a method you can use.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          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
          RayNinjaTrader Customer Service

          Comment


            #6
            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.

            Comment


              #7
              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 P.NinjaTrader Customer Service

              Comment


                #8
                thanks all !

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                646 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                367 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                107 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                569 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X