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 trilliantrader, Yesterday, 03:01 PM
      3 responses
      29 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by cmtjoancolmenero, Yesterday, 03:58 PM
      4 responses
      26 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Brevo, Today, 01:45 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by rjbtrade1, 11-30-2023, 04:38 PM
      2 responses
      74 views
      0 likes
      Last Post DavidHP
      by DavidHP
       
      Started by suroot, 04-10-2017, 02:18 AM
      5 responses
      3,022 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X