Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8 (B6) : Strategy 'OnStateChange' Object reference error

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

    #16
    Jesse, Matthew & NT Forum,

    My issue may cross over with the issue presenting for sledge (http://ninjatrader.com/support/forum...ad.php?t=80108).

    Shannon

    Comment


      #17
      Since your test indicator does not have any exposed plots/values[idx] which are being called by the strategy, there is nothing there telling it to call OnBarUpdate() historically. This does not have anything to do with the State.Configure call and I was able to simplify even further to just a test indicator and test strategy which I've uploaded which does not use your Addon class...

      You'll see the same behavior here if you try to enable this strategy-> there is nothing telling the Indicator to run historically so you never see it hit those Prints as you're expecting.

      If you edit the attached indicator and uncomment the call to .Update() from the strategy, it should work like you're expecting.

      So for your test case which had that CalcautionPeriod class, if you just did the same in the strategy and added the following

      Code:
      		protected override void OnBarUpdate()
      		{
      			_testIndicator.Update();			
      		}
      I believe that should work like you're expecting.

      ..Let me know though if you're having further issues with object reference errors from that AddOn class or the indicator call, that seems to be something entirely different which I was not able to reproduce.
      Attached Files
      MatthewNinjaTrader Product Management

      Comment


        #18
        Mathew,

        Thank you for your response.

        I will test "_testIndicator.Update();" this evening.

        In tackling this issue with my main code, I recall "indicator.Update()" resulted in the error message "a hosted indicator tried to load additional data". The indicator in question did not load additional data. While the indicator does use the syntax "_sma = SMA(period);" it is my understanding this does not load additional data.

        Please advise if my understanding is incorrect / possible other causes for this error message. Noting this may already be under investigation (http://ninjatrader.com/support/forum...ad.php?t=78858).

        Again, I will test this evening.

        Thanks again
        Shannon

        Comment


          #19
          Mathew,

          I confirm adding "_testIndicator.Update()" to the TestStrategy OnBarUpdate() resolved the issue in the simplified example.

          In my actual code, in the Strategy OnBarUpdate(), adding _indicator.Update() with nothing else also works (not that any trades are entered due to no other code being present). However, when additional code is added to reference _indicator properties the below error message is returned and the strategy is aborted (i.e. removed from the chart).
          A hosted indicator tried to load additional data. All data must first loaded by the hosting NinjaScript in its configure state.
          I note within the _indicator, the indicator CalculationPeriod is instantiated in State.DataLoaded not State.Configure due to CalculationPeriod referencing BarsPeriod.BarsPeriodType. Is this causing the issue?

          Any suggestions are welcome.
          Shannon

          Comment


            #20
            Mathew,

            As the error message states "... All data must first loaded by the hosting NinjaScript in its configure state", I have changed the TestIndicator code to:
            - Instantiate the Indicator CalculationPeriod in State.Confiture, and
            - Set the BarsPeriod values in State.DataLoaded.

            Companion CalculationPeriod code is now:
            Code:
            public CalculationPeriod(Indicator indicator)
            {
              _ind = indicator;
            }
            
            public void SetPeriod()
            {
              _barsPeriodType = _ind.BarsPeriod.BarsPeriodType;
              _barsPeriodValue = _ind.BarsPeriod.Value;
            }
            This code compiles and works in the simplified example.

            However, in my actual code, this change still fails to resolve the error message
            A hosted indicator tried to load additional data. All data must first loaded by the hosting NinjaScript in its configure state.
            If I am to understand "hosted indicator" and "additional data" correctly, anything that could pass for "additional data" occurs in State.Configure:
            Code:
            else if (State == State.Configure)
            {
              _sma = SMA(Period);
              _calculationPeriod = new CalculationPeriod(this);
              _smaCrossRepository = new SmaCrossRepository(this);
              _peakTroughRepository = new PeakTroughRepository(this, _smaCrossRepository);
            }
            else if (State == State.DataLoaded)
            {
              _calculationPeriod.SetPeriod();
            }
            Please advise if my understanding of "hosted indicator" or "additional data" is incorrect.

            Thanks again
            Shannon
            Last edited by Shansen; 11-11-2015, 01:59 PM.

            Comment


              #21
              Just to confirm, none of your scripts are calling AddDataSeries()?
              MatthewNinjaTrader Product Management

              Comment


                #22
                Confirmed. No scripts are calling AddDataSeries().

                Comment


                  #23
                  Sorry, I have not been able to reproduce with modifying the scripts you provided earlier with samples you provided earlier.

                  Would you be able to reupload everything as it is now? There may be something else I'm missing but happy to look it all over for you again.
                  MatthewNinjaTrader Product Management

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by FrancisMorro, Today, 03:24 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post FrancisMorro  
                  Started by Segwin, 05-07-2018, 02:15 PM
                  10 responses
                  1,769 views
                  0 likes
                  Last Post Leafcutter  
                  Started by Rapine Heihei, 04-23-2024, 07:51 PM
                  2 responses
                  30 views
                  0 likes
                  Last Post Max238
                  by Max238
                   
                  Started by Shansen, 08-30-2019, 10:18 PM
                  24 responses
                  943 views
                  0 likes
                  Last Post spwizard  
                  Started by Max238, Today, 01:28 AM
                  0 responses
                  10 views
                  0 likes
                  Last Post Max238
                  by Max238
                   
                  Working...
                  X