Simulating On-Close Orders with Interactive Brokers (IB)

Previously (here and here) on this blog, I have demonstrated how to implemented an end-of-day trading strategy in real life. The common problem mentioned is that one cannot possibly get the signal and execute the trade at the same time. Well, I can.

In these posts, I concentrated on on-close orders, the Interactive Broker’s LOC and MOC orders. We also discovered that they are not sufficient to cover all scenario. To refresh, for the following table of action (it may come from a simple moving average system) a LOC order will not work:

Close Pct Position
$118.27 -10.00% None
$129.16 -1.71% Long
$144.55 10.01% Long

Assuming we are currently out of the market, the table suggests (it has been pre-computed) that the systemic position is long as long as the closing price is equal or above $129.16. The reason a LOC order won’t work is because we want to go long if the market closes at or above $129.16. This is the opposite of a limit order, so not a LOC.

Again Interactive Brokers comes to rescue. What I use in these cases is their conditional order. For the above situation, I will add a market order and then I will set two conditions to it:

  • Price above or equal $129.16
  • Execution time – I use 15:59:58 or later

I have been using this approach for a while now and it has worked quite well in practice.

An interesting feature is that when the price condition is set (the first condition above) in TWS, one chooses the instrument to place the condition on. Thus, the instrument used in the condition may be different than the traded instrument. One can use the SPY signals, to trade the futures!

Another feature that I have found useful, is that one can group the orders (set when the order is created). Thus, one can send two opposite conditional orders (one short, one long), for the same time, using different price limits (I want to be short above certain price, long otherwise and I am out of the market). Then, the group can be marked in such way that when one order gets executed, all others get canceled. Pretty ingenious – Interactive Brokers at their best. There is a slight risk that both orders may get triggered, so please read the documentation before employing any of these.

Leave a Reply