Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AddDataSeries error

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

    AddDataSeries error

    I am having issues when running optimizations (back-tests work fine) with the following in the State.Configure section:

    Code:
     AddDataSeries(Instrument.FullName, new BarsPeriod() { BarsPeriodType = BarsPeriodType.Minute, Value = 1 }, Instrument.MasterInstrument.TradingHours.Name);
    I receive the old "Object reference not set to an instance of an object." error associated with the Instrument object.

    I am running the optimization on the ES contract.
    Last edited by GrumpyTrader; 02-07-2016, 12:56 PM.

    #2
    Hello GrumpyTrader,

    Instrument data such as Instrument.FullName and BarsPeriod would not be available in State.Configure and would return null when optimizing. If you wanted to dynamically add another bar series based on the bar type and value of the primary series, you could not do so in NinjaTrader 8.

    The error is being caused by calling Instrument.FullName.

    This means that you will need to create an instrument string input, or enum, or someway of allowing the user to select the secondary instrument.

    Also, it will not work to dynamically change a secondary series when optimizing as all data will be loaded before the optimizations will take place. (Meaning NT8 would not be able to dynamically change a secondary series on different optimization iterations)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the explanation Chelsea. I was afraid that was the case.

      I'm afraid this is going to cause issues with writing strategies that need to add a higher resolution data series for executions when using a different TradingHours template as the AddDataSeries method requires you to input the string symbol.

      It makes it so you can't dynamically apply the strategy to different securities. I'm not sure why though the BarPeriod is defined (and can be reference) but the instrument isn't as they both are defined at the same time in the GUI.

      It seems logical to me that there should be some way around this.

      Comment


        #4
        Hi GrumpyTrader,

        NinjaTrader_Dave has added a feature request to provide a new overload for AddDataSeries() that does not take an instrument name, and does take a trading hours template. This would allow for that secondary series without needing to use the Instrument.FullName.

        This request is being tracked with ID# SFT-1150.

        I've added your vote toward this.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Would be good if AddDataSeries could work in State.Historical, so that it WOULD have access to Instrument.FullName, and could be in code that runs only one time in OnBarUpdate, subject to the ADDed BarsArray object being null. This idea of making the Add method "dynamic" had been mentioned re NT7.

          Would also be good if putting Instrument.FullName into the Configure method would trigger a compile error. I had indeed been putting it there with no definite indication that it was causing problems, although I suspected them.. Just removed last remaining use of Instrument.FullName from a Configure method but still getting the following mystery error:

          Would it be AddDataSeries that is throwing the mystery error: Default, Failed to call 'Add" method. Object Reference not set to an instance of an object; an error which I have been seeing every day?
          Last edited by Ricam; 02-12-2016, 07:50 AM.

          Comment


            #6
            Hello Ricam,

            I will submit a feature request to allow AddDataSeries() to work after the State.DataLoaded state. (Just a heads up, adding dataseries causes data to be loaded for those data series)

            Would this be done instead of allowing a trading template to be submitted with AddDataSeries() without an Instrument.FullName as was requested with SFT-1150?


            It would not be possible to cause code that is able to compile to trigger a compile error with any C# project.

            The error is a runtime error and is not a compilation issue. The class itself is available to the script but is not set to a value until the data is loaded.

            Would you like to submit a feature request to create a runtime error that would appear in the log tab if the Instrument.FullName is called before State.DataLoaded?

            Also, with your script I am not able to see the code and I would not be able to advise why you are getting an error.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I like Ricam's suggestion of being able to call the AddDataSeries method in DataLoaded state. The only issue I see is how do you declare custom Series<> objects for these added dataseries since they are suppose to be instantiated in the Configure state which comes before the DataLoaded state?

              Comment


                #8
                Originally posted by GrumpyTrader View Post
                I like Ricam's suggestion of being able to call the AddDataSeries method in DataLoaded state. The only issue I see is how do you declare custom Series<> objects for these added dataseries since they are suppose to be instantiated in the Configure state which comes before the DataLoaded state?
                I have been instantiating dataseries and series objects in OnStartUp and in one run only code in OnBarUpdate in NT7 and NT8, seems to work fine. Check that the instance is null so you don't instantiate it more than once.;

                The only things that MUST be in Initialize or Configure are Add and AddDataSeries.

                Comment


                  #9
                  Then that sounds like a better idea than the additional overload to AddDataSeries. Though I don't see why they can't do both. It is literally 3 lines of code to write the new overload.

                  Comment


                    #10
                    Hello GrumpyTrader,

                    Adding the overloads would be a simple fix and is a feature request being tracked with ID #SFT-1150.

                    However, allowing data series to be added after the data is loaded would likely require redesigning how scripts work. As I mentioned, AddDataSeries currently must be called in State.Configure because calling this causes data to be loaded. Calling this after the data is loaded would fail to load the data. Thus an entire redesign of how NinjaScripts work with data would be required.

                    I have submitted a feature request for this redesign, however, I have not yet received a tracking ID for this from our development. I will update this thread once I have this ID.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Please add my vote for at least the overloads

                      Comment


                        #12
                        Hi photog53,

                        I have added your vote towards SFT-1150.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Caveat re instantiation in OnBarUpdate

                          Originally posted by Ricam View Post
                          I have been instantiating dataseries and series objects in OnStartUp and in one run only code in OnBarUpdate in NT7 and NT8, seems to work fine. Check that the instance is null so you don't instantiate it more than once.;

                          The only things that MUST be in Initialize or Configure are Add and AddDataSeries.
                          When creating an instance of an indicator in OnBarUpdate, especially if the indicator uses a bars series other than that of the chart, you might get a runtime error that the hosting indicator needs to load data before the hosted indicator, so be careful doing this.

                          Would it be possible to load just the name and period info, NOT the bar values, for the primary bars series before entering the Configure state? If so maybe this could be looked at as part of SFT-1150. That would directly solve the issue that prompted this thread.
                          Last edited by Ricam; 02-12-2016, 08:24 PM.

                          Comment


                            #14
                            That is an interesting idea. I've expanded the tracked suggestion to note this use case.
                            Dave I.NinjaTrader Product Management

                            Comment


                              #15
                              Hi Chelsea,
                              I was thinking about this issue and was wondering where the AddDataSeries methods that don't accept a symbol name get their symbol name from if the Instrument isn't available at the Configure state? It must come from somewhere?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post tkaboris  
                              Started by GussJ, 03-04-2020, 03:11 PM
                              16 responses
                              3,281 views
                              0 likes
                              Last Post Leafcutter  
                              Started by WHICKED, Today, 12:45 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Started by Tim-c, Today, 02:10 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Taddypole, Today, 02:47 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post Taddypole  
                              Working...
                              X