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

Calculate on each tick makes the indicator lag 1 tick if relying on onMarketData

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

    Calculate on each tick makes the indicator lag 1 tick if relying on onMarketData

    When developing tick by tick indicators if you set Calculate on each tick, the indicator is calculated tick by tick but the information of the last tick will be missing. That is if you rely on calculations done in the onMarketData event method.

    The indicator is updated in the onBarUpdate method. When Calculate = on each tick, onBarUpdate is updated every tick. The problem is that onBarUpdate method is called BEFORE the onMarketData method. If your indicator relies on intrabar calculations done in the onMarketData method your indicator will always be wrong because those calculations are still not updated with the last tick info.

    You can test this behavior using the simple indicator attached to this thread. The idea is simply to log some string inside the onBarUpdate method and inside the onMarketData method. You will see that the onBarUpdate executes always before the onMarketData for every tick trade (tick type = last). This is not a multithreading race issue. The log prints statements in the order they were requested to be printed, so log order reflects execution order. Besides I've printed also the managed thread id and it's always the same.

    In the NT8 docs it says

    The OnMarketData() method is guaranteed to always be called before OnBarUpdate()


    which is not true and it contradicts this other fragment in the docs

    Calculate.OnEachTick

    OnMarketData and OnBarUpdate call for each tick used to build the bar

    • 1 OnBarUpdate event on CurrentBar 0
    • Followed by 1 OnMarketData event
    • 1 OnBarUpdate event on CurrentBar 0
    • Followed by 1 OnMarketData event
    • 1 OnBarUpdate event on CurrentBar 0
    • Followed by 1 OnMarketData event
    • 1 OnBarUpdate event on CurrentBar 0
    • Followed by 1 OnMarketData event
    • ...etc.




    My understanding is onBarUpdate should be called always AFTER onMarketData to give the indicator a chance of updating with the most recent tick info.

    Right now, onBarUpdate is updated BEFORE onMarketData which kind of defeats the whole purpose of calculating the indicator tick by tick, and thus making Tick Replay almost useless.

    Can some expert NT8 developer confirm this issue or guide me on what I might be misunderstanding, please?

    This thread a summary of my findings in these two other forums threads:

    Attached Files

    #2
    Hello joanrocagas,

    Thank you for your post.

    I tested out your code as well as my own and see that the OnMarketData() information may not be accurate. I will follow up with your Product Management team on this. Thank you again for your information.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Barry Milan, Today, 10:35 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by WeyldFalcon, 12-10-2020, 06:48 PM
    14 responses
    1,428 views
    0 likes
    Last Post Handclap0241  
    Started by DJ888, Yesterday, 06:09 PM
    2 responses
    9 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by jeronymite, 04-12-2024, 04:26 PM
    3 responses
    40 views
    0 likes
    Last Post jeronymite  
    Started by bill2023, Today, 08:51 AM
    2 responses
    16 views
    0 likes
    Last Post bill2023  
    Working...
    X