Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Disable Strategy - Wait Until Flat
Collapse
X
-
Disable Strategy - Wait Until Flat
Is there an option or feature to set "wait until flat" for disabling a strategy that has an open position? If not, I'd like to propose this as a new feature request. For example, when disabling a running strategy that currently has an open position, the system should prompt "Disable immediately or wait until flat." If this is already possible, then can someone please tell me how?Tags: None
-
Hello mase2005,
Thank you for your post.
This would be possible using custom NinjaScript logic. If you have a programming background and the strategy is something you have developed yourself, we would be glad to provide you links to resources and samples that would help you write the code yourself, or we can provide you with resources to find a programmer to create the script for you. Please let me know if either of these options interests you.
I look forward to your reply.Emily C.NinjaTrader Customer Service
-
Hello mase2005,
Thank you for your reply.
The CloseStrategy() method cancels all working orders, closes any existing positions, and disables the strategy. It may also be overridden with custom logic if desired. Here is the help guide page:
In your case, if you are wanting to disable a strategy under certain conditions and only when it is flat, I suggest checking in OnPositionUpdate() if the position is flat (along with any other desired conditions) and then calling CloseStrategy() to disable the strategy. Here is a snippet of what that might look like:
Code:protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition) { if (position.MarketPosition == MarketPosition.Flat) // feel free to add additional conditions here { CloseStrategy() } }
You could certainly add a check for if (position.MarketPosition == MarketPosition.Flat) inside of the conditions as well.
Please let us know if we may be of further assistance.Emily C.NinjaTrader Customer Service
Comment
-
To clarify: is the CloseStrategy() function called when I disable a strategy from the Control Center (by clicking the checkbox or right-click and choose "disable")? I tried to override the CloseStrategy() function, but it seems to be ignoring my custom logic...
Comment
-
Hello mase2005,
No that would not be called by unchecking it, CloseStrategy is for use in your code specifically. When you uncheck the strategy any logic in the override won't be called. The only items that would happen would be cancelling of working orders if you have those options set in the Tools > Options > Strategies menu. https://ninjatrader.com/support/help...strategies.htm
JesseNinjaTrader Customer Service
Comment
-
Is there any other way for me to interact with a running strategy? Say, change/set a variable to queue my custom shutdown sequence? Ideally, I want to be able to disable a strategy from Control Center and it 1) not allow any new open orders 2) cancel any open orders, and 3) allow the strategy to continue running until all open positions are properly exited according to the strategy
Comment
-
Hello mase2005,
Thank you for your reply.
What you are describing sounds like it could be achieved with a custom add-on. You could create a window with buttons or a checkbox to toggle bools between true/false. Your entries could be set up so they are only submitted if the bool is either true or false, then have logic to cancel orders when the bool is toggled yet then keep the exit logic set up for the open positions to close according to your original logic.
When developing add-ons, the Account class is used to submit and manage orders:
We have a section of the help guide dedicated to information for developing add-ons, including a sample script that you can import by clicking the "AddOn Framework NinjaScript Basic" link on this page:
Please let us know if we may be of further assistance.Emily C.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Kavand, Today, 03:55 AM
|
0 responses
7 views
0 likes
|
Last Post
![]()
by Kavand
Today, 03:55 AM
|
||
Started by marcus2300, Today, 02:46 AM
|
0 responses
8 views
0 likes
|
Last Post
![]()
by marcus2300
Today, 02:46 AM
|
||
Started by mrgreentrading, 04-11-2025, 08:41 PM
|
9 responses
82 views
0 likes
|
Last Post
![]() |
||
Started by michelz, 02-18-2025, 08:30 AM
|
38 responses
1,103 views
0 likes
|
Last Post
![]()
by danwcw
Today, 01:37 AM
|
||
Started by Taddypole, 06-18-2024, 11:58 AM
|
4 responses
97 views
0 likes
|
Last Post
![]()
by music_p13
Yesterday, 11:29 PM
|
Comment