Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Instantiation of Indicators

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

    Instantiation of Indicators

    Can anyone tell me at what time(s) Indicators (and for that matter Strategies) are instantiated?
    I have been assuming that a new Indicator object is created each time an Indicator is actually applied to a Chart (or used in some other framework, but right now I am focusing on Charts).
    And a related question, are private variables instance variables or class variables (akin to static in Java). Again I have been assuming that private variables are instance variables.
    Behavior of event processing when the same indicator is applied to two instruments (each in a separate panel on a Chart) now leads me to think my assumptions were not correct.
    A clear statement of when Indicator objects are instantiated would save a lot of tedious time with the VisualStudio debugger.
    Thanks

    #2
    Hello TurtleBeach,

    Thank you for your inquiry.

    Indicators and strategies are instantiated upon opening the Indicator window for indicators and the Strategy window for strategies on a chart. To demonstrate this, you can place a Print() in the if (State == State.SetDefaults) statement inside of the OnStateChange() method of your script. You will then see your script print upon opening the Indicator/Strategy window.

    To learn more about when these various states occur, I would suggest taking a look at the NinjaTrader 8 help guide at this link: http://ninjatrader.com/support/helpG...tatechange.htm

    Private variables are instance variables. Class variables would not be private and would utilize the static modifier, i.e.:
    Code:
    static int theNumber = 42;
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the information about Indicator instantiation.
      But your answer leads to further questions (as noted in the documentation, the SetDefaults **event** occurs multiple times so it is not actually an indication of object creation, other than that an object does exist).
      So to rephrase my original question, during a NinjaTrader Session (starting the Program, doing various things, ending the program) is there only ONE instantiation of each Indicator (or, if the Indicator dialog is never opened, Indicators are not instantiated)?

      As a suggestion to the NT developers, I would like to see an OnCreation event that truly occurs ONLY ONCE for any object that is created; similarly, an OnDeletion that occurs only when an object is about to be destroyed (since OnTermination is already taken and is not unique). These are really the two places initialization and other housekeeping can be safely done - especially since it appears I have to build in logic in every event to determine which chart/instrument the event applies to.
      Thanks.

      Comment


        #4
        Hello TurtleBeach,

        Thank you for your patience.

        Indicators can be instantiated multiple times. Two examples are by opening the indicators window and adding the indicator to the chart.

        State.SetDefaults is called once the object is created. This looks to occur multiple times as different instances of an indicator can be created more than once.

        Please, let us know if we may be of further assistance.
        Zachary G.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mestor, 03-10-2023, 01:50 AM
        16 responses
        388 views
        0 likes
        Last Post z.franck  
        Started by rtwave, 04-12-2024, 09:30 AM
        4 responses
        31 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by yertle, Yesterday, 08:38 AM
        7 responses
        29 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by bmartz, 03-12-2024, 06:12 AM
        2 responses
        22 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by funk10101, Today, 12:02 AM
        0 responses
        7 views
        0 likes
        Last Post funk10101  
        Working...
        X