Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Delete Strategy from Strategies Tab
Collapse
X
-
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?Tags: None
-
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
-
Yes; But be very careful when working with them.Originally posted by nandhumca View PostHi 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.
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
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
355 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
560 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
561 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment