Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

using Close for bars ago.

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

    using Close for bars ago.

    I have this in an indicator


    Print (Close.Count);
    try {
    Print (Close[8]);
    }
    catch (Exception e) {Print (e.Message);}

    It produces the message

    2415
    Parameter name: indexIndex was out of range. Must be non-negative and less than the size of the collection.

    Is this not the proper use of Close?

    Thanks.

    #2
    Hello,

    Before we get into your code below, are you doing a CurrentBar check?:


    You will need to with the "8" index.
    DenNinjaTrader Customer Service

    Comment


      #3
      Its is not correct use since .Count returns the # of elements contained in the series however, OnBarUpdate() is called once per bar starting from left to right on your chart. So, there may be 200 closing prices returned by .Count, the CurrentBar index may only be on bar #1 thus, accessing Close[8] woudl throw an exception since the indicator has not yet seen 8 bars.

      Hope that makese sense.
      RayNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      596 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      343 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      556 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      554 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X