Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategies process Bars object differently than Indicators

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

    #16
    savekad,

    Lets do one more example, though it's not matching 100% here.

    Lets say I have a 60 minute chart that I am running your code on it.

    60 minutes must pass before the first OnBarUpdate() call with BarsInProgress 0. After 60 minutes have passed from the beginning of your chart, you will get something like :

    OBU call for 60 minute -> 1 element in the BarsArray[0] exists.
    OBU call for 3 minute -> at least 20 elements in the BarsArray[1] exists.
    OBU call for 5 minute -> at least 12 elements in the BarsArray[2] exists.

    I am seeing that NinjaTrader is actually loading more than this for the second and third series, and I suspect there is some under-the-hood item where NinjaTrader is requesting additional historical data. I don't have a good explanation for this at this time other than perhaps it is being a bit over-careful to ensure that it has all the data it needs.

    In this case all series are using "BarsRequired" equal to the same thing but with the under-the-hood handling of multi-series scripts NT is requesting additional historical data for the added series. At least this seems to be the case since I am seeing more than 20, and 12 elements respectively for the added series when I run your code.

    If you need some set of series that are pegged closer to the OBU calls you could always track your own custom defined "BarsArray" and only assign values to it when you get the OBU calls.

    Adam P.NinjaTrader Customer Service

    Comment


      #17
      Let me see if I got it right. Please verify:

      When setting BarsRequired to, say, 0, OBU() will fire for every bar of the BarsArray elements, starting from the first bar of each element and the reason prints are showing that OBU() did not start from CurrentBar == 0 is that NT has loaded extra not-taken-into-account bars and OBU() skipped them.

      Comment


        #18
        savekad,

        NT loaded additional historical data into the past from the beginning of your chart for the second and third series, however OBU skipped them and started iterating with BarsArray[1] and BarsArray[2] after the first OBU call with BarsInProgress == 0.
        Adam P.NinjaTrader Customer Service

        Comment


          #19
          Hi again, Adam.

          Based on your last message to this post, if a strategy script loads some invisible bars for some under the hood logic, is that mean that the CurrentBar of the last bar will be greater than Count?

          After all, we saw that the first bar OBU evaluates is not CurrentBar 0 and that due to the fact that there were some extra bars loaded to the chart.

          Comment


            #20
            savekad,

            There are no extra bars loaded on a chart. There is extra historical data loaded into the "BarsArray" object only for multi-series scripts. BarsArray includes all bars on your chart, but there are some extra that can be added to BarsArray for any additional series you put in your indicator/strategy. I.e. BarsArray includes all bars on your chart, but the bars on your chart do not include all objects in the BarsArray. This only would be for historical data that is before the starting point on your chart and it would also only be for the non-primary series.

            BarsArray[x].Count tells you accurately how many "bars" NT loaded of historical data at the time you call it. The CurrentBars[x] tells you how many times the OBU method was called for series with index x. Generally CurrentBars[x] will always be less than or equal to BarsArray[x].Count.

            Every bar that is on your chart will get iterated through as long as the "BarsRequired" is satisfied. In other words, if "BarsRequired" is 20, then NinjaTrader will skip the first 20 bars on your chart for indicator calculations.

            For each bar on your chart there are "Dataseries" getting built. These are "Close", "Open", "High", "Low", etc. This happens even if BarsRequired isn't satisfied and is done to build these objects up so your indicator can use them in calculations. This is to prevent "index out of bound" type run-time errors.
            Last edited by NinjaTrader_AdamP; 10-15-2012, 08:33 AM.
            Adam P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            669 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            378 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            111 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            575 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            580 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X