Operations > Strategy Analyzer >

Backtest a Strategy

Print this Topic Previous pageReturn to chapter overviewNext page



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



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


tog_minusHow to run a backtest

Start a Backtest

To run a Backtest of a strategy:





1.Left mouse click on an instrument or instrument list (to backtest the entire list of instruments) and right mouse click to bring up the right mouse click menu. Select the menu item Backtest... Alternatively left mouse click on the "b" icon in the Strategy Analyzer toolbar. The default Hot Key CTRL + B can also be used.
2.Select a strategy from the Strategy slide out menu
3.Set the backtest properties (See the "Understanding backtest properties" section below for property definitions) and press the OK button.


The backtest progress will be shown in the Status Bar of the Control Center.

tog_minusUnderstanding historical processing options

Historical Fill Processing

NinjaTrader provides two system fill algorithms that can be used in a backtest. In addition, if you have some experience programming, you can script your own algorithm.




The two system fill algorithms are:



An algorithm that takes a conservative and more realistic approach to filling limit and stop limit orders.

Limit orders only fill if the limit price was penetrated
Limit orders are always filled at the limit price specified never better (for example, if a limit order is submitted on bar n, NinjaTrader will check if the order is filled on bar n+1, if this bar gaps down and the limit order was a buy, the order would be filled at the limit price and NOT the high of bar n+1)


An algorithm that takes a liberal approach to filling limit and stop limit orders.

Limit orders fill if the limit price was touched
On gap down bars, buy limit orders will fill at the high of the gap down bar
On gap up bars, sell limit orders will fill at the low of the gap up bar


Slippage can also be set to mimic market conditions. The value is expressed in "ticks", the minimum value of fluctuation for an instrument, and is only applied to market and stop market orders since slippage is not possible when using a limit order.


Special Circumstance with Forex backtests

During a backtest order quantity is an absolute value, which is in most cases different than in a real-time brokerage account. As an example, 1 traded FX lot at a live brokerage account might be the equivalent to 100,000 of notional value (check with your broker) however, in backtest a value of 1 is a literal value of 1 and not 100,000. Thus if you want to trade 100,000 in a backtest, you need to put in a value of 100,000. Just remember that if you convert your strategy from backtest to live you will need to amend the order quantities appropriately. (Please see the Running FX Strategies section for more information).

tog_minusUnderstanding backtest properties

Backtest Properties

The following properties are available within the Backtest window:





Sets any strategy specific user defined inputs

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.


Sets the start date for the backtest period


Sets the end date for the backtest period

Session template

Sets the session time template for the Data Series. (See the "Session Manager" section of the Help Guide for more information)

Include commission

Include commission in the backtest performance results (See the "Commission Tab" section of the Help Guide for more information)


Sets a text value that will be displayed on the chart to represent the strategy

Maximum bars look back

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

Min. bars required

Sets the minimum number of bars required before the backtest will start processing

Fill type

Sets the algorithm for processing and filling orders during backtest


Sets the slippage amount in ticks per execution

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 close

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

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
"by account" - Allows you to set a virtual account value that is used to determine maximum order size based on margin settings per instrument set in the Instrument Manager

Time in force

Sets the order's time in force