Loading…

Universal Divergence Engine

The CodeBase is full of single-oscillator divergence tools: an RSI divergence indicator, a MACD divergence indicator, a CCI divergence indicator, each rewritten from scratch around one specific buffer. This indicator does the same swing-pivot-and-compare job generically, by loading any other installed custom indicator's buffer through iCustom rather than computing its own oscillator internally. Point it at RSI, MACD, CCI, a volume oscillator, or any single-buffer custom indicator and it runs the same divergence engine against it. It also classifies twice as many patterns as most divergence tools bother with. Regular divergence - price makes a higher high while the indicator makes a lower high (bearish), or a lower low while the indicator makes a higher low (bullish) - is the classic reversal signal every divergence tool covers. Hidden divergence is the mirror image and a genuine trend-continuation signal: price makes a lower high while the indicator makes a higher high (bearish continuation), or a higher low while the indicator makes a lower low (bullish continuation). Most published divergence indicators only ever look for the regular case; this one flags both, tagged separately on the chart. Swing pivots are confirmed fractal-style (InpPivotBars bars required on both sides), so nothing here ever revises a divergence call after the fact on bars that have already closed - a divergence can only move from "not yet confirmed" to "confirmed", never the reverse. Both the pivot scan and every iCustom lookup are gated to run once per new bar rather than on every tick, since pivot confirmation cannot change mid-bar and iCustom calls are not free. The one real limitation, stated plainly: iCustom is called here with only the buffer index and shift arguments, so the target indicator always runs on its own default input settings. There is no generic way to forward an arbitrary number and type of inputs through iCustom's fixed argument list to an indicator this engine knows nothing about in advance - if a specific parameter set matters, attach that indicator to the chart first with those settings as its new defaults, or accept its published defaults. Notes and limitations - Runs the target indicator on its own default settings only - see the full description above for why this is a structural limitation of iCustom, not an oversight. - If InpCustomIndicatorName is misspelled or the file is not installed, iCustom silently returns EMPTY_VALUE at every shift and no divergence will ever be drawn - there is no reliable way in MQL4 to distinguish "not installed" from "still warming up" from inside the calling indicator, so check the Experts log for iCustom-related errors if nothing appears. - Only compares a single named indicator's single buffer against price at a time - it does not scan multiple indicators simultaneously. - Does not repaint on already-confirmed pivots - a pivot only exists once InpPivotBars later bars have printed, so a divergence line, once drawn, is never erased or moved by later price action.

Indicator · MT4 · v1.0 · Free

About Universal Divergence Engine

Universal Divergence Engine is an indicator for MetaTrader 4 based on Divergence. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Custom indicator name, Buffer index and Pivot bars. MQL source code included.

Files in the download: UniversalDivergenceEngine.mq4, UniversalDivergenceEngine.txt.

Settings

SettingDefaultWhat it does
Custom indicator nameName of the custom indicator to load, e.g. Examples\\MACD (path relative to Indicators\\)
Buffer index0Buffer index to read from that indicator (0 = its first plotted buffer)
Pivot bars5Bars required on each side to confirm a swing pivot
Max pivot age300Ignore a divergence pair if the older pivot is more than this many bars back
AlertstrueAlert once when a new divergence confirms

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: MACD · RSI · Pivot Points · CCI · Divergence · Oscillator · Alerts · MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria