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

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 bortz, 11-06-2023, 08:04 AM
      47 responses
      1,605 views
      0 likes
      Last Post aligator  
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      8 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      4 views
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      13 views
      0 likes
      Last Post Javierw.ok  
      Working...
      X