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

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.
    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 algospoke, Yesterday, 06:40 PM
          2 responses
          23 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          45 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          22 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          181 views
          0 likes
          Last Post jeronymite  
          Working...
          X