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 cmoran13, 04-16-2026, 01:02 PM
      0 responses
      77 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      45 views
      0 likes
      Last Post PaulMohn  
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      168 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      101 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      165 views
      2 likes
      Last Post CaptainJack  
      Working...
      X