- ago
QUOTE:
It should cancel the limit order only if you assigned the same CancellationCode for both orders in the strategy.


Interesting. Just this morning I came across the following reply you sent me. I didn't understand it fully at the time and was going to ask you about it.

QUOTE:
Assign the same CancelationCode before both orders. Once filled, Wealth-Lab will cancel the opposite order.

CODE:
CancelationCode = 42;
ClosePosition(... OrderType.Limit,..);
CancelationCode = 42;
ClosePosition(... OrderType.MarketClose,..);


Is this cancellation code an arbitrary number?

I haven't used this construct but I seem to recall that in the trade structure Limit + MOC, when the limit is executed, the MOC is deleted automatically. I also thought there was some logic in the Order Manager that deleted a limit order before placing the MOC. Am I wrong?

A related issue is I am wondering if the broker will accept an MOC order though the API when a Limit Order is still active. It will reject the order if I try this manually. I have to delete the Limit order before placing the MOC. Is there some logic in WL to get around this, or is it cancelling the Limit Order before placing the MOC? I must be missing something here or the Limit Order + (pending) MOC would not work (i.e., trade "stacking").

Some additional detail on how the Order Manager processes pending orders behind the scenes might help me see the big picture.
0
774
10 Replies

Reply

Bookmark

Sort
- ago
#1
To answer one of my own questions, I ran an experiment with IB/TWS paper trading. Using WL and the API, I generated two trades with Sell Limits much higher than would possibly be triggered, and also incorporated MOC Sell orders on both to see what would happen.

The MOC orders were sent to broker 15 min before market close (per Preference Settings) while the Limit orders were still active. The MOC orders were accepted by broker. WL did *not* cancel the Limit order.

At market close, both MOC Sell orders were executed successfully. WL sent cancellations for Limit orders to broker, which were successfully canceled, either because WL detected positions were sold, or because it was end-of-day.

I was surprised the MOC orders were accepted while the Limit orders were still active. I think if I entered that manually via TWS I would get a rejection. (I did with TDA ToS.) Wondering if the API by-passes some restrictions, or it had to do with it being a paper account.

At any rate the Order Manager does *not* automatically cancel the Limit order when it places an MOC instruction with broker. Using the CancelationCode would not have had an effect here, because it would not have taken effect until MOC executed, which was EOD anyhow. Maybe that's what @Cone was thinking when he suggested a new GTD order feature ( https://www.wealth-lab.com/Discussion/TWS-OCA-and-Trade-Stacking-8115 ) to handle the Limit / MOC order potential conflict.
QUOTE:
That could be the basis for a good argument for a GTD (good-til-date) order >> feature request.

QUOTE:
GTD has a time too.
Wealth-Lab orders are Day TIF by default, not GTC.


Do we need a feature request created for this?
0
- ago
#2
QUOTE:
Do we need a feature request created for this?

We already have one for GTD, shouldn't be much difference in the context of implementation - or its potential inapplicability:
https://www.wealth-lab.com/Discussion/GTD-Order-8169
0
- ago
#3
Thanks, @Eugene. Pretty low on the list right now. Maybe not too many users are doing automated trading?
0
- ago
#4
I just found another issue with a Limit trade stacked with an MOC. In my IRA account, the MOC trade was rejected by IB because the Limit trade was still active. The System message was that my account (presumably because it's an IRA) cannot short a stock (which is presumably what would happen if the Limit executed after the MOC was placed, although, ironically, it couldn't take a short because it's an IRA account). The Limit was not close to hitting but that's irrelevant.

The main reason I'm using IB as a broker is that they accepted MOC trades stacked on Limits, but now I see that's only for a non-IRA account, and possibly only if it's a margin account. The utility of API auto-trading (at least for a strategy that uses the Limit /MOC construct) is limited until there is a way to cancel Limits before placing MOC.

I know this is a rehash, but I wanted to share an additional use case that supports addressing the Limit / MOC limitation.
0
- ago
#5
QUOTE:
... my account (presumably because it's an IRA) cannot short a stock (which is presumably what would happen if the Limit executed after the MOC was placed,...

Just to be clear, only accounts with margin can buy short. And I think that's true for all brokers. Moreover, IRA accounts don't typically qualify for margin. (I wonder why?) So the result is IRA accounts will never buy short.
0
Cone8
 ( 26.65% )
- ago
#6
Off topic, but many brokers offer "Limited Margin" accounts for IRA accounts funded with more than $120K (varies by broker). You can short futures and get T+0 settlement for stocks, but you cannot hold stock short.

1
- ago
#7
QUOTE:
many brokers offer "Limit Margin" accounts for IRA accounts funded with more than $120K

Huh. Didn't know that. Thanks.
0
Cone8
 ( 26.65% )
- ago
#8
Corrected to "Limited Margin"
0
- ago
#9
QUOTE:
Corrected to "Limited Margin"

I have "Limited Margin" on my IRA account, which gives me permission to use available cash from sales for new trades immediately (without waiting for T+2). I can't borrow $$ for leverage. Note that you can't SELL the NEW trade(s) before T+2 without incurring a Freeriding Violation.

(I'm referring to stocks and ETFs here, not options, which are T+1.)
0
- ago
#10
Posted Feature Request relevant to this issue here: https://www.wealth-lab.com/Discussion/MOC-Order-Cancels-Conflicting-Orders-9013
0

Reply

Bookmark

Sort