Order Submission
Order submission with the Unmanaged approach is done solely from a single order method. Parameterizing the SubmitOrder() method differently will determine what kind of order you will be submitting. Please note that these orders are live until cancelled. Should you want to cancel these orders you will need to use the CancelOrder() method or wait till the orders expire due to the strategy's time in force setting.
In the example below, a buy limit order to enter a long position is working at the bid price provided that the close price of the current bar is greater than the current value of the 20 period simple moving average.
protected override void OnBarUpdate()
{
if (Close[0] > SMA(20)[0] && entryOrder == null)
entryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, 1, GetCurrentBid(), 0, "", "Long Limit");
}
|
|
It is critical to assign an IOrder object to keep track of your order or else you will not be able to identify it in your code later since there is no signal tracking when using Unmanaged order methods. Please be aware of the following information about IOrder objects:
• | An IOrder object returned from calling an order method is dynamic in that its properties will always reflect the current state of an order |
• | The property <IOrder>.OrderId is NOT a unique value since it can change throughout an order's lifetime |
• | The property <IOrder>.Token is NOT a unique value since it will change as the strategy transitions from historical to real-time |
• | To check for equality you can compare IOrder objects directly |
Order Modification
Unlike the Managed approach where you could modify a working order by calling the entry order method again with your new parameters, the Unmanaged approach requires the utilization of the ChangeOrder() method. The ChangeOrder() method requires you to have access to the IOrder object you wish to modify so it is important to hold onto those for any active order you have in your strategy.
protected override void OnBarUpdate()
{
if (stopOrder != null && stopOrder.StopPrice < Position.AvgPrice && Close[0] >= Position.AvgPrice + 4 * TickSize)
ChangeOrder(stopOrder, stopOrder.Quantity, stopOrder.LimitPrice, Position.AvgPrice);
}
|
|
Order Cancellation
Similar to the live until cancelled technique from the Managed approach, cancelling orders can be done through the CancelOrder() method.
protected override void OnBarUpdate()
{
if (entryOrder != null && Close[0] < entryOrder.LimitPrice - 4 * TickSize)
{
CancelOrder(entryOrder);
}
}
|
|
Signal Tracking
Since the Unmanaged approach does not utilize NinjaScript's signal tracking the features associated with it will no longer be relevant. The following properties and their associated concept cannot be used with Unmanaged order methods:
EntriesPerDirection
EntryHandling
Methods utilizing signal names like BarsSinceEntry() and BarsSinceExit() can still be used though.
|