Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Update()

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

    Update()

    NT Team,

    When ensuring an Indicator is updated and suitable for use in a Strategy please advise if the below simple code is inadvisable and why.

    Code:
    public class MyStrategy: Strategy
    {
      private MyIndicator _myIndicator;
    
      protected override void OnStateChange()
      {
        if (State == State.Configure)
        {
          _myIndicator = MyIndicator();
        }
      }
    
      protected override void OnBarUpdate()
      {
        _myIndicator.Update();
        //etc
      }
    }
    Referencing :
    - UserGuide (Update()),
    - Reference Sample (Indicator: Exposing indicator values that are not plots), and
    - @suprsnipes post (Using exposed variable from indicator within strategy)

    Would the below code work to ensure MyIndicator is updated?
    Code:
    public class MyIndicator: Indicator
    {
      private boolean _isUpdated;
    
      protected override void OnStateChange()
      {
      }
    
      protected override void OnBarUpdate()
      {
        _isUpdated = true;
        // other code
      }
    
      public boolean IsUpdated
      {
        get { Update(); return _isUpdated }
      }
    }
    As always, thanks
    Shannon

    #2
    Hello,

    Update() is intended as a rare use-case method for specific circumstances. For general purposes, you can be confident that calling an indicator method within OnBarUpdate() in a strategy will result in the indicator plot values being up to date, especially if you are using an index to specify a particular bar (example: _myIndicator.myPlot[0]).

    Also, note that Update() is called behind the scenes any time you reference the Values series of a hosted indicator. So, for example, if you refer to _myIndicator()[0], then Update() is being called before a value is provided, to ensure that it is always up to date.

    If you need more granular updates for your indicator, the best practice is to switch the calculation mode of the strategy itself. If you find that end-of-bar updates are not quick enough for the hosted indicator, consider switching the strategy's calculation mode to "On Each Tick," which should ensure that the hosted strategy is up to date, as well.

    If you'd like to explain a bit more about exactly what you are trying to accomplish, I may be able to provide some more insight. But if you are just looking to make sure it's updated so that you have reliable plot data to work with, then that should not be an issue.
    Last edited by NinjaTrader_DaveI; 07-30-2015, 10:35 AM.
    Dave I.NinjaTrader Product Management

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Waxavi, Today, 02:00 AM
    0 responses
    2 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Started by elirion, Today, 01:36 AM
    0 responses
    4 views
    0 likes
    Last Post elirion
    by elirion
     
    Started by gentlebenthebear, Today, 01:30 AM
    0 responses
    4 views
    0 likes
    Last Post gentlebenthebear  
    Started by samish18, Yesterday, 08:31 AM
    2 responses
    9 views
    0 likes
    Last Post elirion
    by elirion
     
    Started by Mestor, 03-10-2023, 01:50 AM
    16 responses
    391 views
    0 likes
    Last Post z.franck  
    Working...
    X