Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question about close price in a strategy

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

    Question about close price in a strategy

    Hi - I'm developing a strategy and have the following question:

    I'm not sure if the Close is the last trading price while current bar is updating, or the price awaiting current bar is closed.

    I'm using additional data series in my strategy. Let's say if I have some conditions that need 1) the last trading on 5-min chart is above MA. and 2) the close price on 1-min chart is above MA when the 1-min bar is completely closed. I'm not sure how to correct code this when I refer price in my method.

    In another word, what does "Close" refer to on current bar? Is it the last trading price or the close price awating the bar is closed? How do I distinguish them when coding?

    Thank you very much!

    #2
    Hello HiddenPhilosopher,

    Thanks for your post.

    The answer very much depend on what calculate setting is being used as well as if you are looking at historical data or Live data.

    When using Calculate.OnBarClose, Close[0] will be the just closed bar and the currently forming bar is not known to the strategy as the strategy code is not run until the current forming bar closes and when that bar closes the bars ago index[0] switches to that bar and the previous bar would now be [1]. Please Note that this is also what happens on all historical data processing regardless of the Calculate setting.

    When using Calculate.OnPriceChange or Calculate.OnEachTick, Close[0] will be the current price of the currently forming bar (live or Market replay data only). The just closed bar will be [1], so this shows you that with either of these two calculate modes, the bars ago shifts forward. In the case of Calculate.OnEachTick, your script will be executed once for every incoming tick (you can get several ticks at the same price) while with Calculate.OnPriceChange your script will run on every change in price (which is less resource intensive than Calculate.OnEachTick). Keep in Mind that when you apply a script that uses either of these calculate modes that any historical data will only be process as if it were set to Calculate.OnBarClose. So these calculate modes only apply to live or playback with market replay data.

    For the multi time frame questions, please see the help guide section: https://ninjatrader.com/support/help...nstruments.htm this will provide insight to all of the considerations for programming and provides an illustration of what data is referenced in the different calculate modes.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    90 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    137 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    120 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X