Let me tell you about rare issue that I experience periodically in my strategy.
Since I want all orders to be under the total control of the strategy logic, I use Unmanaged approach.
Also I use logging both custom and native one. So I can see the detailed workflow of the strategy.
I also use Interactive Broker as market data provider. By the way, the majority of my problems in NT8 is related to IB for some reason...
The key strategy logic has the following structure.
protected override void OnOrderTrace(DateTime timestamp, string message)
{
// Log #1
}
protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
{
// Log #2
}
protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition)
{
// Log #3
if (marketPosition == MarketPosition.Flat)
{
// Some logic #2
}
else
{
// Some logic #3
}
}
protected override void OnBarUpdate()
{
// Some logic #1
}
In the most cases the logging system outputs the following:
Log #1 (exit order submission);
Log #2 (exit order states from Working to Filled);
Log #3 (position is Flat, size = 0 contracts);
"Some logic #2" is executed.
This way my strategy works for days and even weeks. But sometimes unexpected thing happens... I mean "partially filled" state of exit order. When it happens I see the following output.
Log #1 (exit order submission);
Log #2 (exit order states from Working to Partially Filled with filled quantity 50);
Log #3 (position is still Long (or Short), size = 50 contracts);
Log #2 (exit order state Filled);
... and that is all! Logically, another Log #3 (another call of OnPositionUpdate callback) is expected. But no such an action, no "Some logic #2" execution, trading logic is broken... But NT8 native log shows the removed position.
Is there any suggestion of how to process partially filled orders so that the strategy gets the signal that the position is Flat? Thank you.

Comment