The manual also says:
All optimize calls must be placed either in the run function or in functions that are called from the run function. Since parameters are identified by the order of their optimize calls, the order must not change between test and training or from one run to the next.
You made an optimize call disappear in subsequent run calls. Not good.
Then there's this quote:
For optimizing additional global parameters that do not depend on asset and algo, place their optimize call in the very first loop run only, and store the parameter in a static or global variable outside the loop.
Probably not the clearest verbiage, but I think it's saying that optimize() should only be called once for the global variables inside the first loop() call, not the first run() call. (That is, "the first time loop() is run".) If that's the case, you need to say if(this is the first loop call) then global variable = optimize().