Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Auto Close Code
Collapse
X
-
Auto Close Code
I was exploring the strategy builder, and discovered the conditions and actions functionality. However the 'Order Management Folder,' does not provided an option to close all positions. Can someone share the code to 'close all positions,' based on pre-defined conditions? The Strategy Builder has limitations for this type of functionality.Tags: None
-
Hello PYEEDEVELOPER,
Thanks for your post.
A limitation of using the Strategy Builder is that there are no options available that close/flatten all positions.
Something to consider is creating a condition checking if you are in a Long or Short market position and call your ExitLong/ExitShort exit order to exit the long or short position.
An example of checking if you are in a Long position could be seen in the image attached.
Otherwise, you would need to unlock the script from the Strategy Builder and manually code your strategy to use the Account.Flatten() method.
See this help guide page for more information about Account.Flatten(): https://ninjatrader.com/support/help...t8/flatten.htm
Let me know if I may assist further.Brandon H.NinjaTrader Customer Service
-
Originally posted by NinjaTrader_BrandonH View PostHello PYEEDEVELOPER,
Thanks for your post.
A limitation of using the Strategy Builder is that there are no options available that close/flatten all positions.
Something to consider is creating a condition checking if you are in a Long or Short market position and call your ExitLong/ExitShort exit order to exit the long or short position.
An example of checking if you are in a Long position could be seen in the image attached.
Otherwise, you would need to unlock the script from the Strategy Builder and manually code your strategy to use the Account.Flatten() method.
See this help guide page for more information about Account.Flatten(): https://ninjatrader.com/support/help...t8/flatten.htm
Let me know if I may assist further.
I just want to "Flatten" all of the current positions and cancel all of the orders on an account. What's the best way to do that using an indicator?
Comment
-
Hello sbgtrading,
Thanks for your note.
The Strategy Builder screenshot would only apply to strategies, not custom indicators.
To flatten an account on an instrument you could use the Account.Flatten() method.
Note that if you have positions on multiple instruments on an account, you would need to use Account.Flatten() for each instrument that has a position open. See this 'Flatten a list of instruments' section of the help guide sample code for how this could be done.
Please see the help guide documentation below for more information and sample code.
Account: https://ninjatrader.com/support/help...ount_class.htm
Account.Flatten(): https://ninjatrader.com/support/help...t8/flatten.htm
Another option would be to use the Account.FlattenEverything() method in your script to flatten all positions on an account. Note that this method is not documented/supported and it would be up to your discretion to use it in your script.
Let me know if I may assist further.Last edited by NinjaTrader_BrandonH; 02-28-2023, 01:49 PM.Brandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by cutzpr, Today, 08:54 AM
|
0 responses
2 views
0 likes
|
Last Post
by cutzpr
Today, 08:54 AM
|
||
Started by benmarkal, Today, 08:44 AM
|
0 responses
2 views
0 likes
|
Last Post
by benmarkal
Today, 08:44 AM
|
||
Started by Tin34, Today, 03:30 AM
|
2 responses
21 views
0 likes
|
Last Post
by Tin34
Today, 04:11 AM
|
||
Started by sastrades, Yesterday, 09:59 AM
|
2 responses
33 views
0 likes
|
Last Post Today, 04:06 AM | ||
Started by ETFVoyageur, Today, 12:52 AM
|
1 response
18 views
0 likes
|
Last Post Today, 03:36 AM |
Comment