Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Delete Strategy from Strategies Tab

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

    Delete Strategy from Strategies Tab

    Hi there, I built a service to auto-load and start strategies in NT8 and would like to know if there was a way for me to have it DELETE itself from the strategies tab. As of right now I'm using a timer to auto-terminate if a trade isn't made within 15 minutes(if it doesn't happen within 15, it ain't happening according to my strategy. The issue is that even though the strategy is disabling it's still holding on to a little bit of ram. Unfortunately towards the end of the trading day it actually leaks so badly that NT locks up. Is there a way to stop that leak, or remove the strategy from the list entirely?

    #2
    Hi RaddiFX, thanks for posting.

    Removing strategies automatically is not supported. There is code running in the strategy that is taking up the memeory. The script would need to be reduced to test for a memory leak.

    Kind regards,
    -ChrisL

    Comment


      #3
      Thanks Chris.

      How about any unsupported ways, haha. I can deal with the repercussions and I can also deal with programming it myself, I'd just need to know where the active strategies would be stored, or what's being called when I remove them from the list.

      Comment


        #4
        Hi RaddiFX,

        I do not know of any way to remove a strategy from the configured list programmatically.

        Comment


          #5
          So I did a fair amount of digging and testing.

          Long story short, I was able to find the method for removing a strategy from the strategies grid. My question now is how do I tell it which strategy I need to remove. I've gotten as far as adding a new strategy, but that's with me providing all of the NEW information. I now need to find information about strategies that are already enabled and on the grid.

          Just as an example, here is a shortened version of how to add a strategy:

          try{
          NinjaTrader.Gui.NinjaScript.StrategiesGrid sg=new NinjaTrader.Gui.NinjaScript.StrategiesGrid();

          System.Reflection.MethodInfo dynMethod = sg.GetType().GetMethod("StrategyAdd",
          System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
          if (dynMethod!=null)
          dynMethod.Invoke(sg, new object[] { s });

          dynMethod = sg.GetType().GetMethod("StrategyEnable",
          System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
          dynMethod.Invoke(sg, new object[] { s, null, null });

          }

          s being the strategy and you having set all of its parameters earlier.

          Attached is a quick addon I wrote to explore the available methods and how to call them.
          Attached Files

          Comment


            #6
            Hi RaddiFX, I apologize but I won't be able to help with the unsupported code. Other members of the forum will need to assist if they are able.

            Comment


              #7
              If anyone is looking to do this in the future... don't, lol... I figured it out and it doesn't do what I wanted. However, you can run the
              Code:
              CloseStrategy("Exterminate");
              command to close out the strategy and it will do a full cleanup.

              Comment


                #8

                Hi RaddiFX,

                Is it possible to get all the Strategies from ControlPanel->Strategies Grid ? I want to change the instrument from add-on for all the strategies available in strategies grid.

                Comment


                  #9
                  Originally posted by nandhumca View Post
                  Hi RaddiFX,

                  Is it possible to get all the Strategies from ControlPanel->Strategies Grid ? I want to change the instrument from add-on for all the strategies available in strategies grid. First it checks if there are orders or executions on the account for the ticker in question. If there are, DONT TOUCH ANYTHING from outside the strategy cause you could cause all sorts of issues. If there aren't, then you can loop through the existing strategies to see if the one you're looking for exists and edit it with that.

                  Yes; But be very careful when working with them.

                  The below code will loop through each account, and then loop through each strategy within that account:

                  Formatting got a bit wonky, but this should do it.
                  Code:
                  try{
                      //Check to see if the ticket has a currently open trade
                      foreach (var account in NinjaTrader.Cbi.Account.All)
                      {
                          if (account.Name == acct)
                          {
                              bool exists = false;
                              if (account.ConnectionStatus.ToString() == "Disconnected")
                                  add = false;
                              foreach (var order in account.Orders)
                              {
                                  if (order.Instrument.ToString() == (instr + " Default"))
                                  {
                                      add = false;
                                      Print(instr + " - Has open orders");
                                  }
                              }
                              foreach (var execution in account.Executions)
                              {
                                  if (execution.Instrument.ToString() == (instr + " Default"))
                                  {
                                      add = false;
                                      Print(instr + " - Has existing executions");
                                  }
                              }
                              if (add)
                              {
                                  foreach (StrategyBase strategy in account.Strategies)
                                  {
                                            if (strategy.Instrument.ToString() == (instr + " Default"))
                                            {
                                                if (expirationTimer == 0)
                                                {
                                                    Print("Exists - " + instr);
                                                     add = false;
                                                 }
                                                 else
                                             {
                                                 Print("Refreshing - " + instr);
                          //             account.Strategies.Remove(strategy);
                                                 strategy.CloseStrategy("Refresh");
                                         }
                                     }
                                  }
                             }
                          }
                      }
                  }
                  catch(Exception ex){NinjaTrader.Code.Output.Process("error 1 - "+ex.Message, PrintTo.OutputTab1);}  
                  ​

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  608 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  355 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
                  560 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  561 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X