AtmStrategyCreate()

View as Markdown

Definition

Submits an entry order that will execute a specified ATM Strategy.

Please review the section on using ATM Strategies. This method is NOT backtestable and will NOT execute on historical data. See the AtmStrategyCancelEntryOrder() to cancel an entry order. See the AtmStrategyChangeEntryOrder() to change the price of the entry order. The ATM Strategy will be created asyncronous on the hosting NinjaScripts UI Thread, a callback is provided solely to check when the ATM Strategy is started on that thread - accessing for example price data in that outside OnBarUpdate() context is not possible. Please see the SampleATMStrategy build into NinjaTrader for example usage.

Method Return Value

This method does not return a value

Syntax

AtmStrategyCreate(OrderAction action, OrderType orderType, double limitPrice, double stopPrice, TimeInForce timeInForce, string orderId, string strategyTemplateName, string atmStrategyId, Action\<ErrorCode, string\> callback)

Parameters

ParameterDescription
actionSets if the entry order is a buy or sell order. Possible values are: OrderAction.Buy, OrderAction.Sell
orderTypeSets the order type of the entry order. Possible values are: OrderType.Limit, OrderType.Market, OrderType.MIT, OrderType.StopMarket, OrderType.StopLimit
limitPriceThe limit price of the order
stopPriceThe stop price of the order
timeInForceSets the time in force of the entry order. Possible values are: TimeInForce.Day, TimeInForce.Gtc
orderIdThe unique identifier for the entry order
strategyTemplateNameSpecifies which strategy template will be used
atmStrategyIdThe unique identifier for the ATM strategy
callbackThe callback action is used to check that the ATM Strategy is successfully started

Tip: Unlike NinjaScript Strategy orders (both managed and unmanaged), ATM strategies generated by the AtmStrategyCreate() method can then be managed manually by any order entry window such as the SuperDOM or within your NinjaScript strategy.

Examples

1private string atmStrategyId;
2private string atmStrategyOrderId;
3private bool isAtmStrategyCreated = false;
4
5protected override void OnBarUpdate()
6{
7 if (State < State.Realtime)
8 return;
9
10 if (Close[0] > SMA(20)[0])
11 {
12 atmStrategyId = GetAtmStrategyUniqueId();
13 atmStrategyOrderId = GetAtmStrategyUniqueId();
14
15 AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day,
16 atmStrategyOrderId, "MyTemplate", atmStrategyId, (atmCallbackErrorCode, atmCallbackId) => {
17
18 // checks that the call back is returned for the current atmStrategyId stored
19 if (atmCallbackId == atmStrategyId)
20 {
21 // check the atm call back for any error codes
22 if (atmCallbackErrorCode == ErrorCode.NoError)
23 {
24 // if no error, set private bool to true to indicate the atm strategy is created
25 isAtmStrategyCreated = true;
26 }
27 }
28 });
29 }
30
31 if(isAtmStrategyCreated)
32 {
33 // atm logic
34 }
35
36 else if(!isAtmStrategyCreated)
37 {
38 // custom handling for a failed atm Strategy
39 }
40}