I need support for the correct code to cancel previous open orders after new ones be filled when the price jump more ticks that expected.
In the sample below same that I as trying, when the price jump first to the "exit_Buy", the Sell order isn't being canceled (maybe the execution being made before the previous order be in fully submitted state?)
private Order Buy, Sell;
private double Price;
private void AssignOrderToVariable(ref Order order)
{
if (order.Name == "Buy" && Buy != order)
Buy = order;
if (order.Name == "Sell" && Sell != order)
Sell = order;
}
protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity,
Cbi.MarketPosition marketPosition, string orderId, DateTime time)
{
if (Sell != null && Sell.OrderState == OrderState.Submitted && execution.Name == "exit_Buy")
{
CancelOrder(Sell);
}
}
protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
{
if (marketDataUpdate.Price == Price)
{
Buy = EnterLongLimit(1, Price, "Buy");
}
if (marketDataUpdate.Price == Price - (4 * TickSize))
{
Sell = EnterShortLimit(1, (Price - (4 * TickSize)), "Sell");
}
if (marketDataUpdate.Price < Price - (4 * TickSize))
{
ExitLong(@"exit_Buy", @"Buy");
}
}

Comment