The strategy also contains a number of conditions which if true would implement the AtmStrategyClose command and hopefully cause the ATM strategy to close and leave me flat
This works most of the time. When the exit conditions are met the trade closes and everything is fine.
However, about 30% of the time something odd happens. The program not only closes the position but sends an additional close order which results in me being still in a trade (in the opposite direction) after the AtmStrategyClose order is implemented.
By way of example I've attached a trade where this happened. This is the sequence highlighted in the attachment.
At 10:54:01 it enters a short trade of 2 NQ at 4066 on the NQ. At that time the ATM enters two targets and two stop losses.
At 10:56:57 the first target is hit at 4063.50. One NQ contract is bought and one Stop Loss is cancelled. I now have one contract short left and one stop loss. The remaining target is down around 4058.
At 10:59:02 the condition which triggers the AtmStrategyClose command is triggered. This is confirmed by a print of the condition to the output window.
At this time it looks like two things happen. First it looks like the Target 2 is adjusted to the NQ's current price (4062) to close the position by buying 1 NQ. This is fine and what I expect would happen. This leaves me flat in the position.
HOWEVER, the program enters another order designated as a "Close" order. This order ends up buying 1 additional NQ and now leaves me long 1 NQ when I should be flat.
Interestingly, this does not happen all the time. Other times it seems to execute it correctly by closing the position through the existing target orders. It does not enter an additional "close" order. Also, it only does this when using a live data feed. When I use market replay data it handles this correctly everytime. I want it obviously to just close the position and not leave me in a situation where in a position in the opposite direction.
Any help would be appreciated.
Comment