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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    73 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    152 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    162 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    100 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    288 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X