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

How to access bar data before OnBarUpdate() begins

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

    How to access bar data before OnBarUpdate() begins

    I apologize in advance for what is probably a question answered elsewhere, but I have tried searching, and I can't think up the right search term.

    I want to access bar data, such as highs, lows, timestamps, etc. from all/any bar in the data series of my instrument before OnBarUpdate() begins, or possibly as a first act once it begins. Max() and Min() look back a specified number of bars from whatever bar OnBarUpdate() is processing. OnBarUpdate() does not seem to be able to look ahead, but the data for all the bars that are in the chart already exists, so data from the most recently formed bar/last bar in the chart should be available when OnBarUpdate() begins on the first bar. And for all the bars in between.

    So, to sum up, I want to know how to access the data for all the bars in the chart before OnBarUpdate() begins going through the bars.

    An example returning the date of the last bar in a chart would be very helpful.

    And also, just out of curiosity, can OnBarUpdate() be called more than once in an indicator?

    Thanks for your help,
    Klopfgeist

    #2
    Hello there, unfortunately I'm not sure I understand your question. OnBarUpdate() is called whenever there is some bar action, like after a bar completes building if Calculate On Bar Close is set to true. If it is set to false, then OnBarUpdate() will be called once for every bar before the live data, and then on every tick for the incoming data.

    OnBarUpdate() will always refer to the most current bar, and you can get the data from whatever bar you want by referencing the bars back value. To get the high 4 bars back, for example, you could call High[4].

    OnBarUpdate() is not called for every bar on a chart every time a new bar is formed. If COBC = true, there will be one OnBarUpdate() for each bar on the chart.

    You cannot access ("I want to know how to access the data for all the bars in the chart before OnBarUpdate() begins going through the bars") a bar before OnBarUpdate() "creates" the bar, because it does not exist yet.

    OnBarUpdate() isn't necessarily "called", the method is "called" whenever there is an update to the bar. It would not make sense to duplicate the OnBarUpdate() method because then the same exact events would occur twice in your indicator.

    Lastly, to get the date of the last bar on a chart, you can reference Time[0]:
    Code:
    DateTime mostRecentBar = Time[0];
    AustinNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by usazencort, Today, 01:16 AM
    0 responses
    1 view
    0 likes
    Last Post usazencort  
    Started by kaywai, 09-01-2023, 08:44 PM
    5 responses
    603 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by xiinteractive, 04-09-2024, 08:08 AM
    6 responses
    22 views
    0 likes
    Last Post xiinteractive  
    Started by Pattontje, Yesterday, 02:10 PM
    2 responses
    21 views
    0 likes
    Last Post Pattontje  
    Started by flybuzz, 04-21-2024, 04:07 PM
    17 responses
    230 views
    0 likes
    Last Post TradingLoss  
    Working...
    X