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 cmoran13, 04-16-2026, 01:02 PM
      0 responses
      43 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      27 views
      0 likes
      Last Post PaulMohn  
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      163 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      98 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      158 views
      2 likes
      Last Post CaptainJack  
      Working...
      X