Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Missed events using IsFirstTickOfBar with OnPriceChange

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

    Missed events using IsFirstTickOfBar with OnPriceChange

    If a strategy is running in mode Calculate.OnPriceChange, and OnBarUpdate() contains a conditional statement using IsFirstTickOfBar, will first bar tick events be missed?

    My concern is that OnBarUpdate() will be called when price changes but that is not necessarily coincident with the first tick of the bar.

    The help guide for IsFirstTickOfBar seems to imply that there would not be missed events, but thinking about it I don't see why that would be true.
    https://ninjatrader.com/support/help...ttickofbar.htm

    Code:
    // On a tick by tick strategy the only way you know when a bar is closed is when
    // the IsFirsTickOfBar is true.
    protected override void OnBarUpdate()
    {
        // Only process entry signals on a bar by bar basis (not tick by tick)
        if (IsFirstTickOfBar)
        {
            if (CCI(20)[1] < -250)
                  EnterLong();
            return;
        }
     
        // Process exit signals tick by tick
        if (CCI(20)[0] > 250)
            ExitLong();
    }
    In the above example taken from the help guide, if the strategy is running Calculate.OnPriceChange, there would be some missed entries. Can you confirm that this is not the case, and include the reason why.

    #2
    Hello Camdo,

    Thanks for opening the thread.

    NinjaScripts will always be able to calculate on bar closes and IsFirstTickOfBar allows the NinjaScript author to capture those events when Calculate is not set to OnBarClose.

    An incoming tick that opens a new bar signals the close of the previous bar, and we will see iterations for IsFirstTickOfBar for Calculate.OnPriceChange and Calculate.OnEachTick. Since Calculate.OnPriceChange is the middle ground between Calculate.OnEachTick and Calculate.OnBarClose, it would cause issue if bar closes were excluded from the NinjaScript's processing.

    To observe the behavior, we could enable Tick Replay from the Control Center under Tools > Options > Market Data > Show Tick Replay, and then enable Tick Replay in the Data Series window of our chart. From here we can enable an indicator that is set to Calculate.OnPriceChange with the following code:

    Code:
    protected override void OnBarUpdate()
    {
    	if(IsFirstTickOfBar)
    		Print(CurrentBar);
    }
    In the output window we will see consecutive prints for each CurrentBar iteration.

    Please let me know if we can be of additional help.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    52 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