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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    81 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    66 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X