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

Index errors

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

    Index errors

    What can cause an Index Error other than being out of range. My strategy is producing that error on a specific bar which I have isolated by commenting it out but the index is [0] so I don't understand how it can be out of range.

    #2
    Hello galsermil,

    From the error alone all we could discern is that there is a problem retrieving data using [0], there would need to be more context to know why that causes a problem. If you have a sample of the code that is having a problem we can likely provide suggestions on ways that you could further tests that situation.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Her is the offending line and the print staement hatfllows but is never executed

      SorRSignal[0] = SupportandResistanceDetection1.SandRSignal[0];
      Print(Instrument.FullName + " " + Time[0] + " S or R Signal " + SorRSignal[0]);

      Here is the error Message

      2022-03-24 11:43:18:916|3|4|Strategy 'ITEntryStartegyCopy': Error on calling 'OnBarUpdate' method on bar 4948: Index was outside the bounds of the array.

      Comment


        #4
        Hello galsermil,

        From the given code we could say that is either the assignment to the plot or the accessing of the plot. The Print only contains your custom plot which is something that could have that error.

        I would suggest to do a test and see which of these items is the problem:

        You could try:

        Code:
        SorRSignal[0] = 1;
        That tests the series
        and:

        Code:
        Print( SupportandResistanceDetection1.SandRSignal[0]);
        That would help point a more specific direction.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Jesse,

          I get the same error message.

          Comment


            #6
            Hello galsermil,

            Right, that doesn't correct the error that just tells what part is having the issue. What part had the issue?

            JesseNinjaTrader Customer Service

            Comment


              #7
              I assume it must be the Print Statement which makes no sense.

              Comment


                #8
                Hello galsermil,

                Are you sure its the print statement? If so are you able to remove the other code and continue to see the error? The purpose of the two tests I provided in post 4 is so that you know specifically what the problem is so there is no guessing.

                You can try each of those by its self to see which produces the error, depending on which part produces the error would determine what you need to do next.

                Code:
                SorRSignal[0] = 1;
                If this gives an error its a problem with the SorRSignal series.

                Code:
                Print( SupportandResistanceDetection1.SandRSignal[0]);
                If this gives an error then its a problem with the indicator being used.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Jesse,

                  The first time I tried it I had both pieces of code in my Strategy script and it produce the same error. I did it again with each piece of code, one at a time, and they both produced the same error.

                  Comment


                    #10
                    Jesse,

                    I don't know whether you have surmised whether my problem is the indicator or the Strategy, both are my products. The indicator simply determines whether the current bar closes within 2 ticks of a pivot line. I have it divided into two sections for up bars and down bars as the 2 tick zone is on opposite side of the pivot line.
                    I'm referencing two indicators, PriorDayOHLC, and IT_FTreset which is third party. The IT indicator requires an add data series as does the Strategy. Sample and typical code for all lines of which there are 16 in each section: if (Close[0] <= (PriorDayOHLC1.PriorLow[0] + (Zone * TickSize)) && (Close[0] >= (PriorDayOHLC1.PriorLow[0])))
                    SandRSignal[0] = 1;

                    else if (Close[0] <= (IT_FTreset1.PP[0] + (Zone * TickSize)) && (Close[0] >= (IT_FTreset1.PP[0])))
                    SandRSignal[0] = -1;

                    In checking for each line if true, I assign a value to the SandSignal[0] so it is visible to the Strategy
                    In the Startegy, I merely determine if the signal is present on the same bar as other signals which will permit an entry. I do the entries after <IsFirstTickOfBar> which requires the use of SorRSignal[1] but I never get that far. because the Index error disables me.

                    Comment


                      #11
                      Hello galsermil,

                      If both parts of the code make an error then you have multiple problems.

                      The description of what you are doing won't really help me to understand why you are getting an index error, you would have to debug the situation with each piece of code to see why that is happening.

                      If you get an error with only the following code:

                      Code:
                      SorRSignal[0] = 1;
                      That indicates a problem with the series. You would get that error when trying to assign a series in a few cases, two that I could note would be: The plot/series was not created in OnStateChange. The plot/series is being used in a non bar related event where [0] BarsAgo does not make sense.

                      If you see an error with only this line, making sure you commented out all the other lines, then we could focus on that as the first issue. I would need to see how you defined the variable for SorRSignal and how you created it in OnStateChange to better understand the problem.

                      Based on the comments you provided it sounds like the series SorRSignal[0] = 1; may be working in other areas, if that is actually working then please double check the tests I had provided previously. You will need to comment out or remove all the code that is having an error so you no longer have the error, then try each test by its self to see what gives the error.

                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        ITEntryStartegyCopy.cs Jesse,

                        The Print statement is not causing an error but the assignment is. I am uploading the .cs file for the strategy rather than trying to give you the pieces you are interested in. It is not very long..

                        Comment


                          #13
                          Hello galsermil,

                          The Print statement is not causing an error but the assignment is.
                          So this part?

                          Code:
                          SorRSignal[0] = 1;
                          If that is what causes the error then you did not provide the code related to that series. I would need to see that series and how you defined it/created it in OnStateChange/where it was used.


                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            Jesse,

                            I attached the .cs file ,does that not contain all of the code for the strategy where the series was created?

                            Comment


                              #15
                              Hello galsermil,

                              The code we were talking about is not within that strategy so I don't know what part of that you need help with.

                              If we loop back to post #3 you gave the example code:

                              Code:
                              SorRSignal[0] = SupportandResistanceDetection1.SandRSignal[0];
                              Print(Instrument.FullName + " " + Time[0] + " S or R Signal " + SorRSignal[0]);
                              That is what my replies have been for and this code specifically is not in the attached script. if you see an error in the attached script and it is not directly related to the code we have been discussing then you need to reformulate a new question and supply the relevant code.

                              The steps I provided could be used with any code where you see the index error, you have to first find what specific part of the code has the problem. All I was showing was how to break down the code you provided into individual parts so you can test which part has the index error. Without knowing the specific code which is having an index error then we cannot continue.

                              I do see that you have similar code to what we have been talking about, if that is the problem then you need to debug the indicator if the indicator use is what causes the index error:
                              Code:
                                 Print(Instrument.FullName + "    " + Time[0] + "   S or  R Signal   " + SupportandResistanceDetection1.SandRSignal[0]);
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by llanqui, Today, 03:53 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post llanqui
                              by llanqui
                               
                              Started by burtoninlondon, Today, 12:38 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post burtoninlondon  
                              Started by AaronKoRn, Yesterday, 09:49 PM
                              0 responses
                              15 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by carnitron, Yesterday, 08:42 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Yesterday, 07:51 PM
                              0 responses
                              14 views
                              0 likes
                              Last Post strategist007  
                              Working...
                              X