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

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.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Waxavi, Today, 02:10 AM
    0 responses
    6 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Started by TradeForge, Today, 02:09 AM
    0 responses
    11 views
    0 likes
    Last Post TradeForge  
    Started by Waxavi, Today, 02:00 AM
    0 responses
    2 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Started by elirion, Today, 01:36 AM
    0 responses
    4 views
    0 likes
    Last Post elirion
    by elirion
     
    Started by gentlebenthebear, Today, 01:30 AM
    0 responses
    5 views
    0 likes
    Last Post gentlebenthebear  
    Working...
    X