I am having an issue during partial fills where I am missing the confirmation in OnExecutionUpdate.
Background: I enter a position using 3 separate brackets (Bracket 1, 2, 3). In OnExecutionUpdate, I wait until all are filled and then set profits/target.
The issue is that sometimes on partial orders, I will get confirmation that 1 or 2 of the brackets were filled, but never on the last bracket - so my target/stops never get set.
Any advice on what I might be doing wrong?
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
{
if (execution.Order != null && execution.Order.Name == "Long Entry 1")
{
if (execution.Order.OrderState == OrderState.Filled)
{
order1Filled = true;
orderTime = execution.Order.Time;
logEntry(Instrument.MasterInstrument.Name+"\t"+"Bracket 1 Filled - Quantity: "+execution.Order.Quantity+"\t"+"Price: "+execution.Order.AverageFillPrice);
}
}
if (execution.Order != null && execution.Order.Name == "Long Entry 2")
{
if (execution.Order.OrderState == OrderState.Filled)
{
order2Filled = true;
orderTime = execution.Order.Time;
logEntry(Instrument.MasterInstrument.Name+"\t"+"Bracket 2 Filled - Quantity: "+execution.Order.Quantity+"\t"+"Price: "+execution.Order.AverageFillPrice);
}
}
if (execution.Order != null && execution.Order.Name == "Long Entry 3")
{
if (execution.Order.OrderState == OrderState.Filled)
{
order3Filled = true;
orderTime = execution.Order.Time;
logEntry(Instrument.MasterInstrument.Name+"\t"+"Bracket 3 Filled - Quantity: "+execution.Order.Quantity+"\t"+"Price: "+execution.Order.AverageFillPrice);
}
}
if (bracketUnits == 1 && order1Filled)
orderFilled = true;
if (bracketUnits == 2 && order1Filled && order2Filled)
orderFilled = true;
if (bracketUnits == 3 && order1Filled && order2Filled && order3Filled)
orderFilled = true;
if (orderFilled)
logEntry(Instrument.MasterInstrument.Name+"\t"+"Order Complete - Quantity: "+Position.Quantity+"\t"+"Price: "+Position.AveragePrice);
// set stop and profit targets
if (orderFilled && !setTargetsFlag)
setTargets();
}
Alex
