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 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.
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        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.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by stafe, 04-15-2024, 08:34 PM
            7 responses
            31 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by adeelshahzad, Today, 03:54 AM
            4 responses
            29 views
            0 likes
            Last Post adeelshahzad  
            Started by merzo, 06-25-2023, 02:19 AM
            10 responses
            823 views
            1 like
            Last Post NinjaTrader_ChristopherJ  
            Started by frankthearm, Today, 09:08 AM
            5 responses
            17 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            43 views
            0 likes
            Last Post jeronymite  
            Working...
            X