how to exit at 20 SMA?

Discussion in 'Automated Trading' started by gnom, May 24, 2010.

  1. gnom


    I’m trying to close long positions on IB when high of the bar is higher 20 SMA (simple moving average). Is there a way to do through API or trough IB platform?
  2. Don't think you can do it on the standard TWS. It seems like they continue to think about adding a custom indicator to their triggers, but I haven't seen it implemented yet.

    The actual exit at 20 SMA and placing orders is not difficult in TWS. How much monitoring you want to have in place will dictate how big your coding effort is (i.e: you leave for a month and let it run adds much more work as opposed to you sitting in the next room).

    Remember that you'll be at the mercy of your internet connection when implementing this exit, since this logic isn't on the TWS server side. With something like this, I'd have a stop order placed at TWS that you modify once your condition is met. This way you'll already have a "Get Out Of Dodge" order on the TWS side in the event your system drops out.
  3. gnom


    Thank you,
    Can I send order like this to IB through API or do I need manually eneter is if I want to exit at 20 SMA? I don't use API right now and enter orders manually but it gets tough when things are busy.

  4. You could certainly create this order in the API. I haven't played with using the API to modify non-API orders (i.e: something you'd placed yourself).

    You could enter the position by hand and then have the API enter the 2nd order. Your program would monitor the market prices and compute the 20SMA. When your logic indicates an exit, you could modify the 2nd order so that it executes.

    You could also do it so the API just sends an order when your logic it triggered, but I just like to have something already at TWS in case something goes wrong.