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, 03: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.
    JimNinjaTrader Customer Service

    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.
        JimNinjaTrader Customer Service

        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 Jema1, Today, 12:23 AM
          3 responses
          20 views
          0 likes
          Last Post s.kinra
          by s.kinra
           
          Started by elliot5, Today, 03:09 AM
          0 responses
          2 views
          0 likes
          Last Post elliot5
          by elliot5
           
          Started by soon123, Today, 12:51 AM
          1 response
          2 views
          0 likes
          Last Post s.kinra
          by s.kinra
           
          Started by soon123, Yesterday, 11:14 PM
          1 response
          9 views
          0 likes
          Last Post s.kinra
          by s.kinra
           
          Started by smcllr, Yesterday, 04:15 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_ShawnB  
          Working...
          X