This is my code where my entry is filled in OnBarUpdate and the target order is in OnExecution as follows;
protected override void OnExecution(IExecution execution)
{
/* We advise monitoring OnExecution() to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate()
which ensures your strategy has received the execution which is used for internal signal tracking.
This first if-statement is in place to deal only with the short limit entry. */
if (entryOrder != null && entryOrder.Token == execution.Order.Token)
{
// This second if-statement is meant to only let fills and cancellations filter through.
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
// Simple target
targetOrder = ExitLongLimit(0, true, 1, execution.Price + 1 * TickSize, "target", "long entry");
double myExecutionPrice = execution.Price;
//Print(myExecutionPrice.ToString());
// Resets the entryOrder object to null after the order has been filled
if (execution.Order.OrderState != OrderState.PartFilled)
{
entryOrder = null;
}
}
}
// Reset our stop order and target orders' IOrder objects after our position is closed.
if ((stopOrder != null && stopOrder == execution.Order) || (targetOrder != null && targetOrder == execution.Order))
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
{
stopOrder = null;
targetOrder = null;
}
}
}

Comment