• 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

Index outside the bounds of array problem.

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

    Index outside the bounds of array problem.

    Hi there,

    I am having a problem with one of my strategies which I just cannot seem to be able to solve. I've looked up previous "Index was outside the bounds of the array" issues and seen how it's supposed to be fixed with using ...

    if ( CurrentBar < 1)
    {
    return;
    }

    However sadly it is just not happening. Can anyone look at my code to see what may be going on? Thanks!

    Here is the pastebin code for it. https://pastebin.com/uxFnM37U

    #2
    Hello clubfoot,

    Thank you for writing in.

    If you use the following to ensure each series has enough bars,
    Code:
    if (CurrentBars[0] < 5 || CurrentBars[1] < 5 || CurrentBars[2] < 5)    return;
    Does your script run without error?

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Sadly it still didn't it's still showing

      Strategy 'FPOrderFlowAuto': Error on calling 'OnBarUpdate' method on bar 5: Index was outside the bounds of the array.

      Comment


        #4
        Hello Clubfoot,

        Please upload a copy of the strategy in the following format so I may import and test on my end,

        To export a NinjaScript from NinjaTrader 8 do the following:
        From the Control Center window select Tools -> Export -> NinjaScript...
        Click Add>Select the indicator>OK>Export.
        Then attach that file you saved; under My Docs>NT8>Bin>Custom>Select the downloaded .zip file.

        I look forward to your reply.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hi Alan,

          Thanks for looking into this for me! Here it is
          Attached Files

          Comment


            #6
            Hello Clubfoot,

            I was able to compile and run the strategy without error with just 1 bar check, for example,
            Code:
            	if (CurrentBars[0] < 10) return;
            I have attached the revised strategy.

            Please let us know if you need further assistance.
            Attached Files
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              The problem is it starts up fine, but once it is supposed to do a condition it immediately says Index was outside the bounds of the array again and disables itself. Can you run it in playback and see if thats happening for you?

              Comment


                #8
                Originally posted by clubfoot View Post
                The problem is it starts up fine, but once it is supposed to do a condition it immediately says Index was outside the bounds of the array again and disables itself. Can you run it in playback and see if thats happening for you?
                That is because your issue here has nothing to do with the CurrentBars or any bars Array. Your message is telling you that you are trying to refer to an index in an Array, where the index does not exist.

                You have referenced and tried to populate the Values[] array by declaring 3 public Series<double>, but you never created the Values[] array, so any reference to that array will cause you grief. The Values array is indirectly created when you AddPot(). You have not added any Plots, but you are trying to populate the array that holds the values that the Plots reference.

                Either unhitch your public Series<T> from the Values[] array, or else declare the necessary Plots to create the Values[] array.
                Last edited by koganam; 08-26-2017, 09:36 PM. Reason: Corrected spelling.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by TAJTrades, Today, 10:34 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Started by timcjpfx, Today, 10:20 AM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by Eloi_, Today, 09:48 AM
                2 responses
                9 views
                0 likes
                Last Post Eloi_
                by Eloi_
                 
                Started by Longhornmark, Today, 08:22 AM
                2 responses
                20 views
                0 likes
                Last Post anon84
                by anon84
                 
                Started by blinx18, Today, 09:54 AM
                2 responses
                7 views
                0 likes
                Last Post blinx18
                by blinx18
                 
                Working...
                X