Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars Ago vs CurrentBar performance

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

    Bars Ago vs CurrentBar performance

    There are two methods of accessing bar data in OnBarUpdate.
    1. Open[barsAgo], Close[barsAgo], etc....
    2. GetOpen(barIndex), GetClose(barIndex)
    To get the current bar Open[0] or GetOpen(CurrentBar).

    Is there any difference in execution performance of one over the other?

    #2
    Hi ntbone, thanks for your note.

    There is not much of a performance difference between the two. They are just two different methods of getting the same thing. If you use the array syntax, you increment from 0 to go backward in time. When you use one of the Get methods, you enter an absolute bar index, so the current close value would be GetClose(CurrentBar);. It is just sometimes more convenient to have the array syntax.

    Kind regards.

    Comment


      #3
      I realized there was a third option. The options are
      1. Open[barsAgo], Close[BarsAgo]...
      2. GetOpen(barIndex), GetClose(barIndex)
      3. Open.GetValueAt(barIndex), Close.GetValueAt(barIndex)
      Option 1 is limited by how far back the setting MaximumBarsLookBack. Option 3 I believe is limited to how much data the chart has loaded for the primary data series. I am not sure about option 2 but I would guess it is the same as option 3 both in terms of how far back it can look as well as performance.

      My understanding with MaximumBarsLookBack is that it reduces how much memory the indicator uses. If one looks back further then the setting what does that do for performance?

      Comment


        #4
        Hello ntbone, thanks for your reply.

        If you look back further than 256 (Close[1][257], for instance) and your MaximumBarsLookBack is set to 256 then this will cause an index out of bounds error. The performance hit you get from setting MaximumBarsLookBack will depend on the memory resources that the individual PC has. Note that this property is only applied to multi-series scripts (scripts that add additional data series with AddDataSeries)

        Kind regards.
        Last edited by NinjaTrader_ChrisL; 07-01-2019, 10:26 AM.

        Comment


          #5
          I am aware when using #1 referenced above, that you must stay within the range set by the MaximumBarsLookBack. However, as far as I know methods 2 and 3 will allow any bar referenced for an index greater then 0 and < CurrentBar. I was curious about the performance difference between the methods since only one of them seems limited by how far back one can look.

          Comment


            #6
            Hi ntbone, thanks for your reply.

            The Series of a script populate with many different price types such as Close, Low, Median, Typical, etc. The restriction was likely put into place because all of these data arrays are being updated around the same time very often.

            Kind regards.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            579 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 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
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X