Help with Automation - TWS

Discussion in 'Automated Trading' started by ladidalimey, Oct 22, 2008.

  1. Hi,

    I want to semi-automate a trade that is as follows:

    Buy at daily open + number(known in advance) stop

    e.g. DAX opens at 4600, I want to add 80 to open, so order would be buy x contracts at 4680 stop.

    Up until now I have been using a combo of tradestation, tradebullet and IB, which I don't like when trading a lot of markets simulateously. It can be an unstable combination.

    Is there a broker software where I could directly enter the order in advance?
    I can't see how to do it with TWS.

    Or alternatively TWS + one other piece of software i.e. getting TS out of the loop?


  2. I should add I would be willing to change brokers if necessary.
  3. how would you enter the order in advance of the open, if you need the opening price to calculate the price of your order?

    it sounds a little like opg orders is what you're looking for (ib doesn't support these I'm pretty sure), but the way you described it won't work if you're setting the price based on the open. an opg order type is a limit order that can only get filled on the opening print (moc cept for open).

    you could do this pretty easily in tradelink, which is free and works with IB:

    public class FuturesOpen : Response
    decimal orderoffset = .8;
    int entrysize = 1;
    decimal open =0;
    bool isOpen { get { return open!=0; }}
    void GotTick(Tick tick)
      // ignore quotes
      if (!tick.isTrade) return;
      // if we've opened already thats it
      if (isOpen) return;
     // get opening price and send order
       open =;
      Order o = new BuyLimit(tick.symbol,entrysize, open+offset);
      o.Security = SecurityType.FUT;
      o.LocalSymbol = 'DAXZ8'; // or whatever

    for more info, see project website here: http:///
  4. This would be really simple to automate with Ninjatrader and it'd work with your broker.

    To make it even more interesting, if you have an algorithm for determining your buy stop price then you could backtest it and see if you can optimize it. Just a thought!
  5. Hi,

    Thanks for your reply.

    I already use TradingBlox for system testing, but its a little weak on the trade automation front (in all other restpect it is excellent).

    Are you a Ninjatrader user? Could I put the orders in at some point before the open is known?


  6. Tums


    If this is all you do, then excel is all you need.

    IB has a sample excel worksheet. Check your TWS directory.
  7. I'm only using Ninjatrader for backtesting at this time. I hope to run some automated systems soon.

    I was assuming you could automate the calculation of your target. If so then Ninjatrader can do it. If you have to calculate it by hand yourself, then I'm not sure but i don't see why not.
  8. Hi,

    My original point was that I want to automate the placing of a stop entry immediately after the open which involves the open in the calculation . I wanted to place the order automatically as soon as the open becomes known.

  9. This is easy to do with a strategy in ninjatrader.
  10. ivok


    Hi there,

    can I jump in here? I have exactly the same question and want to realize it with the ib api within excel / access. Downloading the api-stuff was the easy part.

    Can some kind soul provide some code snippets for vba to get started (I've got some experience with vba but not with the api)?.

    I'd like to
    1. place a market order at (virtual) open for the es at 08:30 am for the es-future.
    2. get the fill-price
    3. calculate fillprice +/- x%
    4. place stop-order

    I have the tws running and api-interaction is enabled.

    Many thanks
    #10     Nov 15, 2008