Backtest a Strategy
Previous Topic  Next Topic 

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



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




Start a Backtest

Select either an instrument or an instrument list (to basket test the entire list of instruments) and via the right mouse button click context menu, select the sub-menu "Backtest...". Alternatively, you can press the "b" icon from the tool bar or press the short cut key combination Ctrl-B.



Select the strategy (1) and set the backtest properties and press "OK".



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:


Default

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


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


Slippage can also be set expressed in "ticks" or, the minimum value of fluctuation for an instrument. Slippage is only applied to market and stop market orders since slippage is impossible with a limit order.


Special Circumstances with GAIN Forex

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.



Property Definitions

Parameters section

Sets any strategy specific user defined inputs

From

Sets the start date for the backtest period

To

Sets the end date for the backtest period

Exclude weekend

If true, will exclude weekend data from the historical dataseries

Session begins

Starting time of the intraday session for the historical dataseries

Session ends

Ending time of the intraday session for the historical dataseries

Dataseries - Type

Interval type for the historical dataseries

Dataseries - Value

Interval value for the historical dataseries

Include commission

Include commission in the backtest performance results (see setting commissions)

Label

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

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

Slippage

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 time in force