• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Investigating Index was outside of the bounds of the array

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

    Investigating Index was outside of the bounds of the array

    I see this from time to time when I am developing on NT:
    2020-02-28 11:53:07:985 ERROR: Indicator 'sjBasketTickStream': Error on calling 'OnMarketData' method on bar 184: Index was outside the bounds of the array.

    There are many things going on in my OnMarketData() handler. What can I do to learn, specifically where within OnMarketData() did the error occur? I reviewed this post where the user shows a lot more detail in his trace and log files then I am showing. I reviewed both my log and trace file for the time in question and I just see the error I posted above. No details seem to be shown as this user shows. Looks like he is on NT7 and I am NT8. Not sure if that is the difference. Any suggestions for ways to dig into this (catch block or some other file I should be looking at?) would be appreciated. Just need to learn what object inside of OnMarketData() is causing the error.

    #2
    Hello swcooke,

    The error you are seeing would relate to a collection or series so that could be helpful if you are using any type of indexing: [1]

    Otherwise this is a fairly general error which can be raised in many situations. The easiest way to track this type of error down would be to first find what line of code is causing the error. There are various ways to do that, the most simple being prints.

    I generally suggest this type of debugging if you don't have any idea where the error is in the method:

    Code:
    Print("Here 1");
    //first line of code
    Print("Here 2");
    //second line of code
    Print("Here 3");
    //third line of code
    While this will produce a large amount of output, that can all be ignored up to the exception. You would then just note what the last print was and track where it stopped in your code.

    Another alternative is to use visual studio, you can enable all CLR exceptions and then just run the code with the debugger attached. Once the error is raised visual studio can catch that and the line it occurred on. If you are not sure how to do this please let me know and we can go further into that.

    Using Try/Catch may also be helpful however you would not necessarily get told what line the error happened on, only that you are getting this exception. The exception information may or may not contain any extra details so that is not likely the way I would suggest to approach this type of error.




    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      I really love the simplicity of the NT Editor. Is there any workaround available that you can think of that would give me access to the CLR exceptions while using the NT editor?

      Comment


        #4
        Hello swcooke,

        That level of tracking would require having an actual debugger attached to NT which is not part of the NinjaScript editor or NinjaTrader. I don't believe there would be any type of work around in this case as there is no debugger in NinjaTrader. The general expectation is to click the VS button to open VS which includes the debugger if that is needed.

        You don't have to use VS for programming or even continue using it past locating the error. The main benefit there is that you don't have to try and isolate the problem and it should in most cases just take you right to the line having a problem when the exception is caught. Visual studio has a much more powerful C# platform and toolset which can do many other tasks which are not included in NinjaTrader, NT basically just has access to the C# compiler to compile the custom code.



        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi Jesse,

          I've installed Visual Studio Community, enabled Debug mode in the NT editor and recompiled and then attached VS to the NT process. Then I enabled all CLR exceptions and added the Indicator to a chart and waited for the error to print in the NT log. It printed but I got nothing in VS as far as information. Did I miss a step? I didn't set any breakpoints. Please advise

          Comment


            #6
            Hello swcooke,

            That sounds correct, as a quick sanity check you could try doing the following from a test indicator:


            Code:
            protected override void OnBarUpdate()
                    {
                        if (CurrentBar > 10)
                            throw new Exception();
                    }
            You should then see the exception caught assuming you have the CLR errors enabled. I included the checked CLR in the image, make sure its not just a square box and is a check mark, that will enable all exceptions.

            Click image for larger version  Name:	kyCsghW.png Views:	0 Size:	47.3 KB ID:	1089071

            In the case you are not actually hitting a CLR exception that would not break, you may want to try enabling the other exception groups if you are unable to see your specific script stopping but you can see the test stop. If you are using third party libraries or external code you may still be unable to hit the exception like this.

            You may additionally want to comment out any try/catch you are using while doing this.


            I look forward to being of further assistance.
            Last edited by NinjaTrader_Jesse; 03-02-2020, 01:09 PM.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Endlessweek122, Today, 05:57 PM
            0 responses
            1 view
            0 likes
            Last Post Endlessweek122  
            Started by cutzpr, Today, 05:22 PM
            0 responses
            3 views
            0 likes
            Last Post cutzpr
            by cutzpr
             
            Started by ATMtrader0001, Today, 01:13 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by NtFan, Today, 04:18 PM
            0 responses
            6 views
            0 likes
            Last Post NtFan
            by NtFan
             
            Started by kaseipds, Today, 01:29 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X