Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars Object Count

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

    Bars Object Count

    Hello,

    Bars objects get added via Add method in the Initialize event, and I would like to be able to retrieve a count of such objects. For example, say I add 5m, 1m, and 1-tick objects and the default bar object associated with a chart is 15m.

    How can I obtain 4 as the count of such objects? Using Bars.Count gives me the actual number of bars within a series.

    Thank you.

    #2
    Hello ivb73077,

    Thank you for your inquiry.

    You would want to use the Count() method on the BarsArray array. This array holds all Bars objects that are added with the Add() method.

    Please take a look at the NinjaTrader help guide at this link for more information about BarsArray: http://ninjatrader.com/support/helpG...?barsarray.htm

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thank you.

      I would actually like to loop through the BarsArray and print certain attributes about each Bars object. Specifically, I would like to print the ID (i.e. PeriodType.Tick or PeriodType.Minute) and the Value (i.e. 5, 1, 15, etc).

      Might there be a sample of how to capture these properties for each Bars object in BarsArray?

      Something like:

      foreach (Bars b in BarsArray)
      {
      //how to access the PeriodType
      //how to access the Value
      }

      Comment


        #4
        Hello ivb73077,

        In this case, you may want to loop through the BarsPeriods array instead.

        Example:
        Code:
        foreach (Period bp in BarsPeriods)
        {
             Print(bp.Id.ToString()); // print the period type
             Print(bp.Value.ToString()); // print the period value
        }
        For more information about the BarsPeriods array, please take a look at this link in the NinjaTrader help guide: http://ninjatrader.com/support/helpG...arsperiods.htm

        For more information about Period objects, please take a look at the NinjaTrader help guide at this link: http://ninjatrader.com/support/helpG...barsperiod.htm (BarsPeriod is the primary Period object).

        Please, let us know if we may be of further assistance.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Excellent. Was unaware of the BarsPeriods object.

          Thank you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          581 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          338 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
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          552 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X