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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        633 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X