Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Index Out of Range for multi-series

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

    Index Out of Range for multi-series

    I have an indicator that runs on the last historical bar of chart data. It calls a function similar to the runMe one below and it works fine with no exceptions.

    I have a textbox which when changed will call the runMe function again. All subsequent times the runMe function is run, Times[1][endI] throws an error ArgumentOutOfRangeException. Times[1].Count has 35082 members, and endI is only around 500 when the Print(Times[1][endI]) is throwing this exception. Why would this happen?

    Code:
    			
    
    private void runMe(int startI, int endI)
    for(int key = endI;key <= startI; key++){
    	if(BarsArray[1].IsFirstBarOfSessionByIndex(Times[1].Count - 1 - key)){//first bar of session
    		endI = key ;
    		Print(Times[1][endI]);
    		break;
    	}
    }	
    }

    #2
    If you are calling a Series outside of a core market data handler, the current bar pointer may not be in sync, resulting in index out of range exceptions.

    For any custom event methods, like when your text box changes, or a mouse down for example, you should use Absolute Indexes rather than try to find a barsAgo value. I have posted a simlar comment with some undocumented advice as well: http://ninjatrader.com/support/forum...49&postcount=2
    MatthewNinjaTrader Product Management

    Comment


      #3
      This doesn't quite fix my problem since I still need to loop through all 35000 values in Highs[1] and Lows[1]. Those values do not exist to complete the rest of the indicator's calculation. It looks like anything greater 13 bars ago does not exist in those series as well.

      Comment


        #4
        Hi habibalex,

        I'd like to assist by correcting a small sample.

        Can you create a working indicator with just this code demonstrated and export this?

        Tools -> Export -> NinjaScript
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I am having similar "You are accessing an index..." issues with trying to put values into a private Series, defined in State.DataLoaded clause of OnStateChanged (also tried in State.Configure)

          DirectSeries = new Series<double>(this, MaximumBarsLookBack.Infinite);

          The number of elements (DirectSeries.Count) value is 2727.
          When I attempt to assign values starting at element 240, the error occurs:

          For (int I = 240; I >=0; I--)
          {
          DirectSeries[I] = <a double value>;
          }
          This is extremely frustrating. It should be a trivial matter to put values into a private series. While I concede I must be missing something, I cannot understand why this simple code doesn't work.
          Last edited by TurtleBeach; 12-22-2015, 05:34 PM. Reason: Typo

          Comment


            #6
            Chelsea i sent you a link to the indicator as a private message

            Comment


              #7
              Hello habibalex,

              I have received a script from you in my private inbox.

              In your post, most of what is in this script is not mentioned. May I confirm this script the minimal amount of code necessary to reproduce the issue?

              The code for this quite extensive. Is every bit of this to demonstrate what is causing the issue?

              May I post this script to the forum with any added prints?
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Yes all the code there is necessary to demonstrate the problem. I had to add a data series to the chart, a textbox to the chart to fire off the findflips function, and handle code for the textbox.
                The findflips function is where the error is occurring. You can post it if you want.

                Comment


                  #9
                  Hello habibalex,

                  I am looking through the code, but I am not understanding why you have to have textbox or what this does.

                  In OnBarUpdate this appears to be calling findFlips() directly which appears to be a loop that is doing some check with BarsArray and printing the Time of a certain number of bars ago endI.

                  Can you explain why the text box is necessary to loop through the bar information?

                  It almost appears that private void TextBox_PreviewKeyDown isn't necessary, button_TextChanged isn't necessary, rivate void AddButtonToToolbar() isn't necessary, and most of the variables in the script are not necessary.
                  The majority of this script appears to not be necessary to reproduce the issue.

                  Is the issue not that part but instead somewhere in the rest of the code?
                  Which line of code is generating the error? (To find this add prints to the code after each step to see which print appears before the error is generated)

                  TurtleBeach,

                  You mention that you are also experiencing an index as well. Your code appears to be simple and direct. Do you have a barebones sample that I could test and assist with?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Have you tried running the code? It throws an error on the Print statement which is mentioned in the first post when called from the textbox after the indicator is loaded.

                    When the code findFlips is run from OnBarUpdate it works corrrectly as expected. When it is run when the textbox is changed, it fails on the Print(Times[1][endI]) statement. To change the textbox you need the TextBox_PreviewKeyDown function. To run the function you need the button_TextChanged function. You need AddButtToToolbar to add the button to the toolbar. Yes I didn't remove all the variables in there, sorry about that.

                    Comment


                      #11
                      Hello habibalex,

                      What I mean is, can you skip the part with the changing text box. Why is it necessary to trigger this with typing text into a text box?

                      The typing of text only appears to trigger findFlips(Times[1].Count-1, 288,minFlipRotation);//endi USED TO BE 0 not -288.

                      It doesn't appear that this needs to be called when typing text into the text box. It looks like the code just needs to trigger findFlips.

                      Can you further explain why this must be done when the text in the text box is changed?

                      I ask because it also appears to be triggered from OnBarUpdate and is able to generate the error when the indicator is first added to the chart.

                      All the other code in the script appears unnecessary.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        I was only getting an error when findFlips is run after the indicator was loaded. I was not getting an error when it was run from OnBarUpdate. It does not need to be executed through a textbox, but just after the chart is loaded. I guess if I'm connected to a live data feed, and OnBarUpdate is called it should have the same effect. I wanted to do it on demand though...either way how do I access the Time, Open, Low, High, Close chart data if the those objects aren't correctly populated?
                        Last edited by habibalex; 12-24-2015, 01:02 PM.

                        Comment


                          #13
                          Hi habibalex,

                          Because multiple community members have mentioned in this thread this error, I took the time to remove all of the unnecessary code from your script and make it a barebones version of the script that is able to reproduce the error.

                          Please study what I have removed. This is important so that in the future if you would like a member of the NinjaScript support staff to look at your code, you know what we are looking for so that we may assist you.

                          We do not provide debugging services or modify scripts created by clients in the NinjaScript department and generally will not reduce your code to the exact issue as I have done for you. When presenting an issue, please do not include any code that is not absolutely necessary to reproduce the issue.

                          May I confirm that this modified script is able to cause the error on your end? (I am able to reproduce this error with this reduced script just by adding this to a chart)

                          Now that I have a simplified script, I will look further into the cause.
                          Attached Files
                          Last edited by NinjaTrader_ChelseaB; 12-24-2015, 01:08 PM.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            I don't see any error on my side when your modified indicator is run, however it will not trigger after the chart is loaded.

                            I was not getting any errors in OnBarUpdate, only when findFlips was called after the chart had loaded.
                            Last edited by habibalex; 12-24-2015, 01:17 PM.

                            Comment


                              #15
                              Hello habibalex,

                              I am unable to run this script on my end without an error.

                              I would like to schedule a call with you so that I may test the indicator on your end and gather further information.

                              Please send an email to platformsupport [at] ninjatrader [dot] com. In the email please add a link to this forum thread.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by bmartz, 03-12-2024, 06:12 AM
                              4 responses
                              31 views
                              0 likes
                              Last Post bmartz
                              by bmartz
                               
                              Started by Aviram Y, Today, 05:29 AM
                              4 responses
                              11 views
                              0 likes
                              Last Post Aviram Y  
                              Started by algospoke, 04-17-2024, 06:40 PM
                              3 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by gentlebenthebear, Today, 01:30 AM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by cls71, Today, 04:45 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X