I get the following error on occasion in my strategy, which uses unmanaged orders:
Cannot change order '493860972' because current order values already match. affected Order: BuyToCover 1 StopMarket @ 62.25
I have the following code which is meant to ensure the order is only changed if the new stop price is different than current (long example):
// Compute trailing stop. Updates TrailLineLong[]
ComputeTrailerLong(barsAgo);
LastTrailingLong = TrailLineLong[barsAgo];
bool updateLastSetStopPrice = false;
if ((StopOrder1 != null) &&
(LastTrailingLong != LastSetStopPrice))
{
ChangeOrder(StopOrder1, StopOrder1.Quantity, 0, LastTrailingLong);
trace = @"Changed StopOrder1 Long at " + LastTrailingLong.ToString(); Print(trace);
updateLastSetStopPrice = true;
}
if ((EntriesPerDirection > 1) &&
(StopOrder2 != null) &&
(LastTrailingLong != LastSetStopPrice))
{
ChangeOrder(StopOrder2, StopOrder2.Quantity, 0, LastTrailingLong);
trace = @"Changed StopOrder2 Long at " + LastTrailingLong.ToString(); Print(trace);
updateLastSetStopPrice = true;
}
if ((EntriesPerDirection > 2) &&
(StopOrder3 != null) &&
(LastTrailingLong != LastSetStopPrice))
{
ChangeOrder(StopOrder3, StopOrder3.Quantity, 0, LastTrailingLong);
trace = @"Changed StopOrder3 Long at " + LastTrailingLong.ToString(); Print(trace);
updateLastSetStopPrice = true;
}
if (updateLastSetStopPrice)
{
LastSetStopPrice = LastTrailingLong;
}
This block of code is called from OnBarUpdate. The initial stop order is placed during OnExecutionUpdate when the entry orders are confirmed to be filled. LastSetStopPrice is initialized there. Is there a more robust way to ensure the order is not modified if the stop price is the same, or any other ideas on preventing this error?
Thanks,
Sliverm3170
Comment