Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error accc

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

    Error accc

    I am trying iterate throught the High and Low price series loop in the OnRender() event. When I try to access the High (or any series) I get an out-of-range error from the 2nd element onwards (i = 1)

    I have listed the simplified code below.

    Code:
    protected override void OnRender(ChartControl cc, ChartScale cs)
    {
         if( State != State.Realtime ) return;  // Wait till we are real-time.                             
         for(int i = 0; i < Bars.Count; i++)
         {
              Print(string.Format("High [{0}] = {1}. Current Bar = {2}, Bars.Count = {3}", i, 
                                             Instrument.MasterInstrument.FormatPrice(High[Bars.Count - i - 1]), CurrentBar, Bars.Count));
         }
    }
    Here is the output window result.The first line (blue) is correct, and an out-of-range exception happens after that.

    High [0] = 177.92. Current Bar = 250, Bars.Count = 251
    Indicator 'InsideOutsideBar': Error on calling 'OnRender' method on bar 250: You are accessing an index with a value that is invalid since it is out-of-range.


    I notice that it fails from i = 1 onwards. However, the value of Bars.Count is 251, and the size of High <double> series is also 251.

    Is my code correct ? What am I missing ?

    #2
    PLEASE IGNORE MY POST. I found the correct solution using ChartBars.FromIndex, ChartBars.ToIndex and High.GetValueAt()

    Comment


      #3
      Hello firstlanetech,

      I am glad you were able to find a solution.

      As a heads up, when in non-data-driven methods such as OnRender(), you will need to use TriggerCustomEvent() or Bars.GetHigh() .

      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      648 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      369 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      572 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X