I had a question regarding ChangeOrder for unmanaged orders.
Suppose my original order was a Stop Order, e.g.
order = SubmitOrderUnmanaged(BarsInProgress, OrderAction.Buy, OrderType.StopMarket, qty, 0, stopLevel);
In backtest (historic simulations), my Stop Levels are coded to be always at least above Close + TickSize for Buys, or at least below Close - TickSize for Sells. Hence, in the backtest (historic simulations), my orders never get rejected.
However, assume during live trading, for some reason whatsoever, my order does get rejected, for instance, by the time my Stop order got accepted by the broker (or the exchange) during a fast moving market, the Stop Level ended up below the current price in the market for Buys, or above the current price in the market for Sells. Now, suppose, for live trading, I want to handle the situation, that if my order is rejected, I want my order to be converted to a market order in such situations (to keep my strategy inline with its intended behavior).
If I write the ChangeOrder within the OnOrderUpdate() class such that both limitPrice & stopPrice are 0, such as this below:
protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice,
Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
{
if (orderState == OrderState.Rejected) ChangeOrder(order, qty, 0, 0); // both limitPrice and stopPrice are 0
}
(i) would it then automatically convert the order.OrderType to be OrderType.Market ?
(ii) or, alternately, is it better to generate a new market order altogether based on the original order's quantity and OrderAction (instead of trying to do ChangeOrder) ?
Thanks.
Comment