Strategy

View as Markdown

The methods and properties covered in this section are unique to custom strategy development.

In this section

Strategy AccountRepresents the real-world or simulation Account configured for the strategy.
AddChartIndicator()Adds an indicator to the strategy only for the purpose of displaying it on a chart.
AddPerformanceMetric()Adds an instance of custom Performance Metric to a strategy used in strategy calculations.
ATM Strategy MethodsAdds ATM strategies to manage your position
BarsRequiredToTradeThe number of historical bars required before the strategy starts processing order methods called in the OnBarUpdate() method.
BarsSinceEntryExecution()Returns the number of bars that have elapsed since the last specified entry.
BarsSinceExitExecution()Returns the number of bars that have elapsed since the last specified exit.
ChartIndicatorsContains a collection of Indicators which have been added to the strategy instance using AddChartIndicator().
CloseStrategy()Cancels all working orders, closes any existing positions, and finally disables the strategy.
ConnectionLossHandlingSets the manner in which your strategy will behave when a connection loss is detected.
DaysToLoadDetermines the number of trading days which will be configured when loading the strategy from the Strategies Grid.
DefaultQuantityAn order size variable that can be set either programmatically or overridden via the Strategy that determines the quantity of an entry order.
DisconnectDelaySecondsDetermines the amount of time a disconnect would have to last before connection loss handling takes action.
EntriesPerDirectionDetermines the maximum number of entries allowed per direction while a position is active based on the EntryHandling property.
EntryHandlingSets the manner in how entry orders will handle.
ExecutionRepresents a read-only interface that exposes information regarding an execution (filled order) resulting from an order and is passed as a parameter in the OnExecutionUpdate() method.
ExitOnSessionCloseSecondsThe number of seconds before the actual session end time that the “IsExitOnSessionCloseStrategy” function will trigger.
IncludeCommissionDetermines if the strategy performance results will include commission on a historical backtest.
IncludeTradeHistoryInBacktestDetermines if the strategy will save orders, trades, and execution history.
IsAdoptAccountPositionAwareDetermines if the strategy is programmed in a manner capable of handling real-world account positions.
IsExitOnSessionCloseStrategyDetermines if the strategy will cancel all strategy-generated orders and close all open strategy positions at the close of the session.
IsFillLimitOnTouchDetermines if the strategy will use a more liberal fill algorithm for back-testing purposes only.
IsInstantiatedOnEachOptimizationIterationDetermines if the strategy should be re-instantiated (re-created) after each optimization run when using the Strategy Analyzer Optimizer.
IsInStrategyAnalyzerDetermines if the current NinjaScript Strategy is run from a Strategy Analyzer chart.
IsTradingHoursBreakLineVisiblePlots trading hours break lines on the indicator panel.
IsWaitUntilFlatIndicates the strategy is currently waiting until a flat position is detected before submitting live orders.
NumberRestartAttemptsDetermines the maximum number of restart attempts allowed within the last x minutes defined in RestartsWithinMinutes when the strategy experiences a connection loss.
OnAccountItemUpdate()An event-driven method used for strategies which is called for each AccountItem update for the account on which the strategy is running.
OnExecutionUpdate()An event-driven method which is called on an incoming execution of an order managed by a strategy.
OnOrderTrace()An event-driven method used for strategies which will allow you to customize the output of TraceOrders.
OnOrderUpdate()An event-driven method which is called each time an order managed by a strategy changes state.
OnPositionUpdate()An event-driven method which is called each time the position of a strategy changes state.
OptimizationPeriodReserved for Walk-Forward Optimization, this property determines the number of days used for the “in sample” backtest period for a given strategy. See also TestPeriod.
OrderRepresents a read-only interface that exposes information regarding an order.
Order MethodsNinjaScript provides several approaches you can use for order placement within your NinjaScript strategy.
OrderFillResolutionDetermines how strategy orders are filled during historical states.
OrderFillResolutionTypeDetermines the bars type which will be used for historical fill processing.
OrderFillResolutionValueDetermines the bars period interval value which will be used for historical fill processing.
PerformanceMetricsHolds an array of PerformanceMetrics objects that represent custom metrics that can be used for strategy calculations.
PlotsA collection holding all of the Plot objects that define their visualization characteristics.
PositionRepresents position-related information that pertains to an instance of a strategy.
PositionAccountRepresents position-related information that pertains to real-world account (live or simulation).
PositionsHolds an array of Position objects that represent positions managed by the strategy.
PositionsAccountHolds an array of PositionAccount objects that represent positions managed by the strategy’s account.
RealtimeErrorHandlingDefines the behavior of a strategy when a strategy-generated order is returned from the broker’s server in a “Rejected” state.
RestartsWithinMinutesDetermines within how many minutes the strategy will attempt to restart.
SetOrderQuantityDetermines how order sizes are calculated for a given strategy.
SlippageSets the amount of slippage in ticks per execution used in performance calculations during backtests.
StartBehaviorSets the start behavior of the strategy. See Syncing Account Positions for more information.
StopTargetHandlingDetermines how stop and target orders are submitted during an entry order execution.
StrategyBaseConverterA custom TypeConverter class handling the designed behavior of a strategy’s property descriptor collection.
SystemPerformanceThe SystemPerformance object holds all trades and trade performance data generated by a strategy.
TestPeriodReserved for Walk-Forward Optimization, this property determines the number of days used for the “out of sample” backtest period for a given strategy.
TimeInForceSets the time in force property for all orders generated by a strategy.
TraceOrdersDetermines if OnOrderTrace() would be called for a given strategy.
TradeA Trade is a completed buy/sell or sell/buy transaction. It consists of an entry and exit execution.
TradeCollectionA collection of Trade objects.
TradesPerformanceValuesPerformance values of a collection of Trade objects.
WaitForOcoClosingBracketDetermines if the strategy will submit both legs of an OCO bracket before submitting the pair to the broker.