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 traderqz, Today, 09:44 AM
    2 responses
    4 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by stafe, 04-15-2024, 08:34 PM
    8 responses
    40 views
    0 likes
    Last Post stafe
    by stafe
     
    Started by rocketman7, Today, 09:41 AM
    2 responses
    6 views
    0 likes
    Last Post rocketman7  
    Started by rocketman7, Today, 02:12 AM
    7 responses
    31 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by guillembm, Yesterday, 11:25 AM
    3 responses
    16 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X