With advanced order handling you can submit an orders in the context of any bars object by designating the "BarsInProgress" index. What this means is that if your primary bar series is "MSFT" and your secondary series added to the strategy through the Add() method is "AAPL", you can submit an order for either "MSFT" or "AAPL" anywhere from within the strategy. There is detailed information on working with multi-time frame and instrument strategies however, this sub-section strictly deals with the concept of order submission.
Let's take as an example the EnterLongLimit() method and one of its method variations (below) designed for advanced order handling:
EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)
Let's also continue with the example above where a "MSFT" 1 minute chart is the primary bar series the strategy is running on. We add a secondary bar series, an "AAPL" 1 min series to our strategy by calling the Add() method in the Initialize() method as follows:
Add("AAPL", PeriodType.Minute, 1);
|
|
In NinjaScript, "MSFT" has a bars index value of "0" and "AAPL" would have bars index value of "1". More information on this concept can be found in the multi-time frame and instrument strategies section as well as the property BarsInProgress. In a multi-instrument strategy, using the EnterLongLimit() method above will generate an order for the instrument that is associated to the value of the "barsInProgressIndex" parameter you pass in.
The following example code demonstrates how you can monitor for bar update events on "MSFT" but submit an order to "AAPL". The key is in passing in a value of "1" (bold red below) into for the "BarsInProgressIndex". A value of 1 represents the "AAPL" bar series and thus the order is submitted for "AAPL".
private IOrder entryOrder = null;
protected override void OnBarUpdate()
{
if (BarsInProgress == 0)
{
if (entryOrder == null)
entryOrder = EnterLongLimit(1, true, 1, Lows[1][0], "AAPL Order");
}
}
|
|
|