Essentially i'm trying to create a 'Monte Carlo' type simulation using NinjaScript and Optimization in Strategy Analyzer. I've written a simple SMA strategy and when I run it in Optimization it seems to work, except that the results that show up for each iteration aren't what they actually are. In other words, the data in the 'list' of all iterations is wrong. If you click on one particular line it doesn't show the same information as it does in the Summary section. I've attached a screenshot of this and also a copy of the strategy.
I suspect the reason it's broken is because of the way i've coded the Random class. I think i've overly complicated it, and perhaps placed code in the wrong spot. What i'm trying to do is run a number of iterations for a strategy (refer the property Iterations). For each Iteration I want the strategy to chose random values for both the Fast and Slow SMA, and I want the strategy to keep those values for the whole Time Frame (not change them after every trade). So after running the strategy in Optimization with Iteration set to 10 for example I should get 10 different sets of parameters for both Fast and Slow SMA.
I couldn't work out how to generate random values outside of OnBarUpdate. Is there a better way to code this and get the performance results to show correctly in Strategy Analyzer?
Comment