Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trouble with random "Object reference not set to an instance of an object" errors

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

    #16
    Hello Mark,

    I'm still thinking it could be an issue with the installation.

    If the repair did not work, please try a creating a clean environment folder.

    To create a clean temporary NinjaTrader folder:
    1. Shutdown NinjaTrader
    2. Rename (My) Documents\NinjaTrader 8\ to (My) Documents\NinjaTrader 8.original\
    3. Download the NinjaTrader installation package from the link below
    4. NinjaTrader - Download
    5. Uninstall and then re-install NinjaTrader


    Also, what connection are you using to connect for data?

    May I see an export of your script to look for anything unusual? (Added series, custom series etc)

    To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript Add-on...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...nt8/export.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Sure thing I can do both. Ninjatrader just uninstalled and a clean copy of the current version download and freshly installed. The connection is Ninjatrader Continuum.

      Script being mailed to support ATTN: ChelseaB shortly.

      Sent.

      Mark
      Last edited by markdshark; 10-13-2023, 03:20 PM.

      Comment


        #18
        Got a new one today which seems related to the previous errors:

        System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
        Parameter name: index
        at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource)
        at NinjaTrader.NinjaScript.Series`1.get_Item(Int32 barsAgo)
        at NinjaTrader.NinjaScript.Indicators.AMyIndicators.m ySUM.OnBarUpdate()


        This showed up randomly after running through the night. There's also another bit of weirdness that I think is related to these errors which is that occasionally and not infrequently indicators will draw themselves completely out of whack. The fix is to disable the strategy and reenable it and the indicator usually draws properly. On rare occasions I will need to do this twice.

        Now the issue of indicators not drawing properly is problematic as the strategy action depends on what the indicator shows. Today it missed an entry because the linReg indicator was not drawn properly. I restarted the strategy and it corrected itself but the moment of the signal had passed so no trade was taken.

        Mark

        Comment


          #19
          Hello Mark,

          Apologies, your case was not properly routed to me.

          I was able to find this morning and received your script. So far I've enabled this on a chart and I've left it running and will be checking periodically for errors on the Log tab of the Control Center.

          May I confirm you renamed the NinjaTrader 8 folder in documents so that a new environment folder is created?

          After this did you import anything other than the custom script?

          May I have you try using the NinjaTrader connection type? (The username and password will be the same as you use in the Client Account Portal)
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            Hi Chelsea. Thank you.

            Yes I created a new clean environment and did a fresh download and install. Created a n ​ew NinjaTrader 8 folder in docs and only imported the indicators and strategies I am using by manually recreating them in Ninjascript editor. MyLinReg, mySUM, myStochastics etc are simply copies of the system indicators with try/catch block added in OnBarUpdate and OnStateChange to trap these errors. This permits the script to continue running in the face of these errors without coming to a grinding halt.

            Currently running live but I will switch from Continuum to Ninjatrader connection this afternoon and report back with any change in behavior. Can you help me understand the difference between the two connection types?

            Mark

            Click image for larger version

Name:	Screenshot 2023-10-23 at 7.54.15 AM.png
Views:	141
Size:	8.6 KB
ID:	1274294

            Comment


              #21
              Compile in Debug mode, and then examine your trace files in Documents->NinjaTrader 8->trace to see where this error message is coming from. It will tell you the exact line number where the exception is generated, so you know what you need to fix.
              Bruce DeVault
              QuantKey Trading Vendor Services
              NinjaTrader Ecosystem Vendor - QuantKey

              Comment


                #22
                That's super helpful, thank you I will do that next!

                Mark

                Comment


                  #23
                  Hi Mark,

                  I've been running the strategy continuously today but I haven't experienced any errors. This is suggesting the script code might not be the issue.

                  How often are you seeing the error appearing? (How long after enabling before the error occurs)
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Thank you for testing it. It's unfortunately one of the worst kinds of errors being that it's super sporadic. Nothing for a week then 1 or two a day separated by several days type of thing. Without the try/catch blocks everything would come crashing down.

                    In general I am getting 2 kinds of errors that are possibly related.

                    1. Object reference not set to an instance of an object / Index out of range exception being thrown from built in indicators (SUM and LinReg have both exhibited this). For example the stack trace on the previous page shows BarSeries.GetClose not being able to find what it needs. Reproduced here:

                    System.NullReferenceException: Object reference not set to an instance of an object.
                    at NinjaTrader.Data.BarsSeries.GetClose(Int32 index)
                    at NinjaTrader.Data.Bars.GetClose(Int32 index)
                    at NinjaTrader.NinjaScript.PriceSeries.get_Item(Int32 barsAgo)
                    at NinjaTrader.NinjaScript.Indicators.AMyIndicators.M yLinReg.OnBarUpdate()​

                    2. The indicators will sometimes draw themselves very out of whack when the strategy is started. Sometimes it's super obvious like when the linReg is something like 50 points lower than where it should be and autoscale smooshes the chart into a single line to fit it all in. Other times like today morning one has to look more carefully as the main chart looked fine but the stochastics were off when I restarted so it missed an entry. When I say "off" I mean the lines didn't seem to match what one would expect to see given the price patterns. Restarting a second time at about 2am and everything rendered just fine and the strategy ran until programmatically disabling itself as intended.


                    I do think it's something related to not getting the right data input for some reason, or in the wrong order, or something like that.

                    I am presently running on an AWS t3.small instance which has 2GB of memory and roughly a 5 GB throughput. The memory seems sufficient. The system isn't snappy by any means but it's not unresponsive so the instance appears to have sufficient resource.

                    Mark

                    Comment


                      #25
                      Hello Mark,

                      As a heads up,NinjaTrader is not officially supported to run with virtualization software or cloud services such as Azure or AWS.​

                      Using any cloud services
                      • May cause issues with identifying logical processors
                      • May cause issues with access permissions
                      • May cause issues with maintaining a connection
                      ​Are you able to reproduce this behavior on a local computer (or a VPS that is not a cloud service)?


                      The script should disable if there is an error, and the Try and Catch is likely causing the "out of whack" behavior.

                      I'll keep running the strategy on my end for a few days to see if I am able to reproduce.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #26
                        I will locate a Non cloud VPS and confirm.

                        Best,
                        Mark​

                        Comment


                          #27
                          Just wanted to add a note that No, the try/catch blocks are definitely not the source of the "out of whack" indicator behaviors as there are no exceptions being thrown at the time the indicators are painting "out of whack".

                          The wildly inaccurate indicator painting is happening when the strategy is started. It might be an indicator on the main window such as LinReg. It might be an indicator on a lower window such as Stochastics. There are no exceptions being thrown regardless.

                          My solution is to maintain a window beside the strategy window with exactly the same time frame and indicators but without the strategy running. This allows me to visually compare the indicators between the two windows when I start a strategy and immediately see if the strategy indicators are painting garbage so I can restart the strategy right away. Sometimes it's obvious without comparison. Occasionally the differences are a bit more subtle and a visual check helps.

                          The other interesting and hopefully helpful detail is that although the null reference exception may happen after a few hours of running, the indicators themselves don't randomly go haywire and print garbage which is the behavior I'd expect if they were suddenly unable to process the input during the run. Rather they either print garbage from the get go when the strategy is started. Or.. (and if they are restarted), they function as intended throughout the run.

                          Perhaps this is because they are all being run in Calculate on tick or price change so that even if they do get a garbage tick in which may cause them to throw an exception on that specific tick, immediately after that the very next tick or price change is received correctly, and so no weird output results.

                          Also relevant, I'm not seeing a random bad tick style paint of the indicator way off for a single tick then back to normal suggesting that's not the sort of error occurring.

                          Here's an error that occurred today which is a bit more informative than the previous ones. It's also one I have not seen before.

                          System.ArgumentOutOfRangeException: 'barsAgo' needed to be between 0 and -1 but was 0
                          Parameter name: barsAgo
                          at NinjaTrader.NinjaScript.Series`1.get_Item(Int32 barsAgo)
                          at NinjaTrader.NinjaScript.NinjaScriptBase.get_Item(I nt32 barsAgo)
                          at NinjaTrader.NinjaScript.Indicators.AMyIndicators.M yLinReg.OnBarUpdate()


                          Mark
                          Last edited by markdshark; 10-24-2023, 05:55 AM.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by NullPointStrategies, Today, 05:17 AM
                          0 responses
                          53 views
                          0 likes
                          Last Post NullPointStrategies  
                          Started by argusthome, 03-08-2026, 10:06 AM
                          0 responses
                          130 views
                          0 likes
                          Last Post argusthome  
                          Started by NabilKhattabi, 03-06-2026, 11:18 AM
                          0 responses
                          70 views
                          0 likes
                          Last Post NabilKhattabi  
                          Started by Deep42, 03-06-2026, 12:28 AM
                          0 responses
                          44 views
                          0 likes
                          Last Post Deep42
                          by Deep42
                           
                          Started by TheRealMorford, 03-05-2026, 06:15 PM
                          0 responses
                          49 views
                          0 likes
                          Last Post TheRealMorford  
                          Working...
                          X