Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator Initialize - Dispose

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

    Indicator Initialize - Dispose

    Hello,

    I would like to understand better the sequence of Initialize and Dispose of an Indicator in NT7.

    I have one chart window open and on this chart MyIndicator is loaded.

    So it shows up as MyIndicator(ES 12-09,1Min,..)

    fine.

    Now I put some Print statements in Dispose and Initialize

    Then I change the symbol in the chart window from ES 12-09 to FDAX 12-09.

    From the Print statements I get.

    MyIndicator(FDAX(12-09).Dispose ( ????? My expectation: MyIndicator(ES 12-09)
    MyIndicaor(FDAX(12-09).Initialize
    MyIndicator(FDAX(12-09).Dispose

    Now I am puzzled:

    I would expect the first .Dispose to be associated with the (ES 12-09) Instrument, which is the one beeing disposed.


    Could you please enlight what is happening?


    P.S. Please enable debugging for the scripts, it is almost impossible to debug only via Print statements.

    Best regards

    Andreas

    #2
    Hi,

    This is not documented but we no longer advise using Dispose(). Please use the following to dispose of your resources.

    protected override void OnTermination()
    {
    // Dispose logic here
    }
    RayNinjaTrader Customer Service

    Comment


      #3
      Thank you, I will try...

      just to know: Same for Strategies, OnTermination() instead of Dispose()


      what about calling the base class implementation, necessary? i guess no longer needed otherwise you could well stick with Dispose


      OnTermination(){

      base.OnTermination().... needed?
      }


      Best regards
      andreas

      Comment


        #4
        Right it's not needed. OnTermination only would hold your "custom cleanup" code.

        Comment


          #5
          OK,

          so OnTermination is called before Dispose, right?

          Probably you want to clean up as much as possible outside the GC Dispose?


          My problem before was Instrument.FullName related.
          Same as in Initialize, Instrument.MasterInstrument.Name now.

          regards

          Comment


            #6
            What exact issue do you see?

            Comment


              #7
              Dierk,

              please read again my first post , the behaviour with OnTermination is the same as with Dispose.

              First issue:

              My point is:

              On a chart window , when I change the instrument from ES 12-09 to FDAX 12-09 I expect something like this:

              MyIndicator(ES 12-09).OnTerminate
              MyIndicator(FDAX 12-09).Initilialize


              Instead all calls are with the new instrument, hence I see
              MyIndicator(FDAX 12-09).OnTerminate.
              MyIndicator(FDAX) Initialize
              This does not make sense to me, especially I need the correct instrument informnation because I save and load instrument relative data in Initialize and OnTerminate.

              Second issue;

              How can I get the instrument.FullName in Initialize()?
              GetBarsInProgress is not allowed, so this means that there are changes due to the multinstrument charts,
              any doc around or should I just dissassmble ...?
              I get only MasterInstrument.Name and the expiry, so I can by hand construct me the Fullname, but does all this make sense?
              What am I missing?


              Best regards,

              Sorry if I am less clear than usual , but I am sick and therfore a bit confused.

              Comment


                #8
                on 1) Not sure why you keep referring to particular instruments. This is irrelevant. The actual indicator instance is relevant and nothing else. If you wanted to understand the sequence of events, then I suggest marking your indicator instances so that they would be unique.

                on 2) Unfortunately there is no way to retrieve the instrument name on Initialize() since the actual instrument/series is assigned AFTER Initialize(). This was the case NT6.5 and nothing has changed since.

                Hope you'll feel better soon

                Comment


                  #9
                  OK,

                  finally used the Visual Studio Debugger on NT7, and what I need can be done inside the

                  string ovverride ToString()

                  function.

                  Andreas

                  Comment


                    #10
                    OnTermination()

                    Hello,
                    i dont understand everithing connected to this.
                    In help:

                    - This is what we want users to overload to dispose of their resources
                    - Do not overload Dispose() any longer
                    - Reason that dispose could be much later that you might expect
                    - Any reference sample updates required

                    In code:
                    // Summary:
                    // Overload this method to handle the termination of an indicator. Use this
                    // method to dispose of any resources vs overloading the Dispose() method.

                    1) question: the code is about indicator. Is it right for the strategy as well?
                    2) question: i did not find any exact sample, how to use it corretly. Can you help me? Now, this in the strategy, how would that be in OnTermination() method?

                    Code:
                     
                    public override void Dispose()
                    {
                      try
                      {
                        // Disposes resources
                        if (MyClass1 = null)
                        {
                            MyClass1.PropertyChanged -= MyClass1 _PropertyChanged;
                            MyClass1.Dispose();
                        }
                     
                        if (MyClass2 != null)
                          MyClass2.Dispose();
                      }
                      ...
                    }
                    Thanks in advance, Tamas

                    Comment


                      #11
                      Same as for a strategy.

                      Just replace:

                      public override void Dispose()

                      with

                      public override void OnTermination()
                      RayNinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_Ray View Post
                        Just replace:
                        Ohhh thank you Ray

                        Comment


                          #13
                          there is a problem with NT creating instances of custom classes and holding them for no apparent reason.

                          if I compile an indicator but dont add to a chart NT already has an instance.

                          I have an indicator wich writes to a file. I create a stream in Initialize an close it on terminate.

                          this doesnt work because once I compiled it NT has initialised the code and it will not release until the NT shut. a new instance on the chart cant use the same file name as it is locked.

                          I had to do a dirty trick with random file names to avoid the problem.

                          why do you do it? what is the purpose of idle indicator?

                          seems as resources leak to me... I think same was in NT 6.5
                          Last edited by maxima; 01-25-2010, 07:55 PM.

                          Comment


                            #14
                            P.S. a year ago it was promised that Ninja would resolve problem with releasing custom dlls as well..

                            same problem as with indicators. If you reference a custom dll and you are making changes, compile it - you cant copy it other as Ninja is always holding dll until completely shut (no mater if it used anywhere or not)....

                            In NT7 beta is still not addressing this and I think will not.

                            Comment


                              #15
                              >> there is a problem with NT creating instances of custom classes and holding them for no apparent reason.
                              Incorrect. Those instances are created so you can properly manage them on the UI before they e.g. get placed on chart.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              629 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              363 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              564 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              568 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X