Profile Picture

Stoploss handling

Posted By tickbytick 6 Years Ago
Message
Posted Thursday November 10 2011
If I open a position using OpenPosition(settings) and specify a stop this will generate a stop market order once the position has opened.

I want to replace this order with a stop limit order so that the order can sit natively at the exchange.

1. is there any way that I can define the position stop as a stop limit when I define and submit OpenPosition?

2. if 1. is not possible can I modify the stop order once the position is opened or do I need to cancel it and create a replacement order ?

thanks
Robert

Posted Friday November 11 2011
No to both questions- you'll have to submit the orders manually. If you always want to use stop limit instead of stop orders though, you could modify your broker plugin to just send stop limit orders when you send stop orders. Then you wouldn't have to do anything special in your system.

Thanks,
Daniel
Posted Friday November 11 2011
I'm worried about the potential for a race condition doing cancel/replace so modifying the plugin sounds like the better bet.

I don't want to make all stop orders stop_limit though.

I tried to use the CustomString to pass information to the plugin about whether to use stop_limit or stop_market but setting it for the position doesn't pass it on as the CustomString of the stop order.

How can I either set the CustomString for the stop order when the position is created, or, access the position CustomString for the stop order from the TWS plugin?


All help and ideas much appreciated!


Robert
Posted Sunday November 13 2011
When you set the CustomString on a PositionSettings object, it should be set on the order that opens the position. The BrokerOrder class has a PositionID property, so you should be able record the CustomString for the first order sent for a position and then link the stop orders to that position.

Does that sound like it would work for you?

Thanks,
Daniel
Posted Sunday November 13 2011
stretching the limits of my cut & paste coding skills here Daniel!

so something like...in SubmitOrder() use a dictionary to hold PosID and CustomString when an order comes in with a CustomString

then

when a stop order comes in I can lookup the CustomString from the dictionary and take action accordingly and remove the dictionary entry.


I also need to remove the dictionary entry if the order is cancelled - do I do that in internalCancelOrder() ?

thanks
Robert
Posted Wednesday November 16 2011
That is pretty much correct. It's probably easier if you don't remove any entries from the dictionary. The reason is that if you resize the position or there is a partial fill, RightEdge will cancel the stop order and submit a new one with an updated size.

Also, do you hold positions open overnight? If you stop and restart your live system, the information from the dictionary would be lost.

Thanks,
Daniel


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems