I'm trying to use OnExecutionUpdate to add target and stop orders to my strategy once the entry is filled.
However, when I execute the event below it throws an Object not found error I can only find by looking at the trace file.
protected void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
{
// set up the target and stop orders associated with the order being filled that triggered this execution
try
{
if (execution.Order != null && execution.Order.OrderState == OrderState.Filled)
{
Print(execution.ToString());
// Print(Time[0] + " Order filled with name: " + execution.Order.Name);
// if(execution.Order.IsLong)
// {
// TargetOrder = ExitLongLimit(0, true, 1, GetCurrentBid() + TargetTicks * TickSize, "LTarget", execution.Order.Name);
// StopOrder = ExitLongStopMarket(0, true, 1, GetCurrentBid() - StopTicks * TickSize, "LStop", execution.Order.Name);
// }
// if(execution.Order.IsShort)
// {
// TargetOrder = ExitLongLimit(0, true, 1, GetCurrentBid() + TargetTicks * TickSize, "LTarget", execution.Order.Name);
// StopOrder = ExitLongStopMarket(0, true, 1, GetCurrentBid() - StopTicks * TickSize, "LStop", execution.Order.Name);
// }
}
}
catch (Exception ex) {Print("OnExecutionUpdate: " + ex.Message.ToString());}
}
Any help on this is greatly appreciated.
Comment