IncludeTradeHistoryInBacktest

<< Click to Display Table of Contents >>

Navigation:  NinjaScript > Language Reference > Strategy >

IncludeTradeHistoryInBacktest

Previous page Return to chapter overview Next page

Definition

Determines if the strategy will save orders, trades, and execution history. When this property is set to false you will see significant memory savings at the expense of having access to the detailed trading information.

 

Notes:

Since trade information is not stored you will only see entry/exit executions plotted on the chart with no connecting PnL trade lines.
This property is set to true by default when a strategy is applied to a chart. However, in any other window (Strategies tab, Strategy Analyzer), it will be set to false by default. If you are working with a strategy outside of a chart, and would like to save orders, trades, and execution history for reference in your code, you will need to set IncludeTradeHistoryInBacktest to true in your script.
During Strategy Analyzer Optimization in a 32-bit process, the IncludeTradeHistoryInBacktest property is forced to false due to the limited resources available in a 32-bit environment.  You must use a 64-bit process if trade history is needed during optimization.

 

 

Property Value

This property returns true if the strategy will include trade history; otherwise, false. Default is set to true.  Always false during a strategy analyzer optimization on a 32-bit process.

 

Warning:  This property should ONLY bet set from the OnStateChange() method during State.SetDefaults or State.Configure

 

 

Syntax

IncludeTradeHistoryInBacktest

 

Examples

ns


protected override void OnStateChange()
{
    if (State == State.SetDefaults)
    {
        // Explicitly include trade history in a backtest
        IncludeTradeHistoryInBacktest = true;
    }
}
 
protected override void OnBarUpdate()
{
  // Stop taking trades after 10 trades have been taken since the strategy was enabled
  if(SystemPerformance.AllTrades.Count >= 10)
      return;
}