• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 morrnel, Today, 01:13 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_Jim  
    Started by babouin77, Today, 12:41 PM
    6 responses
    16 views
    0 likes
    Last Post babouin77  
    Started by punkiy2111, Today, 12:17 PM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_Tabor  
    Started by GLFX005, Today, 11:22 AM
    6 responses
    30 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by mintxom, Today, 10:25 AM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Melissa  
    Working...
    X