But weird things were happening when I tried to optimize a strategy. So I keyed my order names to the strategy parameters, to be sure that the order names were consistent with the iteration being run.
I discovered that each new iteration of the optimization was polluted by filled positions that were active from prior iterations.
For example, I have two parameters, EMAlength and TargetMultiple. For EMAlength=12 and TargetMultiple=3.5, all order names will have "123.5" appended to them. OnStartUp() prints "123.5" to the Output window to indicate which iteration is running.
But then my order management framework generates internal error messages to the Output window with strings like "125" and "124.5" appended to the order name, saying it does not recognize these orders that just got filled. And it shouldn't. These fill events shouldn't even be happening because those orders were never placed in that iteration.
I'm using unmanaged orders.
How do I make sure that everything is FLAT at the end of each optimization iteration, so no remnants of previous positions or orders pollute the new optimization iterations?

Comment