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

CPU Usage with Indicator Calculations using OnPriceChange calculations

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

    CPU Usage with Indicator Calculations using OnPriceChange calculations

    NTS,

    I believe Indicator calculations can be CPU expensive/exhaustive when using OnPriceChange calculations and when lots of CPU resources are being used.

    I have some questions for clarification:

    > how often do indicators re-calculate with OnPriceChange? Do they re-calculate on every price change or just when indicator or strategy calls an indicator value? I believe NT8 only computes indicator values when indicator or strategy calls for an indicator value ie/ OnBarUpdate: if price greater than "Trendline" && indicator[0] > "value.

    > More specifically, if I call indicator value[1] from one bar ago will NinjaTrader 8 recalculate or compute indicator value every time or are indicator values from [1] one bar ago treated as static values and NT8 does not recalculate or compute indicator value as it has already been done? Further, what is quicker and less CPU expensive (a) calling indicator values from previous bars [1][2][3] or calling private double ?

    In my situation I am calling indicator values for previous bars [1][2] allot in my code and want to ensure NT8 is not recalculating or computing the indicator values otherwise I will just create private double and call that double.

    Appreciate the clarification to best manage CPU resources.

    Blairski

    #2
    Hello Blairski,

    OnPriceChange is more CPU intensive than OnBarClose (as the logic is being run on every price change instead of once when the bar closes) but is less CPU intensive than OnEachTick.

    When Calculate is OnPriceChange indicators will update and run OnBarUpdate every time the price changes. (Even if the indicator is not called for that bar)

    Series are updated when OnBarUpdate runs, not when you call an indicator or use a series with a barsAgo index. Using a series with a barsAgo index will cause the indicator to update (as it will have already updated)

    When calling a public double (instead of a public Series<double>) in an indicator, typically Update() is called to update OnBarUpdate(). This would cause the indicator to update.
    https://ninjatrader.com/support/help...nt8/update.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea, NTS,

      Thanks much for quick response. A further question(s) for clarification:

      You are saying that when Calculate is OnPriceChange indicators will update and run OnBarUpdate every time the price changes. Can you clarify and confirm that if price changes 1 million times within the 5 minute bar; every indicator configured to strategy will recalculate and update 1 million times within that 5 minute bar[0]? That sounds very CPU expensive! Does it matter if the indicator is not plotted in the strategy? Are there any situations where NT8 would not re-calculate or computer indicator values for index[0] with Calculate set to "OnPriceChange" every single price change?

      In my situation, I want my strategy to run OnPriceChange but I only want indicators to calculate for [0] when called upon.

      Comment


        #4
        Hello Blairski,

        If the price changes a million times in a 5 minute bar, which would likely be billions of ticks, yes, ninjatrader would be trying to update for all of them. The price would have to change, and go up and back down.
        I get this is a theoretical, but yes this would drive high CPU usage. Further, computers and servers that actually run the market would also likely be affected. That's a massive amount of data that has to be transmitted and processed. Even on days where there is just normal high volume, users with scripts running OnEachTick (way more so that OnPriceChange) can have CPU issues on low performance hardware.
        https://ninjatrader.com/support/foru...35#post1055235

        OnPriceChange would be the only way to keep a script updating to real-time information. How can the script react if its not getting the information and running the data through the logic? OnBarClose would be much more efficient, in that it only runs through the logic when the bar closes, but this cannot react to fast changes in the market.

        That said, take a very simple script like the SMA. If the price ticks up, do you want the new SMA value or do you want to wait a while?

        Or lets say there are a million updates and the indicator isn't updating. Then you call the indicator and it now must process a million updates all at once.

        Your custom script could choose to run logic every few price updates if you wanted to conserve CPU. Or you could call a custom public method from the host script that runs the logic only when called with TriggerCustomEvent to update the series. The indicator would keep updating, but you don't have to run your logic.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by SydniBuck, Today, 12:54 AM
        0 responses
        6 views
        0 likes
        Last Post SydniBuck  
        Started by ketostrongbuyno, Yesterday, 11:50 PM
        0 responses
        10 views
        0 likes
        Last Post ketostrongbuyno  
        Started by ReinaKutch, Yesterday, 11:08 PM
        0 responses
        9 views
        0 likes
        Last Post ReinaKutch  
        Started by JackyThur, Yesterday, 10:51 PM
        0 responses
        10 views
        0 likes
        Last Post JackyThur  
        Started by sjeffblack, Yesterday, 01:22 PM
        2 responses
        30 views
        0 likes
        Last Post sjeffblack  
        Working...
        X