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

When to use Update() Method

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

    When to use Update() Method

    Hello,

    I am trying to understand when it is necessary to call the Update() Method for Properties being exposes from an Indicator.

    I have an indicator that exposes a List<Objects>. The List is populated from logic within the same indicator. I expose the Object with a simple getter :
    Code:
    [Browsable(false)]
            [XmlIgnore]
            public List<MWBSTRedWavePattern> L_RedWavePatterns
            {
                get {  return RedWavePatterns; }
            }
    While I don't believe the Update() Method is required prior to the return in this scenario, I want to understand when it is required?

    Thanks,

    #2
    Hello tornadoatc,

    Update() works similar to TriggerCustomEvent() to ensure all series are up-to-date and OnBarUpdate() for all hosted scripts has been run, but instead of being from another thread, this is from a calling host script.
    https://ninjatrader.com/support/help...nt8/update.htm

    If you don't need information from OnBarUpdate() or from a series, this is not necessary to call.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello tornadoatc,

      Update() works similar to TriggerCustomEvent() to ensure all series are up-to-date and OnBarUpdate() for all hosted scripts has been run, but instead of being from another thread, this is from a calling host script.
      https://ninjatrader.com/support/help...nt8/update.htm

      If you don't need information from OnBarUpdate() or from a series, this is not necessary to call.
      So my understanding is that any exposes property that is not populated from the Values[x] should call Update() from getter. If values are already upto date then no performance penalty as it would not be called if properties are up to date.

      Is this correct?

      Furthermore, this sentence from the link generates questions regarding realtime vs historical: "When indicators are embedded (called) within a NinjaScript strategy, they are optimized to calculate only when they are called upon in a historical backtest." So what is the difference in behavior between historical and realtime bars regarding the need for Update()?

      Thanks,

      Comment


        #4
        Hello tornadoatc,

        If the property is set in OnBarUpdate() and is not a plot, then use Update() to run OnBarUpdate() to update the value before it is returned.

        In historical, an indicator doesn't actually run through the historical data until it is called and then it will process all of the historical data (pretty much at once) for efficiency. In real-time it will calculate even when not called.

        However, if the script needs a value updated in OnBarUpdate() before being returned, use Update() in both historical and real-time.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TheTradingMantis, 01-19-2023, 02:05 AM
        42 responses
        908 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by _Zero_, 04-10-2020, 03:21 PM
        144 responses
        7,891 views
        6 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Richozzy38, Yesterday, 01:06 PM
        7 responses
        28 views
        0 likes
        Last Post Richozzy38  
        Started by swjake, Today, 12:04 PM
        5 responses
        16 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by forrestang, Today, 01:41 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Erick  
        Working...
        X