Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Processing Historical Bars while CalculateOnBarClose=False

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

    Processing Historical Bars while CalculateOnBarClose=False

    With regards to OnBarUpdate,

    When COBC=True, the BarsAgo index of the most recently closed bar is 0.
    When COBC=False, the BarsAgo index of the most recently closed bar is 1.

    Ok, during the time period in which Historical bars are processed by OnBarUpdate,
    what is the correct BarsAgo index for the most recently closed bar?

    The essential questions are,

    1. When Historical is true, should the code ignore COBC setting and always use 0?
    2. When Historical is False, should the code always use '0' for COBC=True and '1' for COBC=False?

    For example, the above two statements can be expressed in code with,

    Code:
    public int FirstBarsAgo {
        get {
            return Historical ? 0 : CalculateOnBarClose ? 0 : 1;
        }
    }
    When processing OnBarUpdate, does the code above give the correct BarsAgo index for the
    most recently closed bar for all combinations of Historical and CalculateOnBarClose?


    #2
    Hello bltdavid,

    Thank you for your post.

    If historical is true, it will always calculate OnBarClose.

    You would want to test this custom logic, but at first glance your code would give the correct BarsAgo index. You could do something similar by using FirstTickOfBar, which is only true when you're not using OnBarClose. So you could change the index you're using depending on whether FirstTickOfBar is true and not have to use the above code.

    Here's a link to our help guide that goes over FirstTickOfBar:



    Please let us know if we may be of further assistance to you.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    133 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    75 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    117 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    113 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    90 views
    0 likes
    Last Post CarlTrading  
    Working...
    X