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

Getting the right most bar

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

    Getting the right most bar

    Hi,
    Something seemingly simple has me tied up in knots.
    When my indicator starts it seems that OnBarUpdate is called for each bar once.
    How do I know when the series of events is completed for the first time?
    In other words, in my OnStartup I print Bars.Count. Lets assume it comes out to 850.
    In my OnBarUpdate event, in theory, I should be able to say something like:
    if(Bars.Count - 1 == CurrentBar)
    {
    // do my thing
    }
    However, for some reason, CurrentBar never reaches Bars.Count -1, it only gets to Count - 2!
    What's with the missing bar? Is it safe to say that if CurrentBar == Bars.Count - 2 then I am dealing with the "current" rightmost bar?
    While I'm at it, once a bar is "closed", does OnBarUpdate ever get called again for it?
    Could I safely say if Close.Count != Bars.Count then I know that I am on the rightmost bar.
    This seems more difficult than it should be.
    Thanks ... Ed

    #2
    Hello Ed,

    Thank you for your post.

    Bars.Count is going to start its count at 1 then count up.
    CurrentBar starts its counting at 0.

    Additionally, are you running this with CalculateOnBarClose set to true or false?
    With this set to true you will get the second right most bar as we are waiting for the bar being built to close.
    With it set to false then we are calculating on each incoming tick of data which would return the right most bar.

    OnBarUpdate() gets called depending on the CalculateOnBarClose. Again, if set to true, then OnBarUpdate will get called when a bar closes, when set to false, then OnBarUpdate will get called with each incoming tick of data.
    Cal H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    3 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    18 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    1 view
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    6 views
    0 likes
    Last Post Javierw.ok  
    Started by timmbbo, Today, 08:59 AM
    2 responses
    10 views
    0 likes
    Last Post bltdavid  
    Working...
    X