A lot of internal reasons can cause executions to lump together for a position update. The really long story short is that is the case. What is guaranteed is that you will get the correct position amount.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Order cancelled when using liveUntilCancelled
Collapse
X
-
I played with this more, and now I know that even if an order is for a single contract, such that a partial fill isn't possible, NinjaTrader won't allow an order to reverse if the internal state of the entry order on the opposite side isn't 'Filled'.
By calling an Enter*Limit() method in OnExecution(), it's possible to get ahead of the state change to 'Filled' on the entry order, which causes NinjaTrader to cancel the reversing part of the order being generated in response to the execution.
Increasing the quantity, such that partial fills occur, makes it more obvous -- NinjaTrader won't allow reversing orders on even the partially filled quantity passed to OnExecution().
The trace order output below shows that trying to submit a reversing order on the partial fill quantity also generates a Cancel on the reversing part of the order.
The only way I could prevent the reversing part of the target order from being cancelled, was by calling the Enter*Limit() method to reverse in the last call to OnPositionUpdate() for the final partial fill, when the quantity in the IPosition object matched the total order quantity, showing the entry order had completely filled.
This seems like a problem, given that partial fills can't be managed easily -- you have to guess about when (or if) an outstanding partially filled entry order should be cancelled, to submit a reversing order on the open position.
It seems like the open position should be the priority, rather than the state of the entry order -- orders could then be generated in response to each execution, so positions that result from orders that never fill completely would be handled correctly. The way I have it coded now only works if the entry order is completely filled -- if I get a partial position, the exit order won't be generated.
--- Output log - ToString() is being called on the argument passed to OnOrderUpdate() and OnExecution() ---
12/9/2008 9:31:05 AM CancelAllOrders: BarsInProgress=0
12/9/2008 9:33:02 AM Entered internal PlaceOrder() method at 12/9/2008 9:33:02 AM: Action=Buy OrderType=Limit Quantity=30 LimitPrice=8819 StopPrice=0 SignalName='****Buy'
12/9/2008 9:33:00 AM in OnOrderUpdate -- Order='354fbb5439b3487f8c9cb0dac7d8d615/Replay101' Name='****Buy' State=PendingSubmit Instrument='YM 12-08' Action=Buy Limit price=8819
Stop price=0 Quantity=30' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='354fbb5439b3487f8c9cb0dac7d8d615' Gtd='1/1/0001 12:00:00 AM'
12/9/2008 9:33:00 AM in OnOrderUpdate -- Order='354fbb5439b3487f8c9cb0dac7d8d615/Replay101' Name='****Buy' State=Accepted Instrument='YM 12-08' Action=Buy Limit price=8819
Stop price=0 Quantity=30' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='354fbb5439b3487f8c9cb0dac7d8d615' Gtd='1/1/0001 12:00:00 AM'
12/9/2008 9:33:00 AM in OnOrderUpdate -- Order='354fbb5439b3487f8c9cb0dac7d8d615/Replay101' Name='****Buy' State=Working Instrument='YM 12-08' Action=Buy Limit price=8819
Stop price=0 Quantity=30' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='354fbb5439b3487f8c9cb0dac7d8d615' Gtd='1/1/0001 12:00:00 AM'
12/9/2008 9:33:00 AM in OnOrderUpdate -- Order='354fbb5439b3487f8c9cb0dac7d8d615/Replay101' Name='****Buy' State=PartFilled Instrument='YM 12-08' Action=Buy Limit price=8819
Stop price=0 Quantity=30' Type=Limit Tif=Day Oco='' Filled=3 Fill price=8793 Token='354fbb5439b3487f8c9cb0dac7d8d615' Gtd='1/1/0001 12:00:00 AM'
12/9/2008 9:33:00 AM in OnExecution -- Execution='5bd0a4c1d19349e6ab3c720d449f1713' Instrument='YM 12-08' Account='Replay101' Name='****Buy' Exchange=Default Price=8793 Quantity=3
Market position=Long Commission=0 Order='354fbb5439b3487f8c9cb0dac7d8d615' Time='12/9/2008 9:33:02 AM'
12/9/2008 9:33:02 AM Entered internal PlaceOrder() method at 12/9/2008 9:33:02 AM: Action=SellShort OrderType=Limit Quantity=3 LimitPrice=8893 StopPrice=0 SignalName='****Target'
12/9/2008 9:33:00 AM in OnOrderUpdate -- Order='d1d88c65e4f64209b87f48560f887bf5/Replay101' Name='Close position' State=PendingSubmit Instrument='YM 12-08' Action=Sell Limit price=8893
Stop price=0 Quantity=3' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='d1d88c65e4f64209b87f48560f887bf5' Gtd='1/1/0001 12:00:00 AM'
12/9/2008 9:33:00 AM in OnOrderUpdate -- Order='d1d88c65e4f64209b87f48560f887bf5/Replay101' Name='Close position' State=Accepted Instrument='YM 12-08' Action=Sell Limit price=8893
Stop price=0 Quantity=3' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='d1d88c65e4f64209b87f48560f887bf5' Gtd='1/1/0001 12:00:00 AM'
12/9/2008 9:33:00 AM in OnOrderUpdate -- Order='d1d88c65e4f64209b87f48560f887bf5/Replay101' Name='Close position' State=Working Instrument='YM 12-08' Action=Sell Limit price=8893
Stop price=0 Quantity=3' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='d1d88c65e4f64209b87f48560f887bf5' Gtd='1/1/0001 12:00:00 AM'
12/9/2008 9:33:00 AM in OnOrderUpdate -- Order='8d4c831a1bf942dfa17bc96e499b458a/Replay101' Name='****Target' State=PendingSubmit Instrument='YM 12-08' Action=SellShort Limit price=8893
Stop price=0 Quantity=3' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='8d4c831a1bf942dfa17bc96e499b458a' Gtd='1/1/0001 12:00:00 AM'
12/9/2008 9:33:00 AM in OnOrderUpdate -- Order='8d4c831a1bf942dfa17bc96e499b458a/Replay101' Name='****Target' State=Accepted Instrument='YM 12-08' Action=SellShort Limit price=8893
Stop price=0 Quantity=3' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='8d4c831a1bf942dfa17bc96e499b458a' Gtd='1/1/0001 12:00:00 AM'
12/9/2008 9:33:00 AM in OnOrderUpdate -- Order='8d4c831a1bf942dfa17bc96e499b458a/Replay101' Name='****Target' State=Working Instrument='YM 12-08' Action=SellShort Limit price=8893
Stop price=0 Quantity=3' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='8d4c831a1bf942dfa17bc96e499b458a' Gtd='1/1/0001 12:00:00 AM'
12/9/2008 9:33:02 AM Cancelled pending entry order on opposite side of the market: BarsInProgress=0: Order='8d4c831a1bf942dfa17bc96e499b458a/Replay101' Name='****Target'
State=Working Instrument='YM 12-08' Action=SellShort Limit price=8893 Stop price=0 Quantity=3 Strategy='DowGapOpenShortAuto' Type=Limit Tif=Day Oco=''
Filled=0 Fill price=0 Token='8d4c831a1bf942dfa17bc96e499b458a' Gtd='12/1/2099 12:00:00 AM'
Comment
-
Not sure what you are trying to get at. For reasons mentioned in the Internal Order Handling Rules in the Help Guide, you cannot be in both directions of the market simultaneously. If you are long and you want to exit there is nothing stopping you from putting in ExitLong. It doesn't matter what your partial fills are. You can put in ExitLong no matter what.Josh P.NinjaTrader Customer Service
Comment
-
The problem is you can't easily reverse a position that results from the partial fill of an order -- if only part of a limit order is filled, and the price moves toward the target price at which you want to reverse, the code has to monitor the price movement, and cancel the outstanding entry order so NinjaTrader will alow the placement of the order in the opposite direction.
My strategy trades a price range under certain conditions -- if I were trading this manually I would place both buy and sell limit entry orders simultaneously, at limit prices above and below the current market, and then double the quantity of the outstanding order once one of the orders filled -- I can't do that in a NinjaTrader strategy.
I guess I can immediately place exit orders using calls to Exit*() methods as partial fills come in for an entry, as you mention, and then I can submit the reversing orders once fills start coming in for those exit orders, cancelling the open entry order on the opposite side if it wasn't completely filled -- but this has the disadvantage of putting the reversing order at the back of the price queue at the exchange. In the past in real trading, I've seen sell limit orders fill at the high of the bar, and buy limit orders fill at the low of the bar because they've been in the queue well before the market reached the given level (sometimes by hours, depending on the price action).
Comment
-
ntVic,
As discussed earlier, you cannot place enter orders in opposite directions. Just consider the consequences if both went part filled at the same time. Then what? What happens to the reversing logic? It doesn't work and this is why there are Internal Order Handling Rules in place. Please review the article in the Help Guide for all the rules.Josh P.NinjaTrader Customer Service
Comment
-
I understand -- I specifically mentioned not being able to submit orders on the opposite side of the market from a strategy in the second paragraph of my previous post.Originally posted by NinjaTrader_Josh View PostntVic,
As discussed earlier, you cannot place enter orders in opposite directions.
A reversing order could simply be generated for each partial fill -- so the quantity on the opposite side would be increased by each partial, up to double the original quantity for a complete fill. You have to keep track of the quantities in the outstanding orders, but that's no more difficult than tracking and cancelling an outstanding entry order to submit a reversing order, as must be done currently.Originally posted by NinjaTrader_Josh View PostJust consider the consequences if both went part filled at the same time. Then what? What happens to the reversing logic? It doesn't work and this is why there are Internal Order Handling Rules in place.
I have read the 'Internal Order Handling Rules', and I understand that the designers of NinjaTrader put in restrictions to avoid certain difficulties, and I know I'll have to find ways to work within these restrictions to get the behavior I want. But these are restrictions on what a trader can do manually (a trader can have both a buy limit and sell limit order working in the Control Center, for example), and the restrictions solve some problems, while creating others.Originally posted by NinjaTrader_Josh View PostPlease review the article in the Help Guide for all the rules.
Thanks.
Comment
-
ntVic,
It does not work that way. How do you know to place a reversal order? Your orders are in flight executions. You get part filled long then you get part filled short, but your short order went in before it knew there was a part filled long so no reversal order was attached to it. How would you ID such a condition? You cannot reliably detect in flight executions and as such the rules are in place.Josh P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
104 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
52 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
34 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
38 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
74 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment