Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to stop a strategy by programming?

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

    How to stop a strategy by programming?

    I wonder if there is a way to implement this:

    The strategy has been running for a while, and when some conditions are met, I want to stop the strategy automatically.

    Of course, one simple way is to "do nothing" in OnBarUpdate after the conditions are met, but is there any way to fully stop it (by programming)?


    J.

    #2
    Hi Follow Shadan, you mean like hitting the 'Start / Stop' button manually? This is unfortunately not possible with NinjaScript, but you can simply set a flag and then stop issueing any orders when your conditions are met.

    Comment


      #3
      I personally have programmed states into my strategy so like if buy conditions are all valid set a variable like buypostion = true then when the trade has finished (eg flat) set buypostion back to false. This stops within the code double buys.

      Also i use the same methods to create a lockdown state for my strategy so that when conditions are valid the strategy goes into basically do nothing OnBarUpdate() mode until i restart it manually.

      eg.

      Code:
      if (buyconditions == true && lockdown == false)
      {
      //trade actions
      }
      
      if (X == X)
      {
      lockdown = (true);
      }
      Maybe it is not the best way to achieve this but it has worked and does work for me.

      Comment


        #4
        Thanks for posting this code snippet here cirion!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmoran13, Yesterday, 01:02 PM
        0 responses
        30 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        22 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        160 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        95 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        148 views
        2 likes
        Last Post CaptainJack  
        Working...
        X