- ago
I have been working to understand particular aspects of how API works with TWS and live trading. The type of trade I was testing was a "stacked" Sell, i.e., Sell At Limit and Sell At Market At Close on same bar. Idea is you try to sell at some target price but if you can't get it, then exit the position at market at the close.

If I manually place two orders in TWS (not using WL8) and the limit is hit, it will sell the position and then short a new position at market close. In order to make this trade work correctly manually I must use what TWS calls an OCA (One Cancels All) trade. This is an advanced feature of the trade ticket that lets you group trades. If any trade executes, all the others in the group are cancelled.

Using the TWS API in WL8, this trade construct does not create an OCA trade at BI but appears to manage it in the Position manager, only sending the Market Order to BI before the close if the Limit has not executed. This worked perfectly in testing, except I noted that if WL8 is restarted after placing initial trade and before market close, the CloseAtMarket is lost from the Position Manager. In other words, proper execution of this trade requires WL8 to be running uninterrupted during market hours.

Also, it appears that with the converse trade of a Buy limit with Buy at Close WL8 does not treat these as exclusive trades and would buy twice if limit is executed.

Do I understand all this correctly?

A related question is if I run a strategy outside of market hours and it attempts to place a buy on open the next day, it appears that BI warns that the order will not be placed until the next day. Is that order held and managed in BI system for execution, or does it depend on WL8 position manager sending before market next day?
0
1,089
12 Replies

Reply

Bookmark

Sort
Cone8
 ( 26.65% )
- ago
#1
We implemented IB's OCA feature for bracket orders, but probably not a Limit and a MarketClose combination. Even for IB this is a troublesome order because if the limit order fills in the last 5 or 10 minutes of the day, it's impossible to cancel the MOC order living on the exchange.

QUOTE:
it appears that BI warns that the order will not be placed until the next day.
Don't be confused. The warning really isn't for the "next day" - it's for the next session open.

You should probably bypass these nuisance precautionary warnings. In TWS > API > Precautions > Bypass Order Precautions for API Orders
0
- ago
#2
QUOTE:
Even for IB this is a troublesome order because if the limit order fills in the last 5 or 10 minutes of the day, it's impossible to cancel the MOC order living on the exchange.

I'm not sure that would be a concern if you create an OCA order within the TWS. The way OCA works, BI would cancel the market close order if the limit order executed before market close. I don't believe the time window restriction applies here, only to placing *new* orders.

If TWS OCA were implemented for this type of order, then it wouldn't matter if WL got disconnected before market close once the order was placed.
0
Cone8
 ( 26.65% )
- ago
#3
Currently, we're set up only to match 2 orders for OCO and they have to be Stop/Limit. It would be an enhancement (feature request) to include more orders and different types. Remember, we're working with a single broker framework that supports any broker, not just IB.

Here's the NYSE exchange rule. It's basically impossible to cancel a MOC/LOC order after 3:50pm on the NYSE (it's similar for NASDAQ, but the time is 3:55pm). You can continue to believe this order will be canceled with OCO after this time, but you would be mistaken. But I understand what you're saying about the order being placed as OCO instead of using Wealth-Lab's "back-up" OCO function.

https://www.nyse.com/publicdocs/nyse/markets/nyse/NYSE_Opening_and_Closing_Auctions_Fact_Sheet.pdf
0
- ago
#4
QUOTE:
You can continue to believe this order will be canceled with OCO after this time, but you would be mistaken.

I must not understand what you are explaining. An OCO MOC/LOC order paired with a Limit order placed more than 15 min before closing *must* cancel one of these upon execution of MOC/LOC or Limit, by definition. I have tested this myself on BI (manually entered with OCA structure) and it works as promised.

Are you saying that in the above OCA example manually entered on BI, if the limit were hit 4 minutes before closing, both orders would execute? Or are referring to the case where WL8 is managing the OCO logic and transmitting to BI via API?
0
Cone8
 ( 26.65% )
- ago
#5
QUOTE:
if the limit were hit 4 minutes before closing, both orders would execute
Yes, because the MOC/LOC couldn't be canceled at that time. I'm not making it up, the link to the NYSE rules are in Post #3.
0
- ago
#6
Now I understand this is not a IB issue or a WL issue. It is a regulatory issue. Thank you.

I also was mistaken about TWS providing the capability to include a MOC order in an OCA construct. I'm guessing they don't support it because of the uncertainty the rule you cited causes.

The ironic thing is that WL8 actually allows for pairing a Limit order with MOC (with the caveat of the same regulatory exception), since WL manages the trade logic through the Orders page. What if there were a rule or option that for "stacked" Limit / MOC orders, the Limit order would be cancelled if not executed 15 min before closing?
0
Cone8
 ( 26.65% )
- ago
#7
That could be the basis for a good argument for a GTD (good-til-date) order >> feature request.
0
- ago
#8
GTD or GTT? Currently Limit orders placed through WL8 are GTC by default, right?
0
Cone8
 ( 26.65% )
- ago
#9
GTD has a time too.
Wealth-Lab orders are Day TIF by default, not GTC.
0
- ago
#10
I wanted to revisit the capability to "stack" an MOC order with a limit order with automated trading. The idea is a strategy might prefer to Sell (or Buy) at a limit price but if it is not filled near end of day, replace it with a market order.

(Note: this is related / referenced with the request for a GTD order capability. https://www.wealth-lab.com/Discussion/GTD-Order-8169) One application of GTD is to allow "virtual stacking" of Limit + MOC order where limit can expire before staged MOC is placed (based on trading preferences), avoiding rejection of this structure for non-margin accounts, like IRA's.

The reason I thought about revisiting this is the inclusion of new functionality for placing MOC orders implemented in WL8 B24,: the capability to set trading preferences to place MOC orders "immediately" or "stage" for a selected time before market close. If it is not looking like GTD is on the radar, then an idea is to add functionality so an MOC trade will cancel any other potentially conflcting orders before sending MOC to broker, avoiding the potential for dupicate trades.

Practically, this would only work if the MOC is "staged" (per trade preferences) and not placed immediately.

I realize this is a feature request and I am wondering what you think about this approach. Maybe it is potentially easier to implement than GTD?
0
Cone8
 ( 26.65% )
- ago
#11
You can cancel placed MOC orders too as long as you do it "in time". I think you can already do everything you want to do if you control the logic with an intraday strategy.

This topic is getting pretty convoluted now, and the logic has changed since it was started. My advice is to start new thread, mark it as a feature request, and state it in a concise way with a clear usage example - you need to "sell the idea" so others will vote for it.
0
- ago
#12
Thanks for the advice. I created it here: https://www.wealth-lab.com/Discussion/MOC-Order-Cancels-Conflicting-Orders-9013

Let me know if you have suggestions to improve clarity.

Note: this is for Daily trading, not intraday.
0

Reply

Bookmark

Sort