Sometimes I run longer Strategy Analyzer optimizations and they get interrupted. Either by me or some outside force. As far as I can tell, the results of the iterations which were completed do not appear in the Strategy Analyzer window if the entire optimization process is not finished.
Is there a setting or another way to see the results of the iterations that were completed before the optimization was interrupted? Would I have to manually write results to a custom file as part of the strategy code? Thanks.
2 Likes
There's no setting for it that I've found. The results grid gets populated when the optimization completes, so interrupting it loses whatever was held in memory.
Writing from the strategy does work, but NinjaTrader runs several iterations concurrently during an optimization. If they all append to the same file you'll get interleaved or truncated lines. Give each iteration its own filename. The other limitation is that the strategy has no idea what fitness value the optimizer assigned, so you end up logging the input values and reassembling everything afterwards.
The route I'd suggest instead is a custom Optimizer. NinjaTrader ships `@DefaultOptimizer.cs` and `@GeneticOptimizer.cs` as editable source and they're the template. Subclass `Optimizer`, drop the file in `Documents\NinjaTrader 8\bin\Custom\Optimizers\`, compile, and it turns up in the Optimizer
dropdown next to Default and Genetic.
What makes it solve your problem is that you own the loop: you set the parameter values, run the iterations, then read the results once they finish. Persist each batch there and an interrupt costs you at most the batch in flight, with the fitness values and parameter sets already together.
1 Like
hmm I was not considering the optimizer code itself could be customized. That’s an interesting idea. Thanks for sharing!