FX5_Divergence — OSMA Divergence Indicator for MT4 (Bullish & Bearish Setup Detection)

The FX5_Divergence indicator detects classical and reverse bullish/bearish divergences between price and OsMA (Moving Average of Oscillator). It highlights potential turning points by comparing price highs/lows to OsMA peaks/troughs, plotting clean arrows and (optionally) drawing matching trend lines on the chart and in the indicator window. With configurable EMA settings and optional alerts, it’s a practical tool for traders who want objective divergence confirmation without clutter.

What this indicator does

How it works (inside the code)

  • OsMA calculation: Uses iOsMA with fastEMA, slowEMA, and signal (defaults 12/26/9). Positive values are placed into the up buffer; negatives into the down buffer.
  • Peak/Trough detection:
    • Peaks require OsMA above zero and a local maximum compared with neighbors, then a forward check to avoid premature signals.
    • Troughs require OsMA below zero and a local minimum with a similar forward check.
  • Divergence rules:
    • Bullish classical: OsMA makes a higher low while price makes a lower low.
    • Bullish reverse: OsMA lower low while price makes a higher low.
    • Bearish classical: OsMA lower high while price makes a higher high.
    • Bearish reverse: OsMA higher high while price makes a lower high.
  • Signals and lines: When a rule matches, the indicator plots an arrow and, if drawDivergenceLines = true, it draws a line between the two price swings and another between the two OsMA swings (solid for classical, dotted for reverse).
  • Alerts: If displayAlert = true, it triggers an alert only when the setup is near the most recent bars (to reduce noise).

Download the Indicator for MT4

You can download both the ready-to-use EX4 file and the editable MQ4 source code for free below.

Inputs

  • fastEMA (default 12)
  • slowEMA (default 26)
  • signal (default 9)
  • drawDivergenceLines (true/false)
  • displayAlert (true/false)

Visual elements

  • Positive OsMA histogram bars: Lime/Green
  • Negative OsMA histogram bars: Firebrick/Red
  • Bullish divergence arrow: Wingdings 233
  • Bearish divergence arrow: Wingdings 234
  • Optional divergence lines on price and indicator windows

Installation (MT4)

  • Open MetaTrader 4 → File → Open Data Folder.
  • Go to MQL4 → Indicators.
  • Paste Divergence inficator .mq4 or the compiled .ex4 into the Indicators folder.
  • Restart MT4 or right-click Navigator → Refresh.
  • Drag “FX5_Divergence_V2.1” from Navigator → Indicators → Custom onto your chart.
  • Adjust inputs, click OK.
Divergence Indicator

How to use it

  • Wait for a divergence indicator arrow. Classical patterns (solid lines) tend to be more reliable than reverse (dotted) patterns.
  • Use higher-timeframe trend or structure as a filter. Favor bullish divergences in established uptrends and bearish divergences in downtrends.
  • Confirm with confluence: price action at key levels, session timing, or a volatility measure (ATR).
  • Consider entries on bar close to avoid intra-bar flicker.
  • Manage risk with stops beyond the divergence swing and take-profits at nearby structure or R multiples.

Example playbook

  • Bullish classical divergence indicator: Price prints a lower low but OsMA forms a higher low, green arrow prints. Enter long after candle close; stop below the divergence low; scale out at prior swing highs.
  • Bearish classical divergence indicator: Price prints a higher high but OsMA forms a lower high, red arrow prints. Enter short after candle close; stop above the divergence high; cover near structure.
  • Reverse divergences can signal early slowdowns; require extra confirmation.

Best practices

  • Test and tune fast/slow/signal periods for your instrument and timeframe.
  • On lower timeframes, consider stricter filters (e.g., only classical divergences, or require an engulfing/structure break).
  • Avoid trading directly into major news; divergences indicator can get overwhelmed by liquidity bursts.
  • Keep charts tidy: enable line drawing only when you need visual study.
JustMarkets

Pros

  • Objective, code-driven divergence detection.
  • Optional synchronized lines for quick study and screenshots.
  • Alerts only when signals form near the most recent bars.
  • Lightweight and responsive across symbols/timeframes.

Limitations

  • Like all divergence indicator tools, signals can fail in strong trends or during news.
  • Peak/trough logic aims to reduce noise but is not foolproof on very low timeframes.
  • Reverse divergences are more “early warning” than stand-alone entries.

FAQ — FX5_Divergence_V2.1 (OSMA Divergence) for MT4

Does it repaint?

Signals are evaluated on completed bars using fixed peak/trough logic. During a forming candle, arrows may appear or disappear; evaluate on bar close for consistency.

Which timeframes work best?

H1–H4 for cleaner divergences; M15 can work with stricter filters. On M1–M5, expect more noise—use higher confluence.

What’s the difference between classical and reverse divergence?

Classical divergence opposes price extremes (e.g., higher high in price vs. lower high in OsMA) and often signals reversals. Reverse divergence is an early warning of momentum changes—use more confirmation.

Can I change arrow types and colors?

Yes. Edit SetIndexArrow codes (e.g., 233/234) and color properties. You can also toggle line drawing and alerts via inputs.

Disclaimer: This indicator is for educational and informational purposes only and does not constitute financial advice. Trading involves risk, including possible loss of principal. Test thoroughly on a demo account before using live. You are responsible for any modifications or use of the source code.

Download the Indicator for MT4

You can download both the ready-to-use EX4 file and the editable MQ4 source code for free below.

Share your love
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments