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 NullPointStrategies, Today, 05:17 AM
    0 responses
    53 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X