Now I did do my homework and have implemented the following:
Initialize() method:
RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;
In my OnOrderUpdate method:
if (order.OrderState == OrderState.Filled || order.OrderState == OrderState.PartFilled) { if (enableLog) { Print(instrumentName + "." + BarsPeriod.Value + "." + BarsPeriod.BasePeriodType); Print("Order: " + order.OrderAction + " was filled"); } barNumberOfFill = CurrentBars[0] + startIndexSeriesOne; if (enableLog) { Print(instrumentName + "." + BarsPeriod.Value + "." + BarsPeriod.BasePeriodType); Print("EXECUTED at BarNumberOfFill (adjusted): " + barNumberOfFill); Print("CurrentBars: " + PriceToString(CurrentBars[0])); Print("Time on 0 series: " + Times[0][0]); } //Log(order.ToString(), LogLevel.Information); if (entryOrder != null && entryOrder == order) { if (order.OrderState == OrderState.Rejected) { if (entryOrder.OrderAction == OrderAction.Buy) { if (Closes[1][0] <= unfilledMaxDistance) { String message = "Long Entry REJECTED - attempting again with Limit at ask: " + currentAsk; Print(message); Log(message, LogLevel.Information); entryOrder = EnterLongLimit(1, true, unfilledPositionSize, currentAsk, LONG_POSITION); } else { String message = "Long Entry REJECTED and Ask at " + currentAsk + " has moved beyond the entry range terminating at " + unfilledMaxDistance; Print(message); Log(message, LogLevel.Information); } } else if (entryOrder.OrderAction == OrderAction.SellShort) { if (Closes[1][0] >= unfilledMaxDistance) { String message = "Short Entry REJECTED - attempting again with Limit at bid: " + currentBid; Print(message); Log(message, LogLevel.Information); entryOrder = EnterShortLimit(1, true, unfilledPositionSize, currentBid, SHORT_POSITION); } else { String message = "Short Entry REJECTED and Bid at " + currentBid + " has moved beyond the entry range terminating at " + unfilledMaxDistance; Print(message); Log(message, LogLevel.Information); } } }
if (entryOrder != null && entryOrder == order) {
have to move outside:
if (order.OrderState == OrderState.Filled || order.OrderState == OrderState.PartFilled) {
The reason I have the existing conditional flow stems from an old template I have been using for years now (and has worked fine). Anyway, my inkling here is that the rejection handling is not being called properly due to a problem in my OnOrderUpdate conditional flow. However, still - even in that case it should not have thrown the alert and just failed quietly.
Any input would be appreciated, as always :-)
Comment