Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy exit handle

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

    Strategy exit handle

    Hi everyone,

    I'm a new developer with Ninja 8. What is good practice to exit, close, destroy, release strategy from the code?

    I'm using Threads and singleton pattern in my strategy and they do not get destroyed or released from memory on strategy exit.

    I used functions like:
    Application.Exit
    Application.Shutdown

    but in that case, whole Ninja application is closed. I'm looking to close only my strategy.

    Workaround to really release all strategy is to recompile it, then everything is clean.

    My question is what is good practice to exit, close, destroy, release strategy from the code?

    Thank you in advance,
    Gunars
    Last edited by gunars.kepe; 08-31-2017, 04:46 AM.

    #2
    Hello gunars.kepe,

    Welcome to the forums!

    NinjaScripts are designed so they can have their resources created when enabled and destroyed when they are disabled. Strategies follow certain defined behavior in the options menu to determine what it should do with any active orders when it is disabled.

    When recreating and destroying your own resources in the context of a strategy, the State system should be used. State.DataLoaded is a good time for the strategy to create new resources while State.Terminated can be used to clean up resources when the strategy exits.

    LifeCycle - http://ninjatrader.com/support/helpG...fecycle_of.htm

    OnStateChange() - http://ninjatrader.com/support/helpG...tatechange.htm

    Strategy Options - http://ninjatrader.com/support/helpG...riptProperties

    If you have any additional questions, please don't hesitate to ask.

    Comment


      #3
      Thank you for your detailed reply.

      I'm using State.Terminated to clean up resources.

      My question is, is there any method that cleans up all strategy resources? Idea is to close strategy, clean up all strategy resources without writing additional cleanup when exiting strategy and without worrying that some resources are still running. To make 100% sure all resources are cleaned up.

      Comment


        #4
        Hello gunars.kepe,

        Thanks for your reply.

        There is not a universal method that will clean up a strategy's resources. Class level variables will be cleaned up by garbage collection after the strategy is disabled and custom resources will have to be handled on their own in State.Terminated to assure they are cleaned up.

        You can disable a strategy programmatically with SetState(State.Terminated);

        SetState() - https://ninjatrader.com/support/help.../?setstate.htm

        Please let me know if I can be of further assistance.

        Comment


          #5
          "There is not a universal method that will clean up a strategy's resources."

          Thank you, you answered my question.

          Gunars

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          88 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          134 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          68 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          119 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          69 views
          0 likes
          Last Post PaulMohn  
          Working...
          X