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

Accessing an index with a value that is invalid

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

    Accessing an index with a value that is invalid

    I get this error:
    You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    I'm accessing a custom indicator with a data series in it and trying to reference a previous value using indicator[1]

    I have the following code in my bar update method, as well

    if((BarsInProgress == 0) && ( CurrentBar > 1))

    #2
    I also just try to access
    HIgh[0] > High[1]

    And I get errors just form that... index out of range.

    I'm using maxbarsback setting and also checking CurrentBar

    I'm running this with a market replay... very bizarre behavior

    Comment


      #3
      Originally posted by light65536 View Post
      I get this error:
      You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

      I'm accessing a custom indicator with a data series in it and trying to reference a previous value using indicator[1]

      I have the following code in my bar update method, as well

      if((BarsInProgress == 0) && ( CurrentBar > 1))
      Unfortunately, that snippet of code does not really say much; it is just a line of code, with no context. You may have to disclose a bit more of what you are doing, even if it is in pseudo-code rather than the actual code.

      You seem to be using a multi-timeframe structure, in which case you have to check all bar series for validity.

      Comment


        #4
        Thanks Kogaman. I am not using MTF. I am referencing a custom indicator. I have tried many ways to check if data.. such has HasValue, Count, etc... but when I try to access my custom indicator then it throws exception.

        I will experiment some more today to see what I can come up with.

        Comment


          #5
          Can I get some help here? This is very frustrating.

          I have an indicator that I'm trying to reference in my Ninja strategy but I keep getting errors on you are trying to access a value that is invalid/out of range

          I am trying the following

          MyIndicator.Series.ContainsValue(0) and MyIndicator.Series.ContainsValue(1)

          before accessing anything... not working. It looked like it was fixed then started again.

          Rather frustrated here...

          Comment


            #6
            Originally posted by light65536 View Post
            Thanks Kogaman. I am not using MTF. I am referencing a custom indicator. I have tried many ways to check if data.. such has HasValue, Count, etc... but when I try to access my custom indicator then it throws exception.

            I will experiment some more today to see what I can come up with.
            Then BarsInProgress is rather pointless. What we need to see in order to be able to help are:
            1. The inputs/outputs of the indicator that is being referenced.
            2. The code line in which you are writing the reference to said indicator.

            Other than that, it is simply a matter of escaping the correct number of bars that do not exist at the time of reference.

            Most often used is, to place this as the first line of OnBarUpdate():
            Code:
            if (CurrentBar < BarsReq) return;
            where BarsReq is usually 1, but can be any number that is appropriate for your back reference.

            Comment


              #7
              Okay.. so it sounds like this is another bug.. (argh). What is the proper way to test if my indicator has valid values then?

              Comment


                #8
                Might this have something to do with the way I'm adding series to my indicator? I am only adding a property like this.. I also add the plots. The indicator works properly but I can't access my series from my strategy. The Indicator.ContainsValue throws an exception.

                I've tried

                MyIndicator(...).MySeries.ContainsValue(0) && MyIndicator(...).MySeries.ContainsValue(1)
                --> throws exception... you are access an index with a value that is invalid

                I need a fix for this... thanks!



                [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                public DataSeries NewSeries
                {
                get { return Values[0]; }
                }


                [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                public DataSeries NewSeries1
                {
                get { return Values[1]; }
                }
                Last edited by light65536; 09-16-2012, 05:31 PM.

                Comment


                  #9
                  Originally posted by light65536 View Post
                  Might this have something to do with the way I'm adding series to my indicator? I am only adding a property like this.. I also add the plots. The indicator works properly but I can't access my series from my strategy. The Indicator.ContainsValue throws an exception.

                  I've tried

                  MyIndicator(...).MySeries.ContainsValue(0) && MyIndicator(...).MySeries.ContainsValue(1)
                  --> throws exception... you are access an index with a value that is invalid

                  I need a fix for this... thanks!



                  [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                  [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                  public DataSeries NewSeries
                  {
                  get { return Values[0]; }
                  }


                  [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                  [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                  public DataSeries NewSeries1
                  {
                  get { return Values[1]; }
                  }
                  The answer is still the same as what I gave you before: you have to escape processing for the number of bars which will not be available at bar 0. In this case, as you are trying to reference the bar 1 bar back, you need to escape 1 bar.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by TraderJA, Today, 12:06 AM
                  1 response
                  18 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by manueldecastro, Yesterday, 10:26 AM
                  7 responses
                  27 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by tradebot, Yesterday, 01:25 PM
                  5 responses
                  21 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by fleconkey, Today, 06:40 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post fleconkey  
                  Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
                  24 responses
                  79 views
                  0 likes
                  Last Post cmtjoancolmenero  
                  Working...
                  X