IB/Excel time orders

Discussion in 'Trading Software' started by Gordon Gekko, Apr 16, 2004.

  1. is it possible to have excel send orders to IB at a certain time? for example, i'd like to enter a symbol, position size, and time into excel and have it sent to IB at that time? i don't need anything fancy.

    if this is possible, anyone know if there is a excel file already made similar to this on IB's site or another trading site?

  2. actually, i already thought of a problem.

    my intention is to use this to close positions if not stopped out when i want to leave my computer. so say i'm long 2 ES and i have a stop order set in TWS. i could put a order in Excel to sell 2 ES at x time at market. the problem is, if i get stopped out, the order from excel would be entering a new position.

    is there a reasonably simple solution to this?
  3. I don't know if it's accessible via the API, but you can use the "Good after Time" order and a stop order that have the same OCA code.
  4. gms


    You would have excel perform an "if" function first to determine if the position has been exited. I'm thinking off the top of my head not ever having specifically written the function to do so. For example, if when a position is exited then the exit price is displayed in a certain cell, the if function could be programmed to see if that cell's value is > 0. If the condition results False, then your function would go to the next function dealing with the time factor.

    For "time", see the functions under Date and Time. You'll have to figure out what the serial number is for the times you wish to exit, then the logic would be along the lines of 'if NOW >= Serial Number (Time you want to exit)'.
  5. alanm


    Is there a reason you want to use Excel?

    If not, you can do this directly in TWS:

    - Put 1 in the OCA field of your stop order
    - Create your close-out order and fill in the "Good After Time" (GAT) field with the appropriate time. Also put 1 in the OCA field.

    If either order is filled, it cancels the other. So, if your stop is hit, it cancels the GAT order. If the stop is not hit, when the GAT order is filled, it cancels the stop.

    There is a slight amount of risk in the stop getting hit at exactly the moment after the GAT time has passed, but before IB has sent the order, and then the GAT order also getting filled before it can cancel it. This time frame is probably _very_ short, but just know that it's there. There might also be something you can do with Conditional orders that could help.

    Can someone who has used GAT orders comment on exactly how soon after the specified time the order is sent (i.e. less than a second, 5 seconds, etc.).
  6. I prefer alanm's suggestion of entering a timed order right in TWS but there is a "dde.xls" sample file that comes with the TWS download. You should be able to find it in the "C:\JTS\excel" folder on your computer. You could modify that file and use the "ontime" function of Excel's visual basic to send an order. There are also functions on that sample sheet already which can check the status of any open orders or positions before you send out your timed order.

    Here's a page that shows how the ontime function is used:
  7. AlanM,

    My experience with them is that you can specify to the second what time you want and it's been "instantaneous", ie. imperceptible delay.
  8. great suggestions! thanks everyone! :cool: