The strategy takes an initial long or short position and thereafter the position is reversed by an opposite entry order which is initially placed in OnExecutionUpdate
(_LongEntryFilled = cumulative count of contracts filled and/or partfilled. _trailingShort[0] is double price below last.
if ( _shortEntryStopMar****rder==null)
{
SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.StopMarket, _longEntryFilled, 0.0,_trailingShort[0], "", "EntryShort");
}
else
{
ChangeOrder(_shortEntryStopMar****rder, _longEntryFilled, 0.0,_trailingShort[0]);
}
if ( _shortEntryStopMar****rder!=null && Position.MarketPosition == MarketPosition.Long)
{
if (_shortEntryStopMar****rder.StopPrice < _trailingShort[0] && Close[0] - TickSize >= _trailingShort[0])
{
ChangeOrder(_shortEntryStopMar****rder, _contracts + Position.Quantity, 0.0, _trailingShort[0]);
}
}
This is fair enough, however if the "OK" is not clicked quickly the entire chart just freezes.
I've found to recover one way is to kill the entire NinjaTrader process stack or to cancel the last entry order from another window, e.g. Superdom. If I am able to cancel the entry order, then the chart spools the buffered ticks but the strategy is dead.
Any advice on how to add code to avoid encountering this error or better yet to handle it? Is there existing reference code to properly handle rejects somewhere? I see in OnOrderUpdate https://ninjatrader.com/support/help...t8/?charts.htm we get the state and error code which seem to be generic, like ErrorCode.OrderRejected. However Ninja obviously is receiving more detailed information in order to determine to present the above error message.
Where is this info exposed? I'm assuming its passed back from the broker (simulator) via the OnOrderUpdate string comment field.
If so, can you provide a list of possible string values by SIM101 and NinjaTrader Continuum?
Will proper handling of the rejection obviate the need to present the user with an error message, that is to not stop the UI / strategy?

Comment