Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is there a way to get the number of bars between two times on a chart?

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

    Is there a way to get the number of bars between two times on a chart?

    I am trying to do an interpolation calculation for an indicator. I cannot use the actual dates of the interpolation because it does not account for market closed time.

    Wondering if there is a way to do this off of bar count. So for example, if I want to calculate the rate of change between say 1/1/2021 and 1/10/2021, I want to do something like this, Rate = (Price 1 - Price 0 ) / (count of Bars between 1/1/2021 and 1/10/2021)

    If I do this with date diff to seconds, my interpolation is scrwed up because of the closed market. Only way I can think to do this is with bar counts, but open to other ideas if anyone has

    #2
    Hello ErikY,

    It is possible to get the number of bars between two bars selected with Bars.GetBar().


    DateTime startDateTime = new DateTime(2021, 10, 24, 0, 0, 0);
    DateTime endDateTime = new Date(2021, 10, 24, 15, 0, 0);

    int numBarsBetweenBars = Bars.GetBar(endDateTime) - Bars.GetBar(startDateTime);
    Chelsea B.NinjaTrader Customer Service

    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
    573 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