I have adapted the following code from your SampleCancelOrder for NT7:
protected override void OnBarUpdate()
{
// First, we need a simple entry. Then entryOrder == null checks to make sure entryOrder does not contain an order yet.
if (Position.MarketPosition == MarketPosition.Flat)
{
// Check IOrder objects for null to ensure there are no working entry orders before submitting new entry order
if (entryOrder == null)
{
if (long0)
entryOrder = EnterLongStop(price,"Long 0");
else if (long1)
entryOrder = EnterLongStop(price,"Long 1");
else if (short0)
entryOrder = EnterShortStop(price,"Short 0");
else if (short1)
entryOrder = EnterShortStop(price,"Short 1");
}
// If cancel true, cancel the order.
else if (entryOrder != null && cancel)
{
CancelOrder(entryOrder);
Print("cancel Order " + entryOrder);
}
}
else if (cancel)
{
ExitLong();
ExitShort();
}
}
protected override void OnOrderUpdate(IOrder order)
{
// Checks for all updates to entryOrder.
Print("OrderUpdate " + order.OrderState.ToString());
if (entryOrder != null && entryOrder == order)
{
// Check if entryOrder is cancelled.
if (order.OrderState == OrderState.Cancelled)
{
// Reset entryOrder back to null
entryOrder = null;
}
}
}
The problem I'm having is that the order is never cancelled. The print statements indicate that CancelOrder(entryOrder) keeps being executed on each bar update, but there is never an update to the order status, and on a second chart with ChartTrader open, I can see the order still sitting there.
How can I fix this?
Thanks
Comment