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 AaronKoRn, Today, 03:05 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Emily  
          Started by zacharydw00, Today, 02:21 PM
          2 responses
          15 views
          0 likes
          Last Post zacharydw00  
          Started by Harvard, Today, 12:01 PM
          2 responses
          15 views
          0 likes
          Last Post Harvard
          by Harvard
           
          Started by DanDaMan, Today, 12:40 PM
          5 responses
          15 views
          0 likes
          Last Post NinjaTrader_Zachary  
          Started by bob999, 02-16-2021, 10:00 AM
          3 responses
          29 views
          0 likes
          Last Post NinjaTrader_Kate  
          Working...
          X