Optimization of the trading algorithm: An example
Optimization features of the Protrader terminal were considered in the articles “Optimization of the trading algorithm: Introduction" and "Optimization of the trading algorithm: Target functions and setup”. Also the functional of the Walk forward option was disclosed in the article “Optimization of the trading algorithm: Walk forward optimization”. In the current article we’ll try to combine all the described optimization steps, and to use fully the AlgoStudio capabilities on the simple strategy example.
Open the AlgoStudio:
Choose the script in which the trading system algorithm is implemented on MQL4 language.
Selected trading strategy called “Impulse” was described in the article “Trend strategy implementation example”. After loading the “Impulse” script, it needs to be compiled for its further usage in the optimization module. To provide this click the “Compile” button.
If the compilation is successful then in the optimization window the external variables of the trading system will become available for optimization, and information about the script will also appear.
Now let’s move to the optimization settings. The first thing to pay attention to is the window “Backtesting setup”. Here we need to choose the instrument on which the optimization and the test will be held. Choose the trading pair EURUSD in the “Symbol” window. “Time frame” of the testing set in 15 min. Let’s set the custom testing period, to provide this choose the “Custom” value in the “Range” row. Since I’m interested in performance of the selected strategy for the last year, I choose 01.01.2013 in the field “Start time” and 01.01.2014 in the “Stop time”.
To accelerate the optimization process and testing I choose the “Modeling scheme” 1 m – Close. This suggests that while modeling the historical data only close prices of minute bars will be used. The test strategy does not require more detailed data. Selection of detailing data is individual for each trading strategy.
Let’s move to the optimizing algorithm setup - > “Optimization setup” window. We will use the genetic algorithm, to provide this choose “Genetic algorithm” in the “Type” window. Since the target optimization area is quite large, we will use “gradient” and “elitism”. Also let’s increase the chromosomes count to 50.
Now we move to the determination of the optimized system parameters. In this case there will be quite a large number of them. Let’s choose the variables that need to be optimized and determine the intervals of their changing in the “Strategy variables” window.
To hold a full-fledged optimization it remains to determine the target function. Let's define target functions and their weights with which they will enter the resultant target function in the “Targets” window. We will maximize the target function “Profit factor”.
Setup is over, so let’s start the optimization using the “Run” button. Note that for each strategy, depending on the target area type of optimization, you need to pick the optimal parameters of the optimization settings. The optimal optimizer settings are those that provide the best ratio of the result accuracy to the expended time.
As we can see by the optimization results, a large amount of trading system settings for the selected period reaches high values of the target function “Profit factor”. Look at the chart of balance that was received while trading with one of the optimal parameter sets. It suffices to choose the trading system parameter set which we are interested in, and activate “Analyze results” in the context menu.
Balance chart is fairly flat, without large discrepancy with the curve “Equity”. But just how we can trust to the obtained results? How to understand how sustainable are they?
To provide this, you need to hold the forward test that will show the sustainability degree of the obtained results. As we know from the article “Optimization of the trading algorithm: Walk forward optimization” there is a ready-made module for optimization followed by forward test. It called “Walk forward” optimization. Let’s verify the sustainability of solutions that were obtained by optimization. Choose the needed optimization type for this.
Set the values of optimization period “IS period” and forward testing period “OS period” equal to 100 days.
As we can see from the “Walk forward” optimization results, the obtained selected optimal set of trading system parameters failed to show at least roughly similar results as shown on the optimization and forward test periods. Low value of the “Robust” indicator also shows it. This fact indicates instability of the obtained optimal system parameters on the selected period of historical data.
It may be noted the small number of trades in the optimized variants. Possibly while increasing the optimization area you will be able to get more stable results. I will finish the cycle of “Optimization of the trading algorithm” by this article. I hope that the above-described method of optimization will help readers to use more effectively the capabilities of the Protrader terminal.
Have not tried PTMC yet? There is no better way to boost knowledge than to use it! Start trading with PTMC now!