I'm running an automated strategy that's working fine but I'm having an issue with canceling an order if it hasn't been executed. The order shall be cancelled if the next candle hasn't made a higher high (for longs) or a lower low (for shorts).
Here's the code for entering the trade (works well):
if(orderId.Length == 0 && atmStrategyId.Length == 0 && my criteria here)
{ atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.StopLimit,High[0]+1*TickSize,High[0]+1*TickSize, TimeInForce.Day, orderId, "MyStrat", atmStrategyId);
}
If I add the part that's in charge of canceling the order, it doesn't work anymore: (The last part of the code is critical)
if (orderId.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderId);
// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (status.GetLength(0) > 0)
{
// If the order state is terminal, reset the order id value
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderId = string.Empty;
}
} // If the strategy has terminated reset the strategy id
else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
atmStrategyId = string.Empty;
if (High[0] <= High[1])
{
AtmStrategyCancelEntryOrder("orderId");
}
Thanks for highlighting where I made a mistake.

Comment