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().
    https://ninjatrader.com/support/help...nt8/getbar.htm

    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 AlessioCianini12, Today, 01:38 AM
    0 responses
    27 views
    0 likes
    Last Post AlessioCianini12  
    Started by nandhumca, Yesterday, 11:54 PM
    0 responses
    29 views
    0 likes
    Last Post nandhumca  
    Started by nandhumca, Yesterday, 11:51 PM
    0 responses
    28 views
    0 likes
    Last Post nandhumca  
    Started by ezrollin, Yesterday, 11:48 PM
    2 responses
    29 views
    0 likes
    Last Post ezrollin  
    Started by jjanguda, Yesterday, 10:15 PM
    1 response
    29 views
    0 likes
    Last Post NinjaTrader_ChrisSch  
    Working...
    X