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

How to cleanly shut down indicator

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

    How to cleanly shut down indicator

    Hi. In my indicator, I have initialized the following event handler (in OnBarUpdate()):

    MarketData.MarketDataItem +=
    new MarketDataItemEventHandler(MarketData_MarketDataIt em);

    I've noticed that even when I remove the indicator from my chart, this event is still kicking off. My indicator also opens up 3 Windows forms and my question is: how can I ensure that when the indicator is removed from the chart, the above event gets unhooked and I can close out my 2 Windows forms.

    I tried the following deconstructor code:

    // my destructor code

    ~ZooPulse()

    {

    Print("destruct1a!");

    Print("destruct3!");

    zform.Close();

    zform = null;

    Print("destruct2!");

    MarketData.MarketDataItem -= new MarketDataItemEventHandler(MarketData_MarketDataIt em);

    Print("destruct4!");

    //System.GC.Collect();

    Print("DONE");

    }



    where zform is my Windows form. I get the first 2 Print statements, then nothing else. So I know it doesn't like my zform.Close(). I've tried commenting out the form cleanup and just removing the MarketData event handler, but that also doesn't print "destruct4", so I know it failed on that too.



    How do I remove my event handler and close out my forms when the user Removes the indicator on the chart? Thanks.


    #2
    imported post

    Unfortunately there is no guaranteed way to unhook the event handler. You for sure are getting into advanced logic that is really not an officially supported feature. We have added a TearDown() logic for NT6 which will be in beta in August which will allow you to disconnect any handlers. You could try Dispose() method but there is no guarantee that this method is called immediately upon removing the indicator from a chart.

    Ray
    RayNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by ttrader23, Today, 09:04 AM
    2 responses
    10 views
    0 likes
    Last Post ttrader23  
    Started by geotrades1, Today, 07:54 AM
    10 responses
    26 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by ninza33, Yesterday, 12:31 PM
    3 responses
    16 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by patrickmlee007, Today, 09:33 AM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
    53 responses
    5,309 views
    0 likes
    Last Post BartMan
    by BartMan
     
    Working...
    X