Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Object reference not set to an instance of an object.

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

    Object reference not set to an instance of an object.

    I am getting an error:
    Category: Default
    Message: Indicator '<name of indicator that is not assigned to a chart>' : Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

    This error comes up once I assign attached indicator (I have few others that do that) to two chart windows. When assigned to just one, the error does not seem to come up. Once I have it on two charts - above error will print every time scripts refresh, sometimes the chart window will stop responding requiring end-task nt8 (application is functional but will not exit).

    I am using NT8 8.1.3.0 64-bit​

    Please take a look at the attached indicator and hopefully you can help me figure out the problem or point me in the right direction. as I have coded similar indicator that has the same problem.
    Attached Files

    #2
    Hello MiCe1999,

    I wanted to clarify what you mean by assign, do you mean if you manually apply the indicator to two charts?

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello MiCe1999,

      I wanted to clarify what you mean by assign, do you mean if you manually apply the indicator to two charts?
      Yes, the error comes up when I add the indicator to the second chart window indicators, after clicking OK or Apply button.

      Comment


        #4
        Hello MiCe1999,

        I tried this on two charts but don't see an error when refreshing either chart. What are the exact steps you are using when you see the error? Can you detail everything starting from creating the two charts along with the settings used?

        If the error message is showing a different indicator than the one you attached the script you attached is likely not the problem. You would need to look at the other indicators code and its OnStateChange per the error message.

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello MiCe1999,

          I tried this on two charts but don't see an error when refreshing either chart. What are the exact steps you are using when you see the error? Can you detail everything starting from creating the two charts along with the settings used?

          If the error message is showing a different indicator than the one you attached the script you attached is likely not the problem. You would need to look at the other indicators code and its OnStateChange per the error message.
          Open Nt8
          Open chart (new->chart select instrument, etc)
          Open another chart
          Assign the indicator to the first chart
          Assign the indicator to the second chart
          Error occurs

          Note that the error has a different indicator in the description, but indicator of that name is not open anywhere (that indicator was a also a simple script, no assembly or dlls).

          Comment


            #6
            Hello MiCe1999,

            Yes in this case you need to look at the other indicators code, the problem is not with the one you attached. The indicators menu calls on all indicators you have when you open the menu, if the other indicator has a problem in its OnStateChange logic that would happen regardless of what other indicators you are using.

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Hello MiCe1999,

              Yes in this case you need to look at the other indicators code, the problem is not with the one you attached. The indicators menu calls on all indicators you have when you open the menu, if the other indicator has a problem in its OnStateChange logic that would happen regardless of what other indicators you are using.
              I see, so they are like one big program after compiling. I'm beginning to understand, on state change occurs when I add the indicator or change it's position and that's exactly when the error occurs.

              Thanks for that. I think I need to have a trading instance of NT8 and development. Can you point me to documentation how I can install two NT8 on the same computer (to be used one at a time)?

              Comment


                #8
                Hello MiCe1999,

                I see, so they are like one big program after compiling.
                Yes and no in this case, that is correct that all the scripts are compiled into a single dll but that is not related to this error. When you open the indicators menu the platform goes from top to bottom of the indicators list, creates a new instance of each indicator and calls its SetDefaults to get the defaults for the property grid. For whatever reason the code in the indicator mentioned in the error is having an error in its OnStateChange which is why you see that error happen even though its not being used. The error states something is null in that indicators OnStateChange, to address that error would require looking over the code in OnStateChange in that indicator and finding out what is null when you do those steps. Alternatively that indicator can be removed to resolve the error also.

                I have included the steps to make a secondary user folder below.

                1. Exit NinjaTrader
                2. Open the Documents folder
                3. Rename the NinjaTrader 8 folder to NinjaTrader 8 Old
                4. Download the installer from https://account.ninjatrader.com/download
                5. Install the platform, this will create a new user folder.
                6. Open the platform and import any of the items that you need

                To revert back to your previous data use the following steps.

                1. Exit NinjaTrader
                2. Open the Documents folder
                3. Rename the NinjaTrader 8 folder to NinjaTrader 8 Clean
                4. Rename the NinjaTrader 8 Old folder to NinjaTrader 8

                NinjaTrader looks for the folder named NinjaTrader 8 for your user data, once you have created the second user folder you simply have to exit and rename the folders to switch installs. ​

                Comment


                  #9
                  Originally posted by NinjaTrader_Jesse View Post
                  Hello MiCe1999,


                  Yes and no in this case, that is correct that all the scripts are compiled into a single dll but that is not related to this error. When you open the indicators menu the platform goes from top to bottom of the indicators list, creates a new instance of each indicator and calls its SetDefaults to get the defaults for the property grid. For whatever reason the code in the indicator mentioned in the error is having an error in its OnStateChange which is why you see that error happen even though its not being used. The error states something is null in that indicators OnStateChange, to address that error would require looking over the code in OnStateChange in that indicator and finding out what is null when you do those steps. Alternatively that indicator can be removed to resolve the error also.

                  I have included the steps to make a secondary user folder below.

                  1. Exit NinjaTrader
                  2. Open the Documents folder
                  3. Rename the NinjaTrader 8 folder to NinjaTrader 8 Old
                  4. Download the installer from https://account.ninjatrader.com/download
                  5. Install the platform, this will create a new user folder.
                  6. Open the platform and import any of the items that you need

                  To revert back to your previous data use the following steps.

                  1. Exit NinjaTrader
                  2. Open the Documents folder
                  3. Rename the NinjaTrader 8 folder to NinjaTrader 8 Clean
                  4. Rename the NinjaTrader 8 Old folder to NinjaTrader 8

                  NinjaTrader looks for the folder named NinjaTrader 8 for your user data, once you have created the second user folder you simply have to exit and rename the folders to switch installs. ​
                  Thanks for the instructions. Fresh install does not have the error with the same indicator, indeed.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  576 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  334 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  553 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  551 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X