Skip to content
All library documents

Configuring an Indicator to Detect Price Divergences

Article MQL5 code base

Summary

This indicator plots paired lines across the price chart and an oscillator chart to mark bullish and bearish divergences. It supports four divergence classes, each with controls for whether to detect it and for the colors used to display bullish and bearish lines. The price series is compared with a selected base indicator, such as RSI, MACD, Momentum, RVI, Stochastic, or Standard Deviation; two additional built-in choices are also described. Users can instead select a custom indicator and configure its name, data buffer, and input parameters.

Detection relies on locating local extrema and matching price extrema with indicator extrema. Settings control the maximum distance used to find a second support point and the allowed separation between price and indicator extrema. Because an extremum requires a central bar with bars on either side, the indicator registers divergences with a two-bar delay. The description explains configuration and timing, but gives no performance evidence, trading rules, or guidance on whether a detected divergence predicts a reversal.

Key ideas

  • The indicator displays divergences as matched lines on price and indicator charts.
  • It can compare price with several built-in indicators or a configured custom indicator.
  • Users can select which divergence classes to register and set their display colors.
  • Detection uses local extrema and configurable limits on search depth and extremum alignment.
  • A two-bar delay follows from requiring bars on both sides of a local extremum.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.