Example 7 – Optimized Crossover

NOTE: In NeuroShell Trader, open the chart named “Example 7 – Optimized Crossover” which is the basis for following example:

After reading Example 5 and Example 6 you may be wondering if the crossover rules that we picked could be improved upon without manually changing the lookback parameters. That’s where our genetic algorithm optimizer comes into play. We can optimize the moving average periods in Example 6 to see if we can find periods that do better than the periods of 12 and 26. If you examine the trading strategy, you will see that we have chosen “Rule Parameter optimization” in the dropdown box over top of the long and short entry tabs. Rule Parameter optimization adjusts the parameters of the conditions (rules) used for long entry and short entry.

When you optimize you can and should set appropriate ranges for each variable. The genetic algorithm optimizer (in this case the Evolution Strategy option) will keep the variables within those ranges when it optimizes. Unlike other optimizers, you do not need an “increment” for each variable, because genetic algorithms do not search in increments. They aren’t trying all combinations either, like many “exhaustive search” optimizers do. Instead they are using a technique similar to “selective breeding”, and each new solution that evolves can be anywhere in the “search space”, so to speak. Optimization stops after new solutions are not found after a number of attempts computed by an internal algorithm. It is possible that if you set optimization to run longer, a better solution might be found, but odds are it will not be exceptionally better.

To see the ranges for the variables (set at first to a default range), navigate to the dialog where we entered the long entry and short entry rules. To the left side of the rules you will see a plus sign (+). Click on the plus sign and the rule will “open up” to reveal the selected ranges. Double clicking on any range allows you to change it. We set the ranges for all averaging periods from 1 to 40 days (which would be bars instead of days on an intraday chart).

In the “Optimization” tab you will see a dropdown box where you can set various “Objective functions” of the optimization process. The default is “maximize return on account” because that’s the easiest for most people to understand. However, as you get more advanced you can try different ones.

In the “Trading Strategy Results Summary” dialog (the final one in the wizard) you can press the “Detailed Analysis” button to see a host of trading statistics about the backtest completed after the optimization was complete. In the tab called “Trading Rules” you will see the crossover parameters that the optimizer determined were best over the time period in the chart.

The averaging periods for the red and blue moving averages do not change on the chart when optimization chooses new ones. When you insert a moving average crossover into a trading strategy, it is really a new copy, not the one already on the chart. So when the optimizer finds new averaging periods, the averages on the chart are not changed. Therefore we deleted them and inserted the complete crossover rules the optimizer selected. We did that by going to Insert->Existing Data/Calculations and then clicking on the plus(+) sign beside Trading Strategy, and again on the plus sign beside Inputs. Then we selected the completed crossover rules there. Note that they have values of either 0 (false) or 1 (true) indicating if a crossover took place on that bar or not.

Was this article helpful?

Related Articles