I have looked at the CancelOrder() and SetStopLoss sections of the manual. I also have looked through the Order, OnOrderUpdate, and OnExecutionUpdate parts of the manual. I am confused as to how to proceed, because the code does not SEEM to be working on historical data.
The relevant code I have so far is below. I am unsure how to proceed from here. For reference what happens is I will be short, and a bar pattern will occur triggering a long position. The short position will close with an execution called Close position, submit the long, fill, and then the old short position stop loss will activate. I am trying to cancel it to reset upon submittal...there has to be something I am doing wrong.
private Order stoplossorder 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 ((order.FromEntrySignal == "Stop loss") && order.OrderState == OrderState.Initialized) { stoplossorder = order; } } protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time) if (execution.Name == "Stop loss" || execution.Name == "Close position") { CancelOrder(stoplossorder); }
Comment