Hello,

I'm trying to optimize two global parameters in my strategy.
Workshop5/6 optimize per asset/algo, which is not my case.

I read the manual and probably misunderstand it; due I got an error:
Quote

Zorro 2.66.3
(c) oP group Germany 2025


rs compiling............
WFO: rs 2020..2025
Error 111: Crash in run: run() at bar 1


From the manual I read:
Quote

In portfolio strategies, parameters should be normally optimized separately for any component. Use one or two loop() calls to cycle through all used assets and algos. For optimizing asset/algo specific parameters, place the optimize calls inside the inner loop, and make sure to select asset and algo before. 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. The global parameters are then assigned to the first asset and/or algo. If asset/algo specific optimization is not desired at all, don't use loop, but enumerate the assets in a simple for loop, f.i. for(used_assets) ..., and optimize the parameters outside the for loop. Make sure in that case to select all assets before the first optimize call; otherwise the optimizer will assume a single-asset strategy.


From the bolded phrase I understood the following:

Code
// The strategy, once a week decides which 3 assets out of a bank of assets, to buy. It's a long only strategy.
// var threshold should optimize how many assets to hold

var threshold;  // this is a global var outside the loop which I wish to optimize

function run() 
{
   set(PARAMETERS);

   NumWFOCycles = 15; // activate WFO

   if (FIRSTINITRUN)  // I tried FIRSTRUN too, same error 
		threshold = optimize(N_OF_ASSETS-2,N_OF_ASSETS-3,N_OF_ASSETS,1);

   while( loop( ..... { // first loop over the assets
   } // end of while loop


   while(loop(.... { // second loop over the assets, run after the first loop was finished

   } // end of while loop


   for( over all assets ... {

                   Each asset is compared to the threshold, after optimizing it should decide to take 1 or 2 or 3 or 4 or 5 assets, instead 3 assets, before the optimize.

   } // end of for loop
                 


The second parameter I want to optimize, is the LookBack build-in var.

Any insight over global parameters optimization will be appreciated.

David

Last edited by dBc; Yesterday at 14:37.