# Optimize 2 parameters individually only. Avoid testing all combinations

Suppose I have 2 parameters to optimize.

``````param1 = Optimize("param1 ", default_=1, Min_=1, Max_=4, step=1);
param2 = Optimize("param2 ", default_=1, Min_=1, Max_=4, step=1);
``````

If I run the code above, Amibroker will test out ALL possible combinations of the 2 parameters values. In this context, there will be 4x4=16 rows displayed in the optimization test results.

This is not what I want. What I want is to test out each parameter individually. I don't want to test out all possible combinations of the 2 param values. So, there should be 4+4=8 rows displayed in the optimization test results.

Thank you.

You may use `Exclude` statement

What are the combinations you are actually looking for?
I mean if you use two times Optimize() then you will get two columns.

If both columns shall show just 1 to 4 then it is not 8 rows but 4 rows.
So Exclude line would be

``````Exclude = param1 != param2;
`````` If param1 shall not be same as param2 then

``````Exclude = param1 == param2;
``````

But this will not get 8 rows but 12. From your post it does not make much sense to me what you are trying to do.

Both have same range 1 to 4. I guess it is just simple example.

How are they (param1 and param2) used in later code?
Are they used for same indicator?
Do you want to use different ranges for single indicator?
Why not using just one param line (so just one Optimize code line)?
-> So why not using optimize together with matrix (holding periods or whatever param is supposed to be)?

Then you need just single Optimize(). So you get single result column.

1 Like

What I have been doing is running single Optimize() 2 times.
Run this optimization; Then run this optimization; What I want is actually combine the results of 2 single Optimize() into one Optimize run. It will look something like this; Yes, but I was asking specific questions about what is goal (different or same range, same indicator, ...).

But if you just want them to be as in your spreadsheet....
Then as I wrote you may use `Exclude` statement:

Note: zero serves as "ignore".

``````param1 = Optimize("param1 ", 1, 0, 4, 1);
param2 = Optimize("param2 ", 1, 0, 4, 1);

Exclude = (param1 != 0 AND param2 != 0) OR param1 == param2;

if ( param1 > 0 AND param2 == 0 ) {
// Then do this
_TRACEF( "1 -> param1:%g, param2:%g", param1, param2);
}

if ( param2 > 0 AND param1 == 0 ) {
// Then do that
_TRACEF( "2 -> param1:%g, param2:%g", param1, param2);
}
`````` 3 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.