I have a question regarding unmanaged orders (using an Interactive Brokers brokerage connection):
First of all, I’m entering a Buy Limit order in the OnBarUpdate() event.
if (entryOrder == null && profitTakerOrder == null && stopLossOrder == null) { SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, Convert.ToInt32(Math.Round(Quantity / Open[0], 0, MidpointRounding.ToEven)), SubmissionPrice, 0, "", "Enter Long Limit"); }
if (stopLossOrder != null && Close[0] > trailingStopPrice) { // Trail Stop-Loss 3% below current price ChangeOrder(stopLossOrder, stopLossOrder.Quantity, 0, Close[0] - ((Close[0] / 100) * 3)); trailingStopPrice = Close[0] + ((Close[0] / 100) * 3); }
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time) { if (execution.Order.OrderState != OrderState.Filled) return; Print("Execution: " + execution.ToString()); if (entryOrder != null && execution.Order == entryOrder) { // Stop Loss 5% below entry price stopLossOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, execution.Order.Filled, 0, execution.Order.AverageFillPrice - ((execution.Order.AverageFillPrice / 100) * 3), string.Empty, "Stop Loss"); //// Profit Taker 6% above entry price //profitTakerOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, // execution.Order.Filled, execution.Order.AverageFillPrice + ((execution.Order.AverageFillPrice / 100) * 6), 0, string.Empty, "Profit Taker"); if (execution.Order.OrderState != OrderState.PartFilled) entryOrder = null; } if ((stopLossOrder != null && stopLossOrder == execution.Order) || (profitTakerOrder != null && profitTakerOrder == execution.Order)) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled) { stopLossOrder = null; profitTakerOrder = null; } } }
Any help is appreciated.
Thanks...
Comment