I am currently developing a statistical tool in NinjaTrader 8 to compare trades between different variations of my strategy. For this purpose, I am utilizing a slightly modified version of the SampleMaCrossOver strategy, where I've added print statements to monitor the strategy states during execution.
While running a single backtest and analysing the lifecycle of the strategy through the Strategy Analyzer, I noticed some peculiarities in the sequence of states. The sequence I observed was as follows: the strategy switches to the SetDefaults state, then to the Terminated state three times, back to SetDefaults two times, and finally terminates. I have attached a text file (SampleMaCrossOverStrategyAnalysis10.txt) that shows this sequence as output from my print statements.
Next, I conducted an optimization test by adjusting the 'Fast' parameter from 10 to 15 in increments of 5, with IsInstantiatedOnEachOptimizationIteration set to false. When examining the print outputs, it appears that the first and second iterations of the strategy run concurrently. This concurrency poses a challenge for data collection as trades from the first iteration intermingle with those from the second in my csv output files. You can observe this behavior in the attached text file (SampleMaCrossOverStrategyAnalysis10&15.txt).
I am seeking answers and guidance for the following:
- Why does the strategy cycle through the SetDefaults and Terminated states multiple times at the end of a backtest? Is this the expected behavior? If not, what might be causing this in my code?
- In the optimization test, how can I prevent iterations of the strategy from running concurrently and avoid intermingling of data in my csv files? Is there a recommended method for cleanly extracting this data?
- Is it possible to directly export the strategy data to an .xlsx file instead of a .csv? If so, could you provide some guidance or refer me to relevant documentation/examples on how to accomplish this?
- Given that my primary goal is to export the strategy data for further analysis in Excel, do you have any additional recommendations on how to optimize my data extraction process or any features of NinjaTrader that may assist in this endeavor?
I have also attached the modified SampleMaCrossOver strategy code (SampleMaCrossOverStrategyAnalysis.cs) for reference. The start and end dates for all the backtests are 01/05/2023 and 23/05/2023 respectively.
Thank you for your time and assistance.
Best Regards,
Aviram Y

Comment