Attached Sell MOC order filled at the open

Hello guys,

A couple info that might be relevant:

  • Norgate Data
  • IB Paper Trading
  • Sending a Buy LMT order to IB Controller and attaching a Sell MOC order
  • Since I was getting some " The contract description is ambiguous” messages, I had to specify the exchange to the IB controller...
  • Since sending a Sell MOC to the NYSE was answering something along the line of "this kind of order is not supported", I had to route NYSE orders to SMART...
// Get symbol's market
StockMarketName = StrToUpper( MarketID(1) );
StockMarketName = WriteIf(StockMarketName=="NASDAQ","ISLAND",StockMarketName);
StockMarketName = WriteIf(StockMarketName=="NYSE","SMART",StockMarketName);
ContractFullName = Name() + "-" + StockMarketName + "-STK-USD";

// transmit order
parentID = ibc.PlaceOrder( ContractFullName, "Buy", LastValue(BuyQuantity), "STP", 0, LastValue(LimitPrice), "Day", False ); // place order but do not transmit yet
ibc.PlaceOrder(ContractFullName, "SELL", LastValue(BuyQuantity), "MOC", 0, 0, "Day", True, 100, "", parentID );

Now obviously I hope to get a cleaner solution but I already have a problem : the MOC SELL order, routed to Nasdaq / Island has been filled seconds after opening the position...

NB: time on the screenshorts are European time, so it's basically 9:30 in NYC...

MOC seconds after entering position

Does anyone knows if that's due to Paper Trading or maybe to sending MOC orders to Island/Nasdaq ?

Or maybe attaching MOC to the parent order is not a good solution at all, but in that case, do you have any suggestion of a workaround ?

Thanks a lot,

Hummm, I still haven't found the issue but I think I spotted a mistake in the documentation.

@Tomasz On this page : autotrading page

This here:

GTD yyyymmdd hh:mm:ss tzone;GAT YYYYYMMDD HH:MM:SS TZONE - GTD order valid after specified time

Should be the other way around or it doesn't work:

GAT YYYYYMMDD HH:MM:SS TZONE;GTD yyyymmdd hh:mm:ss tzone

EDIT : Nevermind : my suggestion doesn't trigger any error but doesn't place GAT et GTD at all...

But it looks like the solution inside the documentation doesn't work:

IB Controller 1.38 does not support many order types, though the documentation of ibcontroller on Readme page mentions a number of them..

Well in that case it all looks fine with IBController, maybe it's just a paper trading problem, I'll see.

Else the workflow to do the same without MOC is a bit more work!!

As in the docs:

ibc.PlaceOrder("MSFT", "BUY", 100, "LMT", 27, 0, "DAY;GAT 20051214 18:00:00 GMT", True );
- day limit order good after Dec 14,2005, 18:00 GMT

ibc.PlaceOrder("MSFT", "BUY", 100, "LMT", 27, 0, "GTD 20051215 17:00:00 GMT;GAT 20051214 18:00:00 GMT", True );
- limit order valid from Dec 14,2005 18:00 to Dec 15,2005 17:00 GMT

ibc.PlaceOrder("MSFT", "BUY", 100, "LMT", 27, 0, "GTD 20051215 19:00:00 GMT", True );
- limit order valid from now until Dec 15,2005 19:00 GMT

IBController is open source. Really, you can look at the source. The truth is that IBController does NOT do any real processing, it just passes whatever you throw at it. It is up to TWS to accept and execute.

TimeInForce parameter is handled in lines 574-600

TBH I really suspect it's an IB issue...

Since I got an attached MOC filled at the open, I tried using GAT/GTD on the Buy order attached to the MOC but it didn't work as expected.

Apparently it could be an IB problem, cf: dmitrys-tws-api-faq (

[Q] Note: good-after-time (GAT) orders are not supported for ("generic") combo orders!

[A] by

Just a heads-up that took me a while to sort through this morning: Via API or not, good-after-time (GAT) orders are not supported for ("generic") combo orders, despite what the online documentation would have you believe.