# amibroker

### Using optimum parameter values in backtesting

After Optimization process has found optimum values for parameters of our trading system, typically we want to use optimum values in subsequent backtesting or explorations. In order to achieve that, we need to manually update default_val (second) argument of Optimize function with the values obtained from the optimization report.

The arguments of Optimize function are shown below (note second parameter marked in dark red color – this is the default value parameter we will be changing after optimization run):

`some_var = Optimize( "description", default_val, min_val , max_val, step );`

Let us consider the following example formula used for optimization process:

`SetOption("ExtraColumnsLocation", 1);periods = Optimize( "Periods", 2, 5, 50, 1 ); // note that default value is 2Level = Optimize( "Level", 2, 2, 150, 4 ); // note that default value is 2Buy = Cross( CCI( periods ), -Level );Sell = Cross( Level, CCI( periods ) )`

If we perform Optimization process and check the results (for this example we use Net Profit as the optimization target), we can see that the best results use Periods = 6 and Level = 126.

Now in order to run backtest and obtain exactly the same results as in the respective line of the above Optimization results, we need to enter the values into default argument, so the modified code will look like this:

`SetOption("ExtraColumnsLocation", 1);periods = Optimize( "Periods", 6, 5, 50, 1 ); // we changed default value to 6Level = Optimize( "Level", 126, 2, 150, 4 ); // we changed default value to 126Buy = Cross( CCI( periods ), -Level );Sell = Cross( Level, CCI( periods ) )`

Now we can use the code with modes other than Optimization and the formula will use optimized values we retrieved from the results.