Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 Aviram Y, Today, 05:29 AM
                0 responses
                2 views
                0 likes
                Last Post Aviram Y  
                Started by quantismo, 04-17-2024, 05:13 PM
                3 responses
                27 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by ScottWalsh, 04-16-2024, 04:29 PM
                7 responses
                34 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by cls71, Today, 04:45 AM
                0 responses
                6 views
                0 likes
                Last Post cls71
                by cls71
                 
                Started by mjairg, 07-20-2023, 11:57 PM
                3 responses
                218 views
                1 like
                Last Post PaulMohn  
                Working...
                X