Hi Guys:
Auto Trading a well tested strategy got the following odd behavior.
1) System opens a position correctly
2) System sends protective OCO orders (sell stop and sell limit) accordingly below and above the trading price.
3) Both OCO Orders correctly are submitted and are confirmed as ACTIVE (both in WL Pro and AT Pro)
4) Time goes by....
5) When an exit condition is triggered (not the placed orders but internal to the strategy's logic), the system doesn't renew the OCO orders (expecting them to be canceled) and issues a Market Sell order (bar+1).
6) The order manager correctly sends the cancelation instruction for both OCO orders.
7) While the OCO orders are in status "Pending Cancel" the order manager attemps to send the Market Sell order which fails with an error (because the OCO orders have not finished canceling).
8) The OCO orders finally receive their confirmed cancel status but the Market Sell order remains in error status.
The position would have not been correctly exited because of this error, and the only way around it is to be constantly monitoring the order manager to see if this happens and then manually resend the Market Sell order so that the position is correctly exited.
Of course in backtesting and in paper trading the strategy behaves correctly. This only happens in true live trading.
Should some kind of delay or sleep need to be executed inside the code to allow the extra time the OCO orders need to receive cancelation status?
This doesn't happen all the time for the same strategy (it would seem maybe some time of network hiccups causes them to happen). Of course if the strategy is executed with Auto Trading Off and the alerts are only placed in the order manager, the human tends to send the cancel orders and wait for their status to be confirmed cancel before sending the market sell order so in that scenario the error never happens. It only happens in the fast execution during Auto trading.
I couldn't find any thread referring to this kind of problem. And the user guide doesn't indicate any special behavior needs to be changed when taking a strategy from paper trading to live auto trading.
Thanks for the help.
Size:
Color:
Thanks for the post, very good description. The OCO cancel is delayed based on receipt from the back end. A script delay would not help since it must finish executing for WLP to determine that the OCO has not been refreshed. The Orders tool needs to handle the delayed cancel response better before transmitting the new order, and since it should already do that correctly, we'll call it a bug. Please create a Support ticket for this one.
Just to be sure, your script actually sends a Market order, not a limit order beyond the marketeable price, right? For example, if a stock is trading at 20.15 and you send a SellAtLimit 20.00, WLP executes the order hypothetically at 20.15 (at market), but unfortunately Fidelity will cancel this order since they won't accept a limit order beyond the inside market.
Size:
Color:
QUOTE:
Just to be sure, your script actually sends a Market order, not a limit order beyond the marketeable price, right?
Yes, my script only enters and exits the market with market orders. The only limit and stop losses it uses are the OCO it places for protection (in case of Internet disconnect, computer failure, etc...) but the actual logic entries and exits are all SellAtMarket orders.
Will create a ticket for this.
thanks.
Size:
Color:
Ticket 22152 created
Size:
Color: