I really appreciate any suggestion. I have lost lot of $$ due to this unexpected behavior since I am not able to regenerate it in simulations..
Here is an extract from the strategy (stop1 and target1 are Order). There might be several non-needed tests but I was trying several options to solve the issue.
private void ManageOrders()
(calculate new stopPrice and TargetPrice)
if(newSpPr != stopPr)
{
stopPr = newSpPr;
if(stopPr < GetCurrentBid(instID))
{
if(stop1 != null) {CancelOrder(stop1); stop1 = ExitLongStopMarket(instID, true, qtty1, stopPr, Name + "_" + "LgSp1", Name + "_" + "LgEn1");}
}
else
{
if(stop1 != null) {CancelOrder(stop1); stop1 = ExitLongLimit(instID, true, qtty1, stopPr, Name + "_" + "LgSp1", Name + "_" + "LgEn1");}
}
}
if(newT1Pr != target1Pr)
{
target1Pr = newT1Pr;
if(target1 != null) {CancelOrder(target1); target1 = ExitLongLimit(instID, true, qtty1, target1Pr, Name + "_" + "LgTg1", Name + "_" + "LgEn1");}
}
Then
protected override void OnExecutionUpdate(..)
#region cancel Stop or Target orders if the other is filled
if(execution.Order.OrderState == OrderState.Filled)
{
if(execution.Name == Name + "_" + "LgSp1") {CancelOrder(stop1); stop1 = null; if(target1 != null) {CancelOrder(target1); target1 = null;}
if(execution.Name == Name + "_" + "LgTg1") {CancelOrder(target1); target1 = null; if(stop1 != null) {CancelOrder(stop1); stop1 = null;}
}
Comment