Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    595 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    554 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X