Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Account.Flatten() Without Closing Strategy?
Collapse
X
-
Hello gbourque,
There isn't a way to call Account.Flatten() without disabling a strategy.
Instead place a market order in the opposite direction of the position with the position quantity.
If you are trying to close the strategy position use ExitLong()/ExitShort().
If you are trying to close an account position without changing the strategies position use Account.Submit() with Account.CreateOrder.
Chelsea B.NinjaTrader Customer Service
Comment
-
My strategy is unmanaged so I can't use ExitLong nor ExitShort. I tried just submitting sells to close long positions, and buys to close short positions. This worked but the Replikanto trade copier got confused and left orders open. I'm not sure why Flatten has to close the strategy. That should at least be optional.
Comment
-
Hello gbourque,
Call SubmitOrderUnmanaged with OrderType.Market and the OrderAction opposite to the position (i.e. if MarketPosition.Long use OrderAction Sell, if MarketPosition.Short use OrdeAction.BuyToCover).
Disabling working strategies is intentional as closing the account position will cause the strategies position to become out of sync.Chelsea B.NinjaTrader Customer Service
Comment
-
Hi Chelsea,
I met similar issue in strategy development. To avoid disabling active strategy, I use ExitLong and ExitShort instead of Flatten(). the challenge for me is I was trying to exitlong on 2nd instrument without knowing its quantity. How to do that? If no paramenters get fed into ExitLong(), it simply close all primary positions instead of secondary positions.
Comment
-
Hello judysamnt7,
If the position was entered by the strategy, submit the exit using the barsInProgress index of that instrument that was added to the script.
ExitLong(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal)
If the position was not entered by the strategy, get the position from the account, and submit the order to the account using the addon approach.
Chelsea B.NinjaTrader Customer Service
Comment
-
To use syntax ExitLong(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal), the quantity has to be determined. How do I get the quantity of remaining position size for 2nd instrument? Can it be left blank ?
another question is : if I convert my strategy to an indicator, would Flatten() still close everything ?
Comment
-
Hello judysamnt7,
If the strategy submitted the order the Position.Quantity or Positions[price series index].Quantity would be the remaining quantity.
This cannot be left blank.
Yes, Account.Flatten() is an addon approach method and will work in any script.Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
41 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
124 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
64 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
41 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment