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

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 Waxavi, Today, 02:10 AM
          1 response
          16 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by Kaledus, Today, 01:29 PM
          5 responses
          13 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Waxavi, Today, 02:00 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by alifarahani, Today, 09:40 AM
          5 responses
          23 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by gentlebenthebear, Today, 01:30 AM
          3 responses
          17 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X