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

Exception on OnBarUpdate for DataSeries

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

    Exception on OnBarUpdate for DataSeries

    Hi,

    I know this has been covered before, but I can't find a thread that has this covered for my situation. Sorry if this should be something really basic.

    I am working on an indicator, which uses several DataSeries objects.

    I have declared it as private. eg:

    Code:
            #region Variables
    			private DataSeries probUp;
    	#endregion
    I am initializing in Initialize():

    Code:
            protected override void Initialize()
            {
    			probUp = new DataSeries(this);
            }
    And using in OnBarUpdate()

    Code:
            protected override void OnBarUpdate()
            {
    				probUp[0] = 0;
            }
    But for some frustrating reason, I am getting a null reference exception relating to this last statement (actually using the probUp field). I have stared at the code for an hour or two, and can't figure it out. It seems to be fine with my similar IntSeries fields. What am I missing?

    I have tried using properties, not using properties, etc. It seems like it is not being initialized in the Initialize() method... Which is counter-intuitive, since it's right there!

    Thanks!

    #2
    What happens when you use

    probUp.set (0)

    ?

    See the help for dataseries. .And it also takes you to a sample file example.

    Comment


      #3
      I have the same problem--the reference was the first thing I looked at.

      Comment


        #4
        I am looking a little more closely in VS debugger, and I see the indicator reference is set to null for my DataSeries fields, but not for my IntSeries fields... Not sure, but maybe there is some problem with the initialization line...

        Comment


          #5
          Tracing more, it's some problem with the value getting wiped out through my accessors between initialize and OnBarUpdate.

          Anything stand out immediately?

          Code:
                  public DataSeries ProbUp
                  {
                      get { return probUp; }
                      set { probUp = value; }
                  }
          Edit: Seems to be something to do with the internals of how NS is using DataSeries.

          For some reason, the set accessor is being called automatically somewhere between Initialize and OnBarUpdate, but the call stack just says external code. If I set the field as public and drop the accessors, I don't see the exception anymore for this field.

          Hopefully with this info someone can point me in the right direction--I'd rather keep it abstracted as much as possible, though it probably doesn't actually matter at all for this.
          Last edited by Lavafang; 11-26-2014, 10:34 PM.

          Comment


            #6
            Lavafang, if you want to setup a series and expose this non plot associated series then for external script access (through a public property) then we would suggest following this example closely - http://www.ninjatrader.com/support/f...ead.php?t=4991

            The documented .Set for pushing a value in would be preferred.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Will do. Thanks.

              First glance looks like it's the same as what I have, except without the public set accessor method.

              Cheers.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Waxavi, Today, 02:10 AM
              1 response
              17 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by Kaledus, Today, 01:29 PM
              5 responses
              13 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by Waxavi, Today, 02:00 AM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by alifarahani, Today, 09:40 AM
              5 responses
              23 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by gentlebenthebear, Today, 01:30 AM
              3 responses
              17 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X