Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

8.0.0.3 IsValidDataPoint exception

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

    8.0.0.3 IsValidDataPoint exception

    See attached indicator. When I call IsValidDataPoint() for the first point in a series, I get an ArgumentOutOfRangeException: "Index was out of range. Must be non-negative and less than the size of the collection." In the indicator attached, this happens in OnRender() when ChartBars.FromIndex is 0 (that is, the first bar is visible on the chart).

    Thanks,
    Dale
    Attached Files

    #2
    Hello Dale,

    Thank you for your post.

    I tried this on an ES 09-15 1 Minute chart without issue. Can you provide some specifics on the chart you are using to test this?

    Comment


      #3
      I get the exception in the log on an ES 09-15 1 Minute chart but ONLY when I scroll all the way to the left, so the first bar is on the chart. I can send a video if that would help.

      Comment


        #4
        Hello Dale,

        Thank you for your response.

        My colleague took a look at the code and provided the following:
        Code:
        for (int idx = ChartBars.FromIndex; idx < ChartBars.ToIndex; idx++)
        	        {
        	          //  var barsAgo = Bars.Count - 1 - idx;
        	            try
        	            {
                            if (!Periods.IsValidDataPoint(idx))
                            {
                                continue;
                            }
        	            }
        	            catch (Exception ex)
        	            {
        	                Log(ex.Message, LogLevel.Error);
                            _isExceptionReported = true;
                            return;
        	            }
        	        }

        Comment


          #5
          Originally posted by NinjaTrader_PatrickH View Post
          Hello Dale,

          Thank you for your response.

          My colleague took a look at the code and provided the following:
          Code:
          for (int idx = ChartBars.FromIndex; idx < ChartBars.ToIndex; idx++)
          	        {
          	          //  var barsAgo = Bars.Count - 1 - idx;
          	            try
          	            {
                              if (!Periods.IsValidDataPoint(idx))
                              {
                                  continue;
                              }
          	            }
          	            catch (Exception ex)
          	            {
          	                Log(ex.Message, LogLevel.Error);
                              _isExceptionReported = true;
                              return;
          	            }
          	        }
          No, I really don't think that is possible. Intellisense and your help documentation say that IsValidDataPoint() takes a bars ago value, not a bar index.

          From your reference:
          IsValidDataPoint()
          Checks if the specified input has been set at a barsAgo value relative to the current bar.

          This is very different from GetValueAt(), which does take an index.
          GetValueAt()
          Gets the underlying input value at a specified bar index value.

          Comment


            #6
            Right, it's a barAgo value, which means it is relative to CurrentBar. The exception is expected and here is why:

            Let's say you have 50 bars on the chart, with Calculate.OnBarClose. This means your Periods series has only calculated to CurrentBar 48

            At the time of your exception in your OnRender pass:

            Bars.Count = 50
            CurrentBar = 48
            ChartBar.FromIndex = 0

            Calculate this out, your barsAgo (50 - 1 - 0) = 49. So your IsValidDataPoint() is trying to access the 49 bar ago

            However, your Periods series only has calculated to 48 bars (0 - 48), hence the exception. The reason you do not get that until you scroll the first bar into view, is before that, the barsAgo value is less than the size of the array - although I'm not sure this is accessing the info you thought it was.

            I'm not entirely sure what you were attempting to do, but IsValidDataPoint() was intended to be used in OnBarUpdate / CurrentBars.

            If you can elaborate on what your goal was with this example script where you ran into this exception, we can provide a workaround, or amend code if there is indeed something wrong with IsValidDataPoint() which I'm missing.
            MatthewNinjaTrader Product Management

            Comment


              #7
              Thank you, Matthew, that was the clue I needed. I was forgetting the extra difference between Bars.Count and CurrentBar in this case where Calculate == Calculate.OnBarClose. I think now I've finally internalized it. Sorry for bothering y'all.

              Best regards,
              Dale

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by ghoul, Today, 06:02 PM
              0 responses
              4 views
              0 likes
              Last Post ghoul
              by ghoul
               
              Started by Barry Milan, Yesterday, 10:35 PM
              6 responses
              18 views
              0 likes
              Last Post Barry Milan  
              Started by DanielSanMartin, Yesterday, 02:37 PM
              2 responses
              13 views
              0 likes
              Last Post DanielSanMartin  
              Started by DJ888, 04-16-2024, 06:09 PM
              4 responses
              13 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by terofs, Today, 04:18 PM
              0 responses
              12 views
              0 likes
              Last Post terofs
              by terofs
               
              Working...
              X