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

private string atmStrategyId;
private string atmStrategyOrderId;
private bool isAtmStrategyCreated = false;
protected override void OnBarUpdate()
{
if (State < State.Realtime)
return;
if (Close[0] > SMA(20)[0])
{
atmStrategyId = GetAtmStrategyUniqueId();
atmStrategyOrderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day,
atmStrategyOrderId, "MyTemplate", atmStrategyId, (atmCallbackErrorCode, atmCallbackId) => {
// checks that the call back is returned for the current atmStrategyId stored
if (atmCallbackId == atmStrategyId)
{
// check the atm call back for any error codes
if (atmCallbackErrorCode == ErrorCode.NoError)
{
// if no error, set private bool to true to indicate the atm strategy is created
isAtmStrategyCreated = true;
}
}
});
}
if(isAtmStrategyCreated)
{
// atm logic
}
else if(!isAtmStrategyCreated)
{
// custom handling for a failed atm Strategy
}
}