Refactoring Divergence Detection into a Reusable MQL5 Engine
Summary
This article turns divergence logic previously embedded in an adaptive SuperTrend implementation into a standalone MQL5 module. The engine groups oscillator calculation, pivot detection, divergence classification, and state memory, and offers setup, update, calculation, query, and teardown functions. It supports an MPO4 oscillator calculated from price data or RSI through an indicator handle, allowing separate consumers to reuse the same detection logic without copying it into each project.
A lightweight Parabolic SAR expert advisor demonstrates integration: it queries divergence state and adapts the SAR acceleration factor when opposing divergence appears. The article also outlines integrating the header into other indicators or EAs and discusses a limitation of the built-in SAR handle that motivates manual calculation. Its evidence is an implementation walkthrough and demonstration, rather than a quantified trading comparison; no general profitability claim follows from the example, and the engine only supplies divergence information for the caller to interpret.
Key ideas
- Separating oscillator, pivot, divergence, and state logic makes the engine reusable across indicators and EAs.
- The module can use either a custom momentum oscillator or RSI as its divergence source.
- Consumers decide how divergence changes their own parameters or trading rules.
- The Parabolic SAR example illustrates integration but does not establish strategy performance.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.