public class MyStrategy {
private Order shortEntry = null;
private Order longEntry = null;
....
}
Now suppose I want to enter a BUYSTOP or a SELLSTOP order to enter a position. It looks like there are at least two ways of keeping track of these orders:
Method 1:
this.longEntry = SubmitOrderUnmanaged(DATA_SERIES_ORDERS, OrderAction.Buy, OrderType.StopMarket, quantity, 0, entryStopPrice);
OR
thisshortEntry = SubmitOrderUnmanaged(DATA_SERIES_ORDERS, OrderAction.SellShort, OrderType.StopMarket, quantity, 0, entryStopPrice);
This method uses the Order object returned from SubmitOrderUnmanaged. But note that it does not provide a value for "oco" or signalName
Method 2:
SubmitOrderUnmanaged(DATA_SERIES_ORDERS, OrderAction.Buy, OrderType.StopMarket, quantity, 0, entryStopPrice, "", "MY_LONG_ENTRY");
OR
SubmitOrderUnmanaged(DATA_SERIES_ORDERS, OrderAction.SellShort, OrderType.StopMarket, quantity, 0, entryStopPrice, "", "MY_SHORT_ENTRY");
and then implement OnOrderUpdate:
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.Name == "MY_LONG_ENTRY") {
this.longEntry = order;
} else if (order.Name == "MY_SHORT_ENTRY") {
this.shortEntry = order;
}
}
Ninjatrader support has an example Strategy that uses approach 2, and the comments inside OnOrderUpdate say this:
// Assign Order objects here
// This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not guaranteed to be complete if it is referenced immediately after submitting
So why is method 2 better than method 1 for entry orders? Is it really the case that you should not use the Order object returned from SubmitOrderUnmanaged?
Also, if we just want to submit a basic BuyStop or SellStop (or BuyLimit or SellLimit) order and we don't want to set any OCO, do we just use a blank string "" for oco as in the example above?
Comment