Advanced Guide To NinjaTrader: Strategy Analyzer
  1. Advanced Guide To NinjaTrader: Introduction
  2. Advanced Guide To NinjaTrader: Market Analyzer
  3. Advanced Guide To NinjaTrader: Strategy Analyzer
  4. Advanced Guide To NinjaTrader: Advanced Trade Management Technology
  5. Advanced Guide To NinjaTrader: Conclusion

Advanced Guide To NinjaTrader: Strategy Analyzer

The NinjaTrader Strategy Analyzer allows traders to run historical analysis on NinjaScript-based automated trading strategies. To open the Strategy Analyzer, within the NinjaTrader Control Center select File > New > Strategy Analyzer, as shown in Figure 17.

Select File > New > Strategy Analyzer to open the NinjaTrader Strategy Analyzer.
Figure 17: Select File > New > Strategy Analyzer to open the NinjaTrader Strategy Analyzer.


Layout
The Strategy Analyzer consists of the following, as shown in Figure 18:

1. Toolbar - with icons for

  • Load backtest results

  • Save backtest results

  • Open output window

  • Run backtest

  • Run optimizer

  • Run walk forward optimization

  • New strategy

  • Edit

  • Delete

  • Calculate mode (Currency, Percent or Points)

2. <On the fly> to run a historical test on the instrument that is not included in the Instrument List

3. Individual Instruments

4. Instrument Lists

5. Strategies

6. Performance Results

7. Strategy Menu - automatically appears when the mouse cursor hovers over it; left-click the thumbtack icon in the top-right corner of the window to pin it to the Strategy Analyzer window.

The Strategy Analyzer layout.
Figure 18: The Strategy Analyzer layout.
Image courtesy: NinjaTrader, LLC.


SEE: Use Momentum Strategy To Your Advantage

Backtest a Strategy
Traders can use NinjaTrader's Strategy Analyzer to a strategy to determine how it would have performed on historical data. To run a backtest, traders will need access to historical data and a NinjaScript strategy. The NinjaTrader platform is installed with several pre-defined sample strategies; conversely, traders can create their own custom strategies by programming in NinjaScript or working with a qualified NinjaScript programmer.

To run a backtest:

1. Right-click the desired instrument or instrument list and select "Backtest" from the menu, as shown in Figure 19; or click the "b" icon (Run Backtest) in the toolbar.

\'Right-click
Figure 19: Right-click the desired instrument or instrument list and select "Backtest" from the menu.


2. Select a strategy from the Strategy slide-out menu (see Figure 20).

Select a strategy from the Strategy slide out menu.
Figure 20: Select a strategy from the Strategy slide out menu.


3. Set the desired backtest properties, as shown in Figure 21. Double-click to highlight and change a property. (See below for a description of each property).

Double-click to highlight and change any backtest property.
Figure 21: Double-click to highlight and change any backtest property.


4. Click "Run Backtest" at the bottom of the properties window to execute the study.

5. The progress of the backtest appears in the Status Bar of the Control Center.

SEE: Backtesting And Forward Testing: The Importance Of Correlation

By default, the Strategy Analyzer uses a conservative and more realistic approach to filling limit orders and stop-limit orders. Using this approach, limit orders are filled only if the limit price is penetrated, and limit orders are always filled at the limit price specified (and never better). Traders can choose the Liberal algorithm that takes a more aggressive approach to filling limit and stop limit orders during backtesting. The Liberal approach will fill limit orders if the limit price is touched (rather than if it is penetrated), and on gap bars, limit orders will fill at the most favorable price level (such as at the high of the gap down bar for buy limit orders, or at the low of the gap up bar for sell limit orders). To choose the type of fill the backtest will utilize, select either "Default" or "Liberal" from the drop-down menu next to "Fill Type" under Historical Fill Processing, as shown in Figure 22.

\'Under
Figure 22: Under Historical Fill Processing, choose either "Default" or "Liberal" to define how limit and stop limit orders will be filled during backtesting.


The properties that are available in the Backtest window are shown in Figure 23, with a brief description of each.

The available properties in the Backtest window.
Figure 23: The available properties in the Backtest window.


Optimize a Strategy
Traders can optimize a strategy to determine the input parameters that produce the best results. The optimization process tests a range of input values through iterative backtests to find the optimal values during the historical testing period. To optimize a strategy, traders need access to historical data (on which to test the strategy) and a NinjaScript strategy. The NinjaTrader platform is installed with several pre-defined sample strategies; conversely, traders can create their own custom strategies by programming in NinjaScript or working with a qualified NinjaScript programmer.

To Run an Optimization
1. In the Strategy Analyzer window, right-click on an instrument or instrument list and select "Optimize" from the menu, as shown in Figure 24; or, click the "o" (Run Optimizer) icon in the toolbar.

\'Right-click
Figure 24: Right-click on an instrument or instrument list and select "Optimize."


2. Select a strategy from the Strategy slide out menu, as shown in Figure 25.

Select a strategy from the Strategy slide-down menu.
Figure 25: Select a strategy from the Strategy slide-down menu.


3. Set the backtest properties (see Figure 26).

Set the backtest properties.
Figure 26: Set the backtest properties.


4. Click "Run Optimization" to begin the test.

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

Sub-parameters
The strategy input parameters can be expanded to show the following sub-parameters, as shown in Figure 27:

  • Min. Value - The starting value for the test

  • Max. Value - The last value for the test

  • Increment - The step value used in the test

The strategy input parameters can be expanded to show several sub-parameters used in the optimization.
Figure 27: The strategy input parameters can be expanded to show several sub-parameters used in the optimization.


The input value "Fast" in the above figure, for example, has a Min. Value of 10 and a Max. Value of 40 with an increment of 1. This means that the first value tested will be 10 and each subsequent test will increase the value by 1 (the increment) until the Max. Value of 40 has been reached. The optimization will perform iterations based on these value ranges to determine the optimal combination of input values.

Optimization Criterion
Optimization is based on the best result criterion selected by the trader. There are more than a dozen different optimization criteria from which to choose, as shown in Figure 28. If a trader selects "max. profit factor" for the "Optimize on …" criterion, for example, the optimizer will seek the optimal input values that return the best maximum profit factor.

Choose a result criterion on which to base the optimization.
Figure 28: Choose a result criterion on which to base the optimization.



Optimization Results
After the optimization test has completed, the Strategy Analyzer window will show an "Instruments" tab and an "Optimizer" tab. The Instruments tab, shown in Figure 29, displays the best optimization result for each instrument included in the test. The Optimizer tab displays the top X number of results based on the value set under the "Keep best # results" property in the Optimizer dialog window.

The Instruments tab displays the best optimization result for each instrument included in the test.
Figure 29: The Instruments tab displays the best optimization result for each instrument included in the test.
Image courtesy: NinjaTrader, LLC.


Most of the optimization properties are identical to the ones found in the backtest properties window, with the exception of the following (shown in Figure 30):

  • Aggregated - If set to True, NinjaTrader will find the optimal results for the whole basket of instruments. The COMBINED row in the results tab will display an aggregation of results for the basket of instruments. (Note: this parameter is available only if an Instrument List is selected for optimization.)

  • Keep best # results - Sets the number of best results to display after the optimization.

  • Optimize data series - If True, the Data Series Value property will be available for optimization.

  • Optimize on - Sets the optimization criterion on which to base the optimization results.

  • Optimizer - Sets the optimization algorithm that is used as either Default or Genetic. The Default algorithm tests every possible combination of parameters within the optimization range to find the best results. The Genetic algorithm is able to approximate the best solution without testing every combination.

Optimization specific parameters.
Figure 30: Optimization specific parameters.


Walk Forward Optimization of a Strategy
Walk forward optimization is a process that optimizes strategy input parameters on a set of historical data, then tests the strategy on data that follows the historical data (by "walking forward in time") using the optimized values. The process is repeated by moving the optimization and test segments forward in time.

To Run a Walk Forward Optimization
1. In the Strategy Analyzer window, right-click the desired instrument or instrument list and select "Walk Forward" from the menu, as shown in Figure 31; or, click the "w" (Run Walk Forward Optimizer) icon in the toolbar.

\'Right-click
Figure 31: Right-click an instrument or instrument list and select "Walk Forward" from the menu.


2. Select a strategy from the Strategy slide-out menu.

3. Set the Walk Forward properties.

4. Click "OK."

5. The Walk Forward progress will be shown in the Status Bar of the Control Center.

The Walk Forward properties are identical to those in the Optimization properties with the exception of the following, shown in Figure 32:

  • Optimization period (days) - Sets the number of days used for the "in sample" optimization data set.

  • Test period (days) - Sets the number of days used for the "out of sample" real backtest using the optimized input values generated from the "in sample" period.

Optimization period and Test period are Walk Forward-specific parameters.
Figure 32: Optimization period and Test period are Walk Forward-specific parameters.


SEE: The Pros And Cons Of Automated Trading Systems Advanced Guide To NinjaTrader: Advanced Trade Management Technology

  1. Advanced Guide To NinjaTrader: Introduction
  2. Advanced Guide To NinjaTrader: Market Analyzer
  3. Advanced Guide To NinjaTrader: Strategy Analyzer
  4. Advanced Guide To NinjaTrader: Advanced Trade Management Technology
  5. Advanced Guide To NinjaTrader: Conclusion
RELATED TERMS
  1. Backtesting

    The process of testing a trading strategy on prior time periods. ...
  2. Optimization

    In the context of technical analysis, it is the process of adjusting ...
  3. Optimal Capital Structure

    The best debt-to-equity ratio for a firm that maximizes its value. ...
  4. Search Theory

    A study of buyers and sellers who cannot instantly find a commerce ...
  5. Mechanical Investing

    Buying and selling stocks according to a screen based on predetermined ...
  6. Universe Of Securities

    A set of securities that shares a common feature such as the ...
RELATED FAQS
  1. How was the American Dream impacted by the housing market collapse in 2008?

    Learn how the American Dream was impacted by the housing collapse in 2008. Due to the housing collapse, millions ended up ... Read Answer >>
  2. What is backtesting in Value at Risk (VaR)?

    Learn about the value at risk of a portfolio and how backtesting is used to measure the accuracy of value at risk calculations. Read Answer >>
  3. How can Economic Order Quantity be used to lower inventory costs?

    Learn what economic order quantity is, how it is calculated and how to find the optimal economic order quantity to minimize ... Read Answer >>
  4. How do I build a profitable strategy when spotting a Triple Bottom pattern?

    Learn about the triple bottom chart pattern and how to create a profitable trade strategy based on this pattern, including ... Read Answer >>
  5. How do I build a profitable strategy when spotting an Triple Top pattern?

    Learn how to create profitable trade strategy based on the triple top chart pattern, including optimal entry and exit points ... Read Answer >>
  6. How do bankruptcy costs affect a company's capital structure?

    Understand the Modigliani and Miller theory of capital structure. Learn how the theory shows how bankruptcy costs affect ... Read Answer >>

You May Also Like

Hot Definitions
  1. Yield Curve

    A line that plots the interest rates, at a set point in time, of bonds having equal credit quality, but differing maturity ...
  2. Stop-Limit Order

    An order placed with a broker that combines the features of stop order with those of a limit order. A stop-limit order will ...
  3. Keynesian Economics

    An economic theory of total spending in the economy and its effects on output and inflation. Keynesian economics was developed ...
  4. Society for Worldwide Interbank Financial Telecommunications ...

    A member-owned cooperative that provides safe and secure financial transactions for its members. Established in 1973, the ...
  5. Generally Accepted Accounting Principles - GAAP

    The common set of accounting principles, standards and procedures that companies use to compile their financial statements. ...
  6. DuPont Analysis

    A method of performance measurement that was started by the DuPont Corporation in the 1920s. With this method, assets are ...
Trading Center