Currently I have my OrderExecutionUpdate function this way:
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time) { if (entryOrder != null && entryOrder == execution.Order) { // Check if the entry order is filled if (execution.Order.OrderState == OrderState.Filled) { double takeProfitPrice = 0; // Submit stop loss and take profit orders if (Position.MarketPosition == MarketPosition.Long) { takeProfitPrice = Position.AveragePrice + (Position.AveragePrice - SL)*takeProfitFactor; // 1:1 ratio stopOrder = ExitLongStopMarket(0, true, execution.Quantity, SL, "StopLoss", "EntryOrder"); targetOrder = ExitLongLimit(0, true, execution.Quantity, takeProfitPrice, "TakeProfit", "EntryOrder"); } else if (Position.MarketPosition == MarketPosition.Short) { takeProfitPrice = Position.AveragePrice - (SL - Position.AveragePrice)*takeProfitFactor; // 1:1 ratio stopOrder = ExitShortStopMarket(0, true, execution.Quantity, SL, "StopLoss", "EntryOrder"); targetOrder = ExitShortLimit(0, true, execution.Quantity, takeProfitPrice, "TakeProfit", "EntryOrder"); } entryOrder = null; } } }
Comment