- define optimization variable

Trading system toolbox
(AmiBroker 3.70)

SYNTAX Optimize( "description", default, min , max, step )
FUNCTION Defines optimization process parameters. With normal backtesting, scanning, exploration and comentary modes the optimize function returns default value, so the above function call returns default; In optimization mode optimize function returns successive values from min to max (inclusively) with step stepping. "description" is a string that is used to identify the optimization variable and is displayed as a column name in the optimization result list. default is a default value that optimize function returns in exploration, indicator, commentary, scan and normal back test modes min is a minimum value of the variable being optimized max is a maximum value of the variable being optimized step is an interval used for increasing the value from min to max
EXAMPLE variable = optimize("my optimization var", 9, 2, 20, 1 );


Herman van den Bergen
psytek [at] magma.ca
2003-06-09 05:23:31
You can Optimize parameters with custom number series by using the numbers generated by the Optimize() function as an index to access numbers in a custom array. Here is an example using a custom array FB[] of Fibonacci numbers:

FB[0] = 0.0; FB[1] = 23.6; FB[2] = 38.2; FB[3] = 50.0; FB[4] = 61.8; FB[5] = 100; FB[6] = 161.8; FB[7] = 261.8; FB[8] = 423.6;
FBindex = Optimize("FBindex",0,0,8,1);
FibNum = FB[FBindex];
... place your Code using FibNum here ...
Herman van den Bergen
psytek [at] magma.ca
2003-07-20 17:26:08
You can refresh your Equity chart after each Optimization step and observe (like a slide show) how the linearity of your Equity curve is effected by adding these two lines to the very end of your code:

AB = CreateObject("Broker.Application");

Important note: Do not use in commentary, interpretation, or indicator builder because it will cause loop. (Thanks for the tip TJ!)
Graham Kavanagh
gkavanagh [at] e-wire.net.au
2004-08-21 23:31:39
When optimising for 2 or more variables make sure you have different names for each variable.
x = Optimize("Short",5,5,10,1);
y = Optimize("Short",15,25,55,1);

I made mistake of copy/paste and did not change the optimize name (as above) within the brackets and got all zeroes as results.

This below gets results
x = Optimize("Short",5,5,10,1);
y = Optimize("Long",15,25,55,1);

Tomasz Janeczko
tj --at-- amibroker.com
2006-12-12 11:30:18
Some asked for function that combines Param() and Optimize(). Here it is:

function ParamOptimize( pname, defaultval, minv, maxv, step )
return Optimize( pname,
Param( pname, defaultval, minv, maxv, step ),
minv, maxv, step );


The Optimize function is used in the following formulas in AFL on-line library:

More information:

See updated/extended version on-line.