Backtest a Strategy

<< Click to Display Table of Contents >>

Navigation:  Operations > Strategy Analyzer >

Backtest a Strategy

Previous page Return to chapter overview Next page

Show/Hide Hidden Text

A backtest allows you to analyze the historical performance of a strategy. In order to run a backtest you will need:


Access to historical data
Custom NinjaScript *strategy


Tip:  There are several pre-defined sample strategies that are installed with NinjaTrader that you can explore.






1.By default, the Strategy Analyzer downloads data from your market data provider which can slow down backtest progress for larger tests.  If you wish to disable this feature and operate using existing data in your database, right click on the Strategy Analyzer > select Properties > enable Use Local Data Only
2.The IncludeTradeHistoryInBacktest property is set to false by default when a strategy is applied in the Strategy Analyzer for backtesting. This provides for leaner memory usage, but at the expense of not being able to access Trade objects for historical trades. Thus, fields such as SystemPerformance.AllTrades.Count that rely on references to Trade objects will not have any such references to work with. If you would like to save these objects for reference in your code, you can set IncludeTradeHistoryInBacktest to true in the Configure state. For more information, see the Working with Historical Trade Data page.


tog_minus        How to run a backtest

Start a Backtest

To run a Backtest of a strategy:





1.Select the Backtest type of "Standard"
2.Select the strategy you would like to backtest
3.Select the instrument and Data Series you would like to backtest
4.Set the strategy and backtest parameters (See the "Understanding backtest properties" section below for property definitions)
5.Select the "Run" button to start the backtest


Tip:  You can optionally configure a sound to be played when the Backtest completes.  To enable this option, right click on the Strategy Analyzer > Properties > Play sound on complete > Choose the sound file you wish to play (must be a .WAV)


tog_minus        Understanding backtest properties

Backtest Properties

The following properties are available within the Backtest window:





Backtest type

Sets the backtest type.

1. Standard

2. Optimization

3. Walk Forward Optimization

4. Multi-Objective Optimization


Sets the strategy you would like to test.

Data Series


Sets the instrument or list you wish to test on

Price based on

Sets the type of market data used to drive the Data Series


Sets the bar type of the Data Series.


Sets the Data Series value.

Strategy parameters

Parameters (...)

Each strategy parameter is listed dynamically depending on the strategy selection

Time frame

Start date

Sets the start date for the test period

End date

Sets the end date for the test period

Trading hours

Sets the trading hour template for the Data Series. (See the "Trading Hours" section of the Help Guide for more information)

Break at EOD

Enables or disables the bars being reset at EOD (End Of Day). (See the "Break at EOD" section of the Help Guide for more information)

Set up

Include commission

Enables or disables commissions in the backtest performance results (See the "Commission Tab" section of the Help Guide for more information)

Maximum bars look back

Max number of bars used for calculating an indicator's value.  The "TwoHundredFiftySix" setting is the most memory friendly.

Bars required to trade

Sets the minimum number of bars required before orders will be allowed to be submitted

Historical fill processing

Order fill resolution

Sets the order fill resolution to be used for the backtest. (See the "Understanding Historical Fill Processing" section of the Help Guide for more information)

Fill limit orders on touch

Enables or disables the filling of limit orders on a single touch of price action.


Set the amount of slippage to apply to market / stop market order executions (default is 0)

Order handling

Entries per direction

Sets the maximum number of entries allowed per direction while a position is active based on the "Entry handling" property

Entry handling

Sets the manner in how entry orders are handled. If set to "AllEntries", the strategy will process all entry orders until the maximum allowable entries set by the "Entries per direction" property has been reached while in an open position. If set to "UniqueEntries", strategy will process entry orders until the maximum allowable entries set by the "Entries per direction" property per each uniquely named entry.

Exit on session close

When enabled, open positions are closed on the last bar of a session

Order properties

Set order quantity

Sets how the order size is determined, options are:

"by default quantity" - User defined order size

"by strategy" - Takes the order size specified programmatically within the strategy

Time in force

Sets the order's time in force