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 Mindset, 04-21-2026, 06:46 AM
            0 responses
            55 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            72 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            38 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by cmoran13, 04-16-2026, 01:02 PM
            0 responses
            99 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            60 views
            0 likes
            Last Post PaulMohn  
            Working...
            X