Error on calling 'OnBarUpdate' method on bar 27431: Object reference not set to an instance of an object.
I sometimes get this error and my strategy becomes disable. Is there a way to trap this error in on OnBarUpdate using an error variable rather than inserting Print statement on every line of the code. I have multiple indicator on in the OnBarUpdate method.
I want to include code in OnBarUpdate similar to what I have in OnOrderUpdate as follows:
if (order.Name.Contains("StopLoss") == true) { stopOrder = order; if (error == ErrorCode.OrderRejected || error == ErrorCode.UnableToChangeOrder) { Print("Unable to Change Order. Submitting New Order."); Trail_Stop = Position.GetMarketPrice() + 5*TickSize; ChangeOrder(stopOrder, Position.Quantity, 0, Trail_Stop); } }
Comment