I would like some clarification on the topic of order management. I would like update my order variables (for the entry order, profit target, and stoploss) when my orders are filled, not when I first submit the orders.
Please have a look at my general logic to let me know if I am headed in the right direction.
Note: I did not define all variables here for simplicity, but I can provide executable code if necessary.
protected override void OnBarUpdate() { if (condition == true) { // Submit three orders to form a bracket OCO. These will trigger OnBarUpdate to be called. // I do not want to assign my class variables (_entryOrder, profitTarget, _stopLoss) here partly because they may not be internally assigned / filled yet. string name = "Long Oco"; EnterLong(quantity, name); // Long entry ExitLongLimit(0, true, quantity, profitTarget, name, name); // Profit target order ExitLongStopMarket(0, true, quantity, stopLoss, name, name); // Stoploss order } } protected override void OnOrderUpdate() { // Three orders were submitted as OCO (entry, profit target, stop loss). // I want to assign my order variables to the proper order now that they are filled/accepted/working // Question: Is OnOrderUpdate() called for each of these orders? Only for the EnterLong() order? Please explain. if (order.OrderState == OrderState.Filled) { // The goal here is to know which of the orders above is handled in this OrderUpdate. if (order.OrderType == OrderType.Limit || order.OrderType == OrderType.Market) _profitTarget = order; // OrderUpdate is for the profit target else if (order.OrderType == OrderType.StopLimit || order.OrderType == OrderType.StopMarket) _stopLoss = order; // OrderUpdate is for the stoploss else _entryOrder = order; // OrderUpdate is for the entry order. } }
Comment