Building a Self-Optimizing Expert Advisor with Virtual Indicator Calculations
Summary
The article describes an Expert Advisor that periodically retunes its strategy parameters against a rolling span of historical data. A manager requests candidate parameter sets from an optimization algorithm, runs each set through a virtual copy of the strategy, scores the results with a chosen fitness function, and returns the best set to the live EA. Re-optimization can occur after a fixed number of bars or when performance reaches a trigger condition.
It also explains how to virtualize indicators so they can be recalculated for each candidate without repeatedly creating platform indicator handles. A Stochastic example is presented as a class with parameter initialization and calculation methods, and the strategy is designed to run on historical data. Walk-forward testing is recommended to assess adaptation across changing periods and reduce overfitting. The article gives an implementation architecture and code-level example, but reports no performance results; it cautions that the example lacks checks required for real-account trading.
Key ideas
- A manager can connect an optimizer to a virtual strategy that evaluates candidate parameter sets on historical data.
- The fitness function should reflect the trading qualities the user wants to optimize.
- Re-optimization can be scheduled by elapsed bars or triggered by deteriorating performance.
- Indicator calculations can be embedded in classes to avoid repeatedly creating and deleting indicator handles.
- Walk-forward testing offers a more realistic check of parameter stability across changing market periods.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.