Profile Picture

Intraday system and trailing stop orders

Posted By xzajic2 8 Years Ago
Smile Posted Sunday July 18 2010
I'm testing some intraday 5-min trading system and I've a question. My system uses trailing stop, so I've some code like this:

PositionManager.SetTrailingStop(pos.ID, amount, TargetPriceType.RelativePrice)

Works ok, RE sends trailing stop order to IB and the order is executed (depending of price movement, of course).

But: if there is "pending" trailing stop order on the end of the day, I'd like to cancel it and sell EVERYTHING on CloseAtMarket. How to do this correctly? Is it sufficient to call something like

If Bars.Current.BarStartTime.Hour = 15 And Bars.Current.BarStartTime.Minute =25 Then
For Each pos As Position In OpenPositions
End If

or I need to cancel pending position first? Could someone provide a piece of sample code?
Posted Monday July 19 2010
That may work, but if you're cancelling existing orders, you may want to wait for the cancels to come back as cancelled before you close positions. So you would hook into OrderUpdated and wait for your cancels to close. Once all orders are cancelled, the foreach loop you have is the right way to do it. You could also use CloseAllPositions.
Posted Tuesday July 20 2010
Sounds good. Thank you.

Similar Topics

Reading This Topic

2005-2018 © RightEdge Systems