Profile Picture

IB paper trading: Stop Loss and Take Profit orders from OpenPosition get cancelled at the end of the...

Posted By davidS 8 Years Ago

IB paper trading: Stop Loss and Take Profit orders from OpenPosition...

Message
Posted Friday April 10 2009
I've recently switched from back-testing to paper trading at IB. I've found that the stop loss and take profit orders associated with OpenPosition are entered as day orders. As a result, all SL and TP orders are cancelled at the end of the day. This generates non-fatal errors upon reconnection the next day, when RE checks to see if the orders are still active. It's a real pain to place all of these orders manually.

How can I get RE to place SL and TP orders as GTC?

One other question: RE places SL and TP orders with an attribute allowing transactions outside RTH. IB doesn't seem to allow this for SL orders. IB issues a warning and places the SL order for RTH only (fine with me, except for the warning). How can I better control this behavior? I would like to allow TP outside RTH.
Posted Tuesday April 14 2009
Hi folks, I'm still banging my head against this one. Am I missing something obvious? Why does IB receive stop loss and take profit orders (originated by OpenPosition) as day orders rather than GTC? Is there any way to force them to be GTC? Also, how can I control whether or not SL and TP orders can be executed outside RTH?

When I start RE up for the next trading day, the lack of SL and TP orders for my open positions causes numerous startup warnings from the PositionManager. I've been unable to find a way to clean up this mess and continue trading.
Posted Tuesday April 14 2009
It's being debugged. Bottom line though, we always send follow up orders at GTC. From the looks of it, either the socket interface or TWS is not acknowledging that setting. I hope it's something we can fix.

davidS (4/14/2009)
Hi folks, I'm still banging my head against this one. Am I missing something obvious? Why does IB receive stop loss and take profit orders (originated by OpenPosition) as day orders rather than GTC? Is there any way to force them to be GTC? Also, how can I control whether or not SL and TP orders can be executed outside RTH?

When I start RE up for the next trading day, the lack of SL and TP orders for my open positions causes numerous startup warnings from the PositionManager. I've been unable to find a way to clean up this mess and continue trading.
Posted Tuesday April 14 2009
Thanks. Please let me know if there is anything that I can do to help.
Posted Wednesday April 15 2009
Work around for this issue: at the end of RTH, use the TWS application to manually change all SL and TP Day orders to GTC. On starting RE the next day, the modified orders are recognized as part of the existing position, and trading proceeds normally.
Posted Wednesday April 15 2009
Hmm, I can't figure out how to submit a GTC order to TWS using their API.  There is a time in force value, but setting it to GTC didn't work.  You can modify the orders yourself in TWS, or you can use the following code to have your system resubmit the orders at the start of each day:

if (!order.CancelPending)

{

      if (information == "Order cancelled while disconnected.")

      {

            if (order.TradeType == TradeType.ProfitTarget)

            {

                  OutputMessage("Resending profit target");

                  position.SetProfitTarget(0, TargetPriceType.Price);

                  position.SetProfitTarget(order.LimitPrice, TargetPriceType.Price);

            }

            else if (order.TradeType == TradeType.StopLoss)

            {

                  OutputMessage("Resending stop loss");

                  position.SetStopLoss(0, TargetPriceType.Price);

                  position.SetStopLoss(order.StopPrice, TargetPriceType.Price);

            }

            else

            {

                  OutputMessage("Non PL/SL order cancelled while disconnected.");

            }

      }

      else 

      {

            OutputWarning("Order cancelled: " + information);

      }

}

Thanks,
Daniel

Posted Thursday April 16 2009
Thanks so much, this is a nice solution -- I will try it tomorrow, then add it to my collection of RE/IB tips and tricks.

Posted Thursday April 16 2009
Daniel,

Sorry to be thick, but where does this code go? Do I need to create an event handler for OrderUpdated?

David
phg
Supreme Being (44,897 reputation)Supreme Being (44,897 reputation)Supreme Being (44,897 reputation)Supreme Being (44,897 reputation)Supreme Being (44,897 reputation)Supreme Being (44,897 reputation)Supreme Being (44,897 reputation)Supreme Being (44,897 reputation)Supreme Being (44,897 reputation)
Posted Thursday April 16 2009
If you are working with the IB IOrder interface, see
timeInForce() As String   The time in force. Valid values are: DAY, GTC, IOC, GTD.

-Pete

See also Yahoo group about applying RE.

Posted Thursday April 16 2009
davidS (4/16/2009)
Daniel,

Sorry to be thick, but where does this code go? Do I need to create an event handler for OrderUpdated?

David


Never mind; I figured it out. I'll give it a try and post my results within the next couple of days.

Thanks,
David


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems