Working with Historical Trade Data

<< Click to Display Table of Contents >>

Navigation:  Operations > Strategy Analyzer >

Working with Historical Trade Data

Previous page Return to chapter overview Next page

The Trade class allows you to directly access information about historical trades. However, Trade objects are not always accessible from a NinjaScript strategy by default. The IncludeTradeHistoryInBacktest property determines whether references are made in memory to Trade objects, allowing you access them programmatically after a trade has completed, or whether no references are made, freeing up memory for other uses.

 

IncludeTradeHistoryInBacktest = True

When the IncludeTradeHistoryInBacktest property is set to true, Trade objects will be saved for later reference. This provides a reference to the object in memory, allowing you to access them in your script. For example, this setting would allow you to evaluate the Max Adverse Excursion statistic of an individual trade placed by the strategy in the past. While this can be convenient to address specific needs, it uses more memory than the alternative option. To maximize performance in cases in which you know you will not need to access historical Trade objects, it is recommended to set IncludeTradeHistoryInBacktest to false in the Configure state in your script.

 

Note: This property is set to true by default ONLY when applying a strategy to a chart. If you wish to disable it when applying a strategy to a chart, you will need to explicitly set it to false in your script.

 

 

IncludeTradeHistoryInBacktest = False

When the IncludeTradeHistoryInBacktest property is set to false, Trade objects will not include a reference in memory. Once a trade is completed, no Trade object will be accessible to the script. This setting allows for leaner memory management by avoiding the storage of a potentially large number of objects that may never be used. That being said, if you know that you will need to access these objects after trades have completed, you can set IncludeTradeHistoryInBacktest to true in the Configure state in your script.

 

Note: This property is set to false by default when applying a strategy directly in the Strategies tab of the Control Center, or when using the Strategy Analyzer for backtesting or strategy optimization. If you wish to enable it when applying a strategy in either of these ways, you will need to explicitly set it to true in your script.