I've tried a few things but seem to run into an issue where after it cancels an order the strategy stops taking trades all together...
I don't seem to get this issue when using the cancel code in the OnBarUpdate Method, but then run into an issue where it will cancel and order, but leaves the order there but then never fills that order even after the price eventually reaches is.
I currently have the following code:
public class Strategy : Strategy
{
private int indexEntryBar = 0;
protected override void OnBarUpdate()
{
If (myOrder == null)
{
indexEntryBar = CurrentBar;
EnterLongLimit();
longTrade = true;
}
}
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
if (order.Name == "long")
myOrderl = order;
if (myOrderl != null && myOrderl == order)
{
if (longTrade && CurrentBar - indexEntryBar >= 2)
{
CancelOrder(myOrderl);
myOrderl = null;
longTrade = false;
}
else if (order.OrderState == OrderState.Filled)
myOrderl = null;
}
}
}
Comment