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 sjsj2732, 03-23-2026, 04:31 AM
    0 responses
    73 views
    0 likes
    Last Post sjsj2732  
    Started by NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    313 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    310 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    148 views
    1 like
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    111 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Working...
    X