I've got an automated strategy that uses Stops/Targets and moves to breakeven. Under certain conditions it also reverses.
I originally tried ExitLong()/ExitShort() for the reversal, and then re-enter separately, but had some problems with the strategy shutting down due to reported Overfill (although they didn't show up in the executions/strategies tabs of the Control Center (CC).
Next I tried to use the EnterLong()/EnterShort() and let NT handle the Close Position, and re-enter. This seemed pretty good, no strategy shutdowns or reported overfills. However, in going back over executions tab in CC, there were times that the position was reported as 4 contracts when it should have been only 2.
Using TraceOrders = true; and throwing in some additional debugging code in OnOrderUpdate(), OnExecution(), OnPositionUpdate() etc., it seems the times there were 4 contracts were due to "in-flight" executions, generally after the stop had been moved to breakeven (closer to the market). It seems the NT "Close position" order was generated when a reversal was triggered, then the stop got hit (making the position flat), then the "Close position" order was executed (making position 2 in the opposite direction), and then the NT enter order is executed (making the position 4), with no overfill reported.
I looked for a different solution and tried using the ExitLong()/ExitShort() method again, but also tracking the stop and target orders and waiting for them to reach a terminal state (filled, cancelled, rejected) before calling EnterLong()/EnterShort() for the reverse order.
This seems to work well, no reported overfills (shutting down the strategy) and no positions larger than they should be are reported in the CC executions or strategies tabs.
However, usually the strategy position and stop/target orders show up in the DOM, or a ChartTrader in another chart, set to the same symbol. In this case only some positions show up in DOM/ChartTrader, and other times only the stop/target show up and the DOM/ChartTrader, shows no current position. But the executions/strategies tabs in CC report the position accurately.
Any Ideas?
Ed

Comment