Sometimes i get an error onMarketData when order left hanging without closing. It seems if i do trail and when in trail additional setup evaluates to true and gives out an error
With current code i get an error. The name execution does not exist in current context
if(Position.MarketPosition == MarketPosition.Long && trailLong <= bid && isXiphosLongSetup == true ){
Print("334" + Time[0]);
Print("trailLong" + trailLong);
Print("bid" + bid);
stopOrder = ExitLongStopMarket(1, true, stopOrder.Quantity, trailLong, "SLL", "Xiphos Long"); //Sets Stop
// stopOrder = trailLong;
}
if(Position.MarketPosition == MarketPosition.Long && trailLong <= bid && isDoryLongSetup == true ){
Print("444");
stopOrder = ExitLongStopMarket(1, true, stopOrder.Quantity, trailLong, "SLL", "Dory Long");
}
if(Position.MarketPosition == MarketPosition.Long && trailLong <= bid && isKopisLongSetup == true){
stopOrder = ExitLongStopMarket(1, true, stopOrder.Quantity, trailLong, "SLL", "Kopis Long");
}
if ((targetOrder != null && targetOrder == execution.Order))
{
Print("stopOrder"+stopOrder);
Print("execution.Order"+execution.Order);
Print("targetOrder"+targetOrder);
if (execution.Order.OrderState == OrderState.Filled)
{
CancelOrder(stopOrder);
}
}
if ((stopOrder != null && stopOrder == execution.Order))
{
Print("targetOrder" + targetOrder);
if (execution.Order.OrderState == OrderState.Filled)
{
CancelOrder(targetOrder);
}
}

Comment