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

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 Kaledus, Today, 01:29 PM
    0 responses
    3 views
    0 likes
    Last Post Kaledus
    by Kaledus
     
    Started by PaulMohn, Today, 12:36 PM
    1 response
    16 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by yertle, Yesterday, 08:38 AM
    8 responses
    37 views
    0 likes
    Last Post ryjoga
    by ryjoga
     
    Started by rdtdale, Today, 01:02 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by alifarahani, Today, 09:40 AM
    3 responses
    19 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X