My strategy shut itself down after exiting a position today as there was a duplicate request to cancel the unused stop loss order after my short was exited using a market order to close the position.
I was short 2 lots, and closed out the position by buying back 2 lots at market, all via an automated strategy. Upon closing a positon via my strategy NinjaTrader then automatically takes care of any associated stop loss and profit target orders that were not filled by cancelling those unused orders.
As expected, it cancelled the stop loss order, thus:
28/11/2011 09:15:01|1|32|Order='0K7T6R386/DDT78244' Name='Stop loss' New state=PendingCancel Instrument='FGBL 12-11' Action=BuyToCover Limit price=0 Stop price=134.27 Quantity=1
(Note, the position was filled at entry separately by 1 lot, then a second lot (partfilled, then filled), so there were in fact 2 stop loss orders and 2 profit target orders associated with the position - I refer here only to the first stop loss order (0K7T6R386, 1 lot) as that was the first one to be duplicated and hence caused the strategy shut down.)
...but before the broker's system could confirm this stop loss order as cancelled and could update the order status, a few lines later in the log (still at 09:15:01) the cancellation was requested for the same order (0k7T6R386) a second time, with 'NewState' again as 'PendingCancel'.
This caused the following error message:
'Order rejected: Broker or exchange option
From Gateway: pending terminal action already exists for order 0K7T6R386 affected Order: BuyToCover 1 Stop @ 134.27'
The cancellation of stop loss and profit target orders associated with the original short trade is not explicitly managed by my code, but is dealt with by the Ninja internal managed orders set up.
Can anyone give guidance as to why this duplicate cancellation may have occurred, and how to prevent a re-occurence?
many thanks
Comment