Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reverse Indexing a Series

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

    Reverse Indexing a Series

    Hi guys,

    I've created Series objects that store price information given certain events. The problem I have is how to refer to those events again. Since Series index already in reverse, each new bar added means that I need to add one to the index of where that event took place.

    e.g.
    Code:
    //on bar 10, my event takes place so let's update mySeries.
    mySeries[0] = Close[0];
    Code:
    //on bar 15, I want to get back mySeries value on bar 10, when the last of my events took place.
    //I could keep an iterator updated on each bar so that I have something like;
    lastEventIdx++;
    //some code here
    //I need my value now.
    lastEventValue = mySeries[lastEventIdx];
    I suppose I could refer to the bar by timestamp. I was just wondering if there was a more elegant way to do this or some different paradigm I could use. If you could index from the beginning as opposed to the end, then you wouldn't have this problem as the index of interest would remain fixed.

    Interested to hear your thoughts.

    regards

    #2
    Hello trader_rick,

    Series use a barsAgo value.

    For the most recent bar use a 0 for 0 bars ago.

    To find a bar, record the CurrentBar number where the event occurred.

    Then subtract this from CurrentBar.
    Code:
    private int eventBarNumber;
    
    if (/* event condition here */)
    eventBarNumber = CurrentBar;
    
    Print(mySeries[CurrentBar - eventBarNumber]);
    Below is a public link to CurrentBar in the help guide.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Ah, of course, I forgot CurrentBar counted the 'right way' round.

      Thanks Chelsea!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      548 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      549 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X