Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Internally, does GetBar just loop back to find value?

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

    Internally, does GetBar just loop back to find value?

    Hello.

    I am wondering if Bars.GetBar() simply find a corresponding time by looping back on itself to find the fist value of a time less than the time you input?

    OR.

    Is it some efficient heuristic, that knows which bar occupies that time, and it doesn't simply count bar by bar.

    Asking as I am debugging a piece of code, and am wondering if I write my on GetBar method by simply looping back on itself to find the desired time(or closest time if that bar doesn't exist).... I am just wondering how much slower mine would be if I created it by simply looping back, bar by bar.

    If none of that makes sense, I'm just wondering if the Bars.GetBar() finds the bar simply by starting at the CURRENT bar position, and counting backwards till the appropriate bar, or if it does so through some other means?

    Thanks,
    FP


    #2
    Hello forrestang,

    Unfortunately we cannot look at the actual internal code to answer that. You could try writing your own method to see if that is more efficient, unfortunately this would not be something I could provide any exact details on.

    Comment


      #3
      I dunno how definitive this is, but I was unable to produce a timing difference between using the GetBar method, or using my dumb method which just iteratively counts backwards until it encounters a time less than, or equal to, and breaks the loop, and returns that value.

      I kept increasing the bar count, thinking it might eventually show a time difference, eventually getting up to 30K bars.

      Should using the DateTime.Now, be the way to make the comparison in the way I am doing?

      Attached Files

      Comment


        #4
        Hello forrestang,

        Unfortunately I couldnt comment here as I don't know how the internal method is coded.

        Using DateTime.Now is the PC time which in general is not relevant to the bars on the chart. That would not work with playback or backtesting as an example.

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello forrestang,

          Unfortunately I couldnt comment here as I don't know how the internal method is coded.

          Using DateTime.Now is the PC time which in general is not relevant to the bars on the chart. That would not work with playback or backtesting as an example.
          I suspected that might be the case.

          I'll keep looking around. I tried a stopwatch c# function, but that didn't work(maybe NT8 is an older .NET?), I'll see if I can find something else.

          Are there any other ways that you can think of that I can compare the efficiency of GetBar to a custom method that accomplishes the same thing?

          If not that is ok, but I'm just wondering if there are ways to see just how inefficient what I am trying to do is.

          Thanks,
          FP

          Comment


            #6
            Hello forrestang,

            You can use the C# stopwatch, you may have not added the correct namespace. When using other than default items you may need to add additional using statements, you can find C# examples online by using a search engine or also in MSDN documentation.

            I wouldn't know of any other ways to compare the efficiency, I would likely suggest to avoid trying to make a custom method because at that point it is completely up to you to make sure that the result is accurate and works well. The NinjaTrader method is known to work correctly and accurately and is exposed for NinjaScript use so I would still suggest using that over anything custom.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            649 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            370 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            576 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X