• 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

Is Close[0] the current bar, or the last bar?

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

    Is Close[0] the current bar, or the last bar?



    Hi there,

    Within OnBarUpdate, is Close[0] the current bar that's being formed, or the last completed bar? If it's the bar being formed, then the value of Close[0] would vary with each tick change, correct?

    Thanks


    #2
    Hello timmbbo,

    Thanks for your post.

    The answer depends on the Calculate setting AND if you are looking at historical data OR real time (or market replay) data.

    For historical data (not including market replay), when your script loads, it will process the bars in sequence from the beginning "days to load" specified in the data series of the chart. The script will be run once per bar and will perform based on that the bar index of [0] is the just closed bar. So as each bar is processed it becomes the next [0]. This is true regardless of the Calculate setting sos please keep this in mind going forward.

    When the historical data has been processed and assuming you are connected to live data (or playback>MarketReplay data), the calculate setting of the script can change the bar references once it is processing the real time data as follows:

    Calculate.OnBarClose, in live/replay data, [0] is the latest just closed bar, your script will run once at the end of the bar, the script does not know of the currently forming bar until it closes and the index [0] shifts to the just closed bar, the previously closed bar would now be [1]. Your code would execute exactly the same as it does historically.

    Calculate.OnPriceChange, in live/replay data, Close[0] is the current price of the currently forming bar, the Close, High and Low values change as the price changes in the currently forming bar until it closes. [1] will be the just closed bar in this mode. Your script will execute on every change in price while the currently forming bar changes price which means again that Close[0], High[0] and Low[0] can change (Open[0] will not change as it is set once on the first tick).

    Calculate.OnEachTick, in live/replay data, Close[0] is the current price of the currently forming bar, the Close, High and Low values change as the price changes in the currently forming bar until it closes. Note: In this mode your code will execute on each incoming tick which may be exactly the same price as the previous tick(s). Like OnPriceChange, the currently forming bar prices of Close, High, Low will change until the bar closes. The bar index of [1] is the just closed bar.

    Reference: https://ninjatrader.com/support/help...?calculate.htm
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by aviat72, 04-26-2020, 09:41 PM
    10 responses
    89 views
    0 likes
    Last Post kissandfly  
    Started by healthooa, Today, 01:28 AM
    0 responses
    7 views
    0 likes
    Last Post healthooa  
    Started by superkolleech, Today, 12:46 AM
    0 responses
    8 views
    0 likes
    Last Post superkolleech  
    Started by harjinderjit, Yesterday, 08:24 PM
    0 responses
    20 views
    0 likes
    Last Post harjinderjit  
    Started by Againmain1, Yesterday, 03:04 AM
    1 response
    26 views
    1 like
    Last Post NinjaTrader_ShawnB  
    Working...
    X