In my strategy, I am using unmanaged orders for entry and exits. Everything works fine when I backtest my strategy, however, when I run the strategy on live chart I get an error when I call the ExitLongStopMarket and ExistLongLimit methods for my SL and TP inside OnOrderUpdate.
The error that I get when for example ExitLongStopMarket is called is:
- Object reference not set to an instance of an object
Following is the code within OnOrderUpdate:
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
{
if (entryOrder != null && order == entryOrder && entryOrder1.OrderState == OrderState.Filled)
{
if (order.IsLong) {
stopOrder1 = ExitLongStopMarket(0, true, 1, averageFillPrice - 10 * TickSize, "SL", "Entry");
targetOrder1 = ExitLongLimit(0, true, 1, averageFillPrice + 10 * TickSize, "TP", "Entry");
} else {
stopOrder1 = ExitShortStopMarket(0, true, 1, averageFillPrice + 10 * TickSize, "SL", "Entry");
targetOrder1 = ExitShortLimit(0, true, 1, averageFillPrice - 10 * TickSize, "TP", "Entry");
}
}
}
Thanks.
Pouya


Comment