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

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 traderqz, Yesterday, 09:06 AM
      3 responses
      20 views
      0 likes
      Last Post NinjaTrader_ThomasC  
      Started by f.saeidi, Today, 10:19 AM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by kujista, Today, 06:23 AM
      5 responses
      15 views
      0 likes
      Last Post kujista
      by kujista
       
      Started by traderqz, Today, 12:06 AM
      3 responses
      6 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by RideMe, 04-07-2024, 04:54 PM
      5 responses
      28 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X