Support Board
Date/Time: Tue, 13 May 2025 22:14:27 +0000
Post From: Flattening position without orders - PT doesnt reset LastFillDateTime nor LastExitDateTime
[2016-05-04 11:47:14] |
wat - Posts: 67 |
I am trying to flatten position when there is not PT or stop loss. During simulation or replay there is no problem but when connected to IB, hitting stoploss works fine but hitting PT (which is limit order) causes: strategy sees no PT and LastFillDateTime and LastExitDateTime are old, flattens position LastFill 51.594000 s ago, LastEntry 51.594000 s ago, LastExit 1490.935000 s ago | 2016-05-03 16:59:52
position gets canceled and flattened into negativeLastFill 1.835000 s ago, LastEntry 1.835000 s ago, LastExit 2.240000 s ago | 2016-05-03 16:59:55
position gets flattened again because no orders and gets to 0.My problem is that PT dissapears but neither LastFillDateTime nor LastExitDateTime is set hence it looks like the position is without orders. if(PositionData.PositionQuantity != 0) {
if((sc.GetNearestStopOrder(Order) == 0 || sc.GetNearestTargetOrder(Order) == 0) && (sc.LatestDateTimeForLastBar - PositionData.LastFillDateTime)/SECONDS > 1) { sc.FlattenAndCancelAllOrders(); } } Is there a way to make it work? Thank you. |