protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time)
{
if (entryLong != null && entryLong == execution.Order)
{
if (entryLong.OrderState == OrderState.Filled || entryLong.OrderState == OrderState.PartFilled)
{
if (stopLong == null)
{
PrintLine(Name + ", " + Bars.ToChartString() + ", Stop1 Long: OnExecutionUpdate(), Line 2319: " + CurrentBar + ", Time: " + Time[0] + ", entryLongBar: " + entryLongBar + ", entryLong.OrderState: " + entryLong.OrderState, "StopPrint");
if (StopLongType == OrderType.StopLimit)
SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopLimit, Position.Quantity, stopLongLimitPrice, stopLongPriceWithOffset, "", stopLongName);
}
}
}
}
Strategy, KTTA (10 Second), Stop1 Long: OnExecutionUpdate(), Line 2319: 735, Time: 26/9/2024 7:08:00 PM, entryLongBar: 735, entryLong.OrderState: PartFilled Strategy, KTTA (10 Second), Stop1 Long: OnExecutionUpdate(), Line 2319: 735, Time: 26/9/2024 7:08:00 PM, entryLongBar: 735, entryLong.OrderState: Filled Strategy, KTTA (10 Second), Stop1 Long: OnExecutionUpdate(), Line 2319: 735, Time: 26/9/2024 7:08:00 PM, entryLongBar: 735, entryLong.OrderState: Filled Strategy, KTTA (10 Second), Stop1 Long: OnExecutionUpdate(), Line 2319: 735, Time: 26/9/2024 7:08:00 PM, entryLongBar: 735, entryLong.OrderState: Filled
So, what's happening is that the entryLong buy order was split into multiple executions that was firing so quickly that the stopLong never gets a chance to be placed before the next execution happens (hence the stopLong == null check always passes, when by right it should only be for the first execution). I ended up with 4 separate stop orders instead of one.
Also very odd that out of the 4 executions, 1 was marked as OrderState.PartFilled, and the other 3 as OrderState.Filled (for entryLong) when I would've assumed it to be the other way around (3 PartFilled and the final one as Filled)
I understand that this may very well be the limitations of the engine, I thought I'd ask here to see if anyone has figured out a workaround for this. I'm using Interactive Brokers, if that matters.
Thanks in advance!
-Nick

Comment