On Tuesday, I had a position of 9 MES contracts. My local machine showed my TP and SL order as 9, but the server showed only 2. The entry was filled like this: 2, 1, 1, 1, 1, 1, 1, 1. The result was when target was hit, only 2 MES contracts were sold, the rest I had to manage my manually selling at market. (Even the "Flatten Everything" function didn't work).
Today, a similar incident happened. I sold 7 MES contracts and my position was filled in the following manner: 1, 2, 1, 1, 2. The machine running the strategy showed orders for 7 contracts on the TP and SL exits. Yet, when I opened the trade up on another machine it showed only 1 contract for the TP and SL. In this case, I updated the TP and SL quantities in the Orders tap of the Command Center, but I really want to squash this bug in my code so I won't have to.
The logic seems ok to me, but obviously I'm missing something. I'm posting the entire section for order execution. Let me know if I can clarify anything for you:
if (myMicroEntryOrder != null && myMicroEntryOrder == execution.Order)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
// Sum the quantities of each executio making up the entry order
sumPrimeMicroFilled += execution.Quantity;
//Submit exit orders for partial fills
if (execution.Order.OrderState == OrderState.PartFilled)
{
if (direction == "LONG")
{
microStopOrder = ExitLongStopMarket(microTradeDataSeries, true, execution.Order.Filled,PrimeStp1Price, "PrimeMicroLongStop", "MicroEntryLong");
microProfitOrder = ExitLongLimit(microTradeDataSeries, true, execution.Order.Filled,PrimeTargetPrice, "PrimeMicroLongTarget" , "MicroEntryLong");
}
if (direction == "SHORT")
{
microStopOrder = ExitShortStopMarket(microTradeDataSeries, true, execution.Order.Filled, PrimeStp1Price, "PrimeMicroShortStop" , "MicroEntryShort" );
microProfitOrder = ExitShortLimit(microTradeDataSeries, true, execution.Order.Filled, PrimeTargetPrice, "PrimeMicroShortTarget" , "MicroEntryShort");
}
Print(String.Format("Part Filled: {0}",sumPrimeMicroFilled));
}
//Update our exit order quantities once orderstate turns to filled and we have seen execution quantities match order quantities
else if (execution.Order.OrderState == OrderState.Filled && sumPrimeMicroFilled == execution.Order.Filled)
{
if (direction == "LONG")
{
microStopOrder = ExitLongStopMarket(microTradeDataSeries, true, execution.Order.Filled, PrimeStp1Price, "PrimeMicroLongStop", "MicroEntryLong" );
microProfitOrder = ExitLongLimit(microTradeDataSeries, true, execution.Order.Filled, PrimeTargetPrice, "PrimeMicroLongTarget", "MicroEntryLong" );
}
if (direction == "SHORT")
{
microStopOrder = ExitShortStopMarket(microTradeDataSeries, true, execution.Order.Filled, PrimeStp1Price, "PrimeMicroShortStop", "MicroEntryShort" );
microProfitOrder = ExitShortLimit(microTradeDataSeries, true, execution.Order.Filled, PrimeTargetPrice, "PrimeMicroShortTarget", "MicroEntryShort" );
}
Print(String.Format("Complete Filled: {0}",sumPrimeMicroFilled));
}
//Reset the entry order and sum counter to null / 0 after the order has been filled
if (execution.Order.OrderState != OrderState.PartFilled && sumPrimeMicroFilled == execution.Order.Filled)
{
myMicroEntryOrder = null;
sumPrimeMicroFilled = 0;
}
}
} //end myMicroEntryOrder
if ((microStopOrder != null && microStopOrder == execution.Order) || (microProfitOrder != null && microProfitOrder == execution.Order))
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
{
microStopOrder = null;
microProfitOrder = null;
Print("Micro Profit and Stop orders are nulled");
}
}

Comment