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

Object not set to an instance of an object on bar -1

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

    Object not set to an instance of an object on bar -1

    I very often get the following error message : Error on triggering custom event for NinjaScript 'MY Indicator name' on bar -1: Object reference not set to an instance of an object.
    Can I get more details about this error I don't know where to start looking ?
    Does on bar -1 means from the OnState method ?

    #2
    Hello blar58,

    What is the exact line that is causing the error?

    You can prints to find where code stops executing and check if objects are null.
    You can comment out logic to ensure that code isn't causing the error.

    Does your script have multiple series?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Actually it happened on one of my customer's computer.
      It happens from time to time on mine but not today.
      Yes I am using multiple series

      Comment


        #4
        Hello blar58,

        Its likely a nullable object that has not had a check for null.

        I recommend you debug the script (even if you need to debug on that specific computer) and find the line that is causing the error.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          OK I will thank you !

          My customer ran into another problem that I am not experiencing myself.

          In my indicator I have created a new Bar Type and he gets the following error message :
          2018-10-18 12:33:19:188|3|4|Bars type 'KinetickDayBarsType': Error on calling 'OnStateChange' method: System.MissingMethodException: Method not found: 'System.String System.String.Format(System.IFormatProvider, System.String, System.Object)'.
          at NinjaTrader.NinjaScript.BarsTypes.KinetickDayBarsT ype.OnStateChange()
          at NinjaTrader.Data.BarsType.SetState(State state)

          Any idea ?

          Comment


            #6
            Hello blar58,

            From the error it looks like this is coming from a custom bar type named KinetickDayBarsType. The error looks to be coming from the OnStateChange() method.

            From a google search on System.String System.String.Format() this might be a .NET issue. Something in the script might be targeting .NET 4.6. NinjaTrader targets .NET 4.5.

            Are any bar types included with NinjaTrader 8 able to reproduce the behavior or is this only affecting the custom bar type?

            When you mention in your indicator you have created a new bar type, are you actually saying in an indicator you are adding a data series with AddDataSeries() that already existing imported bar type?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              It is only affecting the custom bar type.
              No I am not adding a data series with AddDataSeries() that already existing imported bar type and in fact this indicator is not using this bar type at all.

              Comment


                #8
                Hello blar58,

                Can you clarify your note:
                "In my indicator I have created a new Bar Type"

                From understanding it is not possible to create a new bar type in an indicator script.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Yes sorry I was not very clear.
                  This bar type has been added to the zip file, it is not in the indicator.

                  Comment


                    #10
                    Hello blar58,

                    If the system bar types included with NinjaTrader are not able to reproduce the behavior, the issue is likely caused by code in the custom bar type's OnStateChange() method.
                    Specifically if there is code that targets .NET 4.6 this would need to removed.

                    Again, I would recommend using prints and commenting out code to find the exact line causing the error.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      OK

                      Thank you !

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Tim-c, Today, 02:10 PM
                      1 response
                      7 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by Taddypole, Today, 02:47 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post Taddypole  
                      Started by chbruno, 04-24-2024, 04:10 PM
                      4 responses
                      50 views
                      0 likes
                      Last Post chbruno
                      by chbruno
                       
                      Started by TraderG23, 12-08-2023, 07:56 AM
                      10 responses
                      400 views
                      1 like
                      Last Post beobast
                      by beobast
                       
                      Started by lorem, Yesterday, 09:18 AM
                      5 responses
                      25 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Working...
                      X