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

Question Regarding the Timing of Various Event Handlers

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

    Question Regarding the Timing of Various Event Handlers

    I have been running some tests and I have a few ideas about how the timing of events work in NT 8. I am hoping that someone from the NT support team can confirm this.

    If I run print statements from the various event handlers looking at price changes here is what I am seeing.

    1. Bar Update Event: Print whenever GetCurrentBid() or GetCurrentAsk() != a variable I created to hold a prior bid or ask price from the prior bar update.

    2. OnMarketDepth Event: Print whenever the same occurs. Example such as:

    if (marketDepthUpdate.MarketDataType == MarketDataType.Ask && marketDepthUpdate.Operation == Operation.Update && GetCurrentAsk() == marketDepthUpdate.Price)

    {
    if(VariablePriorPriceUpdate != marketDepthUpdate.Price )
    {
    Print( "This is where the update occurs");
    }
    }


    3. OnMarketData Event: Print Whenever the same occurs. Example such as:

    if (marketDataUpdate.MarketDataType == MarketDataType.Last)
    {
    if (marketDataUpdate.Price == marketDataUpdate.Ask)
    {
    {
    If( VariablePriorPriceUpdate != marketDataUpdate.Ask)
    {
    Print("This is where the update occurs")
    }
    }
    }
    }


    So in this example lets assume that all 3 event handlers are tracking the same price level change from ask = 2000 to ask = 1999.75. Also lets assume that I am running the OnBarUpdate on less than a 10 tick time series, so it will fire fairly quickly. What I have noticed, is that the timing of all 3 events typically runs like this.

    1. Bar Update runs first.
    2. OnMarketDepth runs second
    3. OnMarketData runs third.

    When I see the print times, and associated bid and ask volumes from the OnBarUpdate, I will always need to run through around 20-100 ask depth / bid depth updates before I get to the exact same matching bid and ask volume.

    I have enclosed an example of the data prints that I have mentioned above. In this data example you can clearly see what I am referring to where the OnBarUpdate runs ahead of the OnMarketDepth and OnMarketData events.

    Here are my questions:

    1. Can you confirm that my understanding is correct and that what I am seeing aligns with the way it is designed.

    2. Can you explain why the OnBarUpdate event catches price level changes first every time? To me, this doesn't quite add up. Considering that the OnMarketDepth event has a sample rate hundreds of times more granular it stands to reason that this event handler would observe price changes first, yet, it still lags behind the less granular OnBarUpdate event which samples the data far less often.

    3. If someone was building a low latency strategy with the aim to capture price change events as quickly as possible it appears from my research the fasted event handler would be the OnBarUpdate event. Can you confirm this.

    Thanks,

    Ian
    Attached Files

    #2
    Hello iantg,

    Thanks for opening the thread, excellent questions.

    1. Can you confirm that my understanding is correct and that what I am seeing aligns with the way it is designed.
    Your understanding and observations are correct. However, it should be noted that it is expected for OnMarketData() events to occur after OnBarUpdate() and OnMarketDepth() events should be treated as independent from OnBarUpdate() and OnMarketData() since the data handled is specific to level 2.

    2. Can you explain why the OnBarUpdate event catches price level changes first every time? To me, this doesn't quite add up. Considering that the OnMarketDepth event has a sample rate hundreds of times more granular it stands to reason that this event handler would observe price changes first, yet, it still lags behind the less granular OnBarUpdate event which samples the data far less often.
    Building off of my answer to point 1, it is simply the expected behavior of the design to update OnBarUpdate() before OnMarketData(). (This is documented in the help guide here.) Through my own tests against a 1 tick data series, I see OnMarketDepth() is not guaranteed to be before or after OnBarUpdate(). I do not see the 15+ second delay you are reporting.

    Demo: https://www.screencast.com/t/w6Ghx7cHa

    3. If someone was building a low latency strategy with the aim to capture price change events as quickly as possible it appears from my research the fasted event handler would be the OnBarUpdate event. Can you confirm this.
    Yes, from your testing, mine, and what is documented, it would be ideal to use OnBarUpdate().

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Jim,

      Thank you for reviewing my questions and confirming that my understanding was about right. I had to do a double take when I saw how the actual data was printing out, because I just assumed that since OnMarketDepth was more granular it would update quicker than the bar update, but this is not the case.

      *** Note: It doesn't always lag behind by 10-15 seconds, I just provided a more extreme case. In most cases this is within a few seconds, but it is always behind, which I found strange.

      Thanks,

      Ian

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by poplagelu, Today, 05:00 AM
      0 responses
      3 views
      0 likes
      Last Post poplagelu  
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,407 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      98 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      8 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      161 views
      0 likes
      Last Post loganjarosz123  
      Working...
      X