Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator Initialize - Dispose

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

    #16
    I dont know what does it mean for a developer. What I see is that if I need to initialise some resource (I have file stream and I have an external window) - once I added one indicator to a chart - I have several of copies being instantiated but only one is used...

    If you need some instanses for inner job you had to have 2 separate sets of methods to init and dispose custom classes.. One you use for what you use and one is for the developers... And the use case should be clearly explained.

    I hope that will happen in NT7.

    Comment


      #17
      Unfortunately nothing will change with NT7 in that regard as all supported features behave well in Initialize().

      Comment


        #18
        Yeah I got it.

        Comment


          #19
          Hello,

          I use Initialize and Dispose a lot in my code.

          In my indicators when I subsitute Dispose with OnTermination my code breaks because OnTermination is never called. Is this a bug or intended?

          Dispose is called as usual.
          Therefore I will continue to use Dispose.

          are there any plans to delete Dispose ?

          Comment


            #20
            >> In my indicators when I subsitute Dispose with OnTermination my code breaks because OnTermination is never called
            Could you please provide a simple a possible scenario where you feel OnTermination should be called but wasn't. Thanks

            Comment


              #21
              just click F5 (reload ninjascript) should bring you there

              Comment


                #22
                I copied the SMA indicator and added this simple method
                Code:
                        protected override void OnTermination()
                        {
                            Print("OnTermination");
                        }
                It's triggered every time I hit F5.

                Comment


                  #23
                  you are correct, OnTermination is called in SMA.

                  But if you put a function public override void Dispose() in SMA,

                  then OnTermination is no longer called.


                  I overlooked this before because the changes will only be visible at the SECOND F5 click (at the first click the old SMA code Dispose/OnTerminate is called, only at the second f5 click the current code base is executed)

                  regards

                  Comment


                    #24
                    Please use OnTermination as advised with NT7 to avoid any further confusion.

                    Comment


                      #25
                      I have code like

                      Dispose(){
                      ... my stuff

                      base.Dispose()

                      }


                      and base can be a strategy, indicator or marketanalyzer column.
                      All works perfectly, and in this way I can control my resources properly.


                      Why don' t you publish the STRUCTURE of your Dispose - OnTermination sequence.

                      Is it?

                      IndicatorBase.Dispose(){
                      OnTermination(); // this calls cleanup in custom indicator

                      DoNTInternalDispose();
                      }


                      Instread

                      MyIndicator.Dispose(){
                      DoMyDispose();

                      base.Dispose();

                      }

                      would give exactly the same behaviour.

                      Only difference is that if a user forgets to call base.Dispose() he could cause exceptions in NT.

                      Is this the idea behind OnTermination?

                      Comment


                        #26
                        We do not provide any support for Dispose() with NT7. Nor should you ever call OnTermination() explicitely. Please clean up your ressources in OnTermination(). Thanks

                        Comment


                          #27
                          "No support..."

                          Thank you for your reply.
                          Not supported doesn' t necessarily mean bad code. Sometimes on the contrary, functionality becomes better...

                          Actually I am only interested to have Dispose() also available in the future. I will use OnTermination where I decide it is the better choice.

                          From your samples .cs files I see a massive use of Dispose(), so I feel on the safe side...

                          Comment


                            #28
                            Reason reference samples use Dispose() is because they are from NT6.5 and OnTermination() did not exist back then.
                            Josh P.NinjaTrader Customer Service

                            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
                            362 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