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

OnTermination() randomly runs on WorkSpace close

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

    OnTermination() randomly runs on WorkSpace close

    Hi,

    If anyone can help me that would be much appreciated as I have been pulling my hair out for 24 hours over the seemingly complete randomness of this issue!

    So I have added buttons to the toolbar modelling the following code


    First I was using the Dispose() method to clean up my resources (remove my added buttons) and this created so many problems. All the problems went away when I changed over Dispose() for OnTermination() and everything has been working almost perfectly since then.

    There is one strange and persistant issue though and that is when a workspace is closed, some of the charts that are runnig the indicator with buttons on it dont seem to be running the OnTermination therefor not deleting the buttons on these randomly selected charts. So when i open the workspace again there is two sets of buttons on some charts, one set works and one doesnt. Really frustrating as is seems as though Ninjatrader is randomly selecting which charts to skip OnTermination on as it is not always the same chart/charts with the problem.

    The worst this is, as you can see from the code below, the print method makes it really easy to see when the OnTermination is run except Ninjatrader cloeses the Output window when you close a workspace making it impossible to track whats going on!

    protected override void OnTermination()

    {
    if (buttonsloaded==true)
    {
    strip.Items.Remove(btnZZ1);
    strip.Items.Remove(btnZZ2);
    strip.Items.Remove(btnZZ3);
    Print("Ran Termination");

    }

    Can anyone understand whats happening here?

    #2
    Originally posted by marty087 View Post
    Hi,

    If anyone can help me that would be much appreciated as I have been pulling my hair out for 24 hours over the seemingly complete randomness of this issue!

    So I have added buttons to the toolbar modelling the following code


    First I was using the Dispose() method to clean up my resources (remove my added buttons) and this created so many problems. All the problems went away when I changed over Dispose() for OnTermination() and everything has been working almost perfectly since then.

    There is one strange and persistant issue though and that is when a workspace is closed, some of the charts that are runnig the indicator with buttons on it dont seem to be running the OnTermination therefor not deleting the buttons on these randomly selected charts. So when i open the workspace again there is two sets of buttons on some charts, one set works and one doesnt. Really frustrating as is seems as though Ninjatrader is randomly selecting which charts to skip OnTermination on as it is not always the same chart/charts with the problem.

    The worst this is, as you can see from the code below, the print method makes it really easy to see when the OnTermination is run except Ninjatrader cloeses the Output window when you close a workspace making it impossible to track whats going on!

    protected override void OnTermination()

    {
    if (buttonsloaded==true)
    {
    strip.Items.Remove(btnZZ1);
    strip.Items.Remove(btnZZ2);
    strip.Items.Remove(btnZZ3);
    Print("Ran Termination");

    }

    Can anyone understand whats happening here?
    OnTermination(), is the last event handled, so just remove the items unconditionally. I suspect that multithreading may sometimes cause the buttonsloaded filter to return the wrong value.

    Comment


      #3
      Hi Koganam,

      Thank you for your post.

      I had tried removing the "buttonsloaded" condition previously and it didnt change anything, but just tried it again to be sure. I completely removed the bool condidion so now i just have

      protected override void OnTermination()

      {


      strip.Items.Remove(PH1);
      strip.Items.Remove(PH2);
      strip.Items.Remove(PH3);
      strip.Items.Remove(PH4);
      strip.Items.Remove(PH5);
      strip.Items.Remove(PL1);
      strip.Items.Remove(PL2);
      strip.Items.Remove(PL3);
      strip.Items.Remove(PL4);
      strip.Items.Remove(PL5);

      strip.Items.Remove(btnZZ2);
      strip.Items.Remove(btnZZ3);
      strip.Items.Remove(btnLET1);
      strip.Items.Remove(btnLET2);
      strip.Items.Remove(btnLET3);
      strip.Items.Remove(btnTDM1);
      strip.Items.Remove(btnTDM2);
      strip.Items.Remove(btnTDM3);
      strip.Items.Remove(btnZZ1);


      Print("Ran Termination");



      }

      I loaded up 9 fresh charts and put the indicator on all of them, Then closed the workspace and re-opened it. 5 out of the 9 charts then had two sets of buttons on them and the other 4 charts where just how i left them....

      Any other suggestions?

      Cheers.

      Comment


        #4
        Originally posted by marty087 View Post
        Hi Koganam,

        Thank you for your post.

        I had tried removing the "buttonsloaded" condition previously and it didnt change anything, but just tried it again to be sure. I completely removed the bool condidion so now i just have

        protected override void OnTermination()

        {


        strip.Items.Remove(PH1);
        strip.Items.Remove(PH2);
        strip.Items.Remove(PH3);
        strip.Items.Remove(PH4);
        strip.Items.Remove(PH5);
        strip.Items.Remove(PL1);
        strip.Items.Remove(PL2);
        strip.Items.Remove(PL3);
        strip.Items.Remove(PL4);
        strip.Items.Remove(PL5);

        strip.Items.Remove(btnZZ2);
        strip.Items.Remove(btnZZ3);
        strip.Items.Remove(btnLET1);
        strip.Items.Remove(btnLET2);
        strip.Items.Remove(btnLET3);
        strip.Items.Remove(btnTDM1);
        strip.Items.Remove(btnTDM2);
        strip.Items.Remove(btnTDM3);
        strip.Items.Remove(btnZZ1);


        Print("Ran Termination");



        }

        I loaded up 9 fresh charts and put the indicator on all of them, Then closed the workspace and re-opened it. 5 out of the 9 charts then had two sets of buttons on them and the other 4 charts where just how i left them....

        Any other suggestions?

        Cheers.
        You may need to remove the strip itself too in OnTermination(). Try that. After all, even without seeing your code, I think you created and added a new strip to hold your buttons.

        Comment


          #5
          Hi Again,

          I have just isolated the code out of the larger program to see if the problem would persist and it has. I think it may only be happening when 5 or more charts are loaded with the indi. But I loaded this indi onto 6 charts and closed the workspace, then reopened and some charts had doubled up buttons.

          I will look at learning how to remove the tool strip now.....
          Attached Files

          Comment


            #6
            I cant remove the tool strip because i havent created another... I am adding onto the existing toolstrip...
            any suggestions?

            Comment


              #7
              marty087, this would be unfortunately an area we could not support officially here, but in testing a bit I see this behavior with your code also using a single chart only. Initialize() could be called multiple times, can you try moving the button startup Initialize() part to OnStartUp() instead?
              BertrandNinjaTrader Customer Service

              Comment


                #8
                FANTASTIC!!!

                I got so caught up thinking it was failure to remove, I didnt even think about it adding twice. Works perfectly now.

                I will be able to get some sleep now... ha

                Thanks Bertrand!

                Comment


                  #9
                  Have a good nights rest and glad that worked.
                  BertrandNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post Javierw.ok  
                  Started by timmbbo, Today, 08:59 AM
                  2 responses
                  10 views
                  0 likes
                  Last Post bltdavid  
                  Started by alifarahani, Today, 09:40 AM
                  6 responses
                  40 views
                  0 likes
                  Last Post alifarahani  
                  Started by Waxavi, Today, 02:10 AM
                  1 response
                  18 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Started by Kaledus, Today, 01:29 PM
                  5 responses
                  15 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X