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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      156 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      90 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      138 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      130 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      107 views
      0 likes
      Last Post CarlTrading  
      Working...
      X