Thank you AndrewAMD for your reply. Your suggestion unfortunately didn't work; it made optimization for the first asset only.

I read many times the manual and made the following changes in the code:

Quote

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) ...,


I changed: while(loop(asset.... ===> for(used_assets) ...

Quote

and optimize the parameters outside the for loop.


Quote

Make sure in that case to select all assets before the first optimize call;


Quote

otherwise the optimizer will assume a single-asset strategy.


Code

var threshold;  // global optimize parameter  
function run() 
{
   set(LOGFILE | PLOTNOW );
   set(PARAMETERS);

   threshold = optimize(a,b,c,1);

   	for(used_assets)  // first loop
	{
             Needs no optimization
        }

   	for(used_assets)  // second loop
	{
             Needs no optimization
        }

   	for(used_assets)  // third loop
	{
             threshold decides how many assets to trade
             without optimize, go 3 assets long
             with optimize, go 1 or 2 or 3 or 4 or 5 assets long
        }

        The optimize runs on the last asset only. The manual says: [b]Make sure in that case to select all assets before the first optimize call[/b]
        How to select all assets before the first optimize call?

       David



***** UPDATE *****

The above code works OK, I got the optimization for the global var "threshold"

Interesting that the performance degraded after the optimization, holding always 3 assets got the best performance.

Last edited by dBc; Yesterday at 14:35.