Guarda come scaricare robot di trading gratuitamente
Ci trovi su Facebook!
Unisciti alla nostra fan page
Script interessante?
Pubblica il link!
lasciare che altri lo valutino
Ti è piaciuto lo script? Provalo nel Terminale MetaTrader 5
Indicatori

Divergence Detector without repaint: RSI, MACD, Stochastic, CCI, Momentum - indicatore per MetaTrader 5

Muhammad Muqeem Korejo
Muhammad Muqeem Korejo
Hi, I'm Muhammad Muqeem Korejo, an MQL4/MQL5 developer from Pakistan with 1.5 years of trading experience.
I build and fix trading tools for MetaTrader 4 and MetaTrader 5:
• Expert Advisors (EAs) built from your strategy rules
• Custom indicators, alerts and on-chart panels
Visualizzazioni:
68
Pubblicato:
Freelance MQL5 Hai bisogno di un robot o indicatore basato su questo codice? Ordinalo su Freelance Vai a Freelance

A divergence happens when price makes a new high but the oscillator does not (or price makes a new low and the oscillator does not). Many divergence indicators look perfect on old charts and disappoint in real time, for two reasons: they draw the signal back on the swing although the swing was only known some bars later, and they delete or move signals when new bars come. This indicator is built so that what you see on an old chart is exactly what you would have seen in real time.

Divergence Detector on a EURUSD H1 chart: regular bullish divergences with RSI, lines on the oscillator and the price

What is drawn

  • The oscillator in its own window (RSI by default; MACD histogram or line, Stochastic %K, CCI or Momentum can be chosen).
  • A line between the two oscillator swings and, optionally, a line between the two price swings on the main chart. Regular divergences: solid lines. Hidden divergences: dotted lines.
  • An arrow on the bar where the divergence was confirmed, in the oscillator window and (optionally) on the price chart.

The four kinds

  • Regular bullish: price makes a lower low, the oscillator a higher low.
  • Regular bearish: price makes a higher high, the oscillator a lower high.
  • Hidden bullish: price makes a higher low, the oscillator a lower low (often seen in an uptrend).
  • Hidden bearish: price makes a lower high, the oscillator a higher high (often seen in a downtrend).

Regular divergences are on by default, hidden ones can be switched on.

No repaint

  • A swing counts only after 3 bars (an input) have closed after it. It never changes after that.
  • The arrow and the alert come on the bar where the second swing is confirmed, not back on the swing. That is the bar an Expert Advisor or an alert sees it.
  • Only closed bars are examined. A divergence, once shown, is never moved or deleted.

Checks against false divergences

  • Price swings and oscillator swings must both exist, at most 2 bars apart (an input). Values are not simply read from the oscillator at the price swing.
  • Neither price nor the oscillator may cross the straight line between the two swings.
  • The two swings must be 5 to 60 bars apart (inputs), and each new swing is compared with up to 5 earlier swings.
  • Optional zone filter for RSI and Stochastic: bearish divergences only above 50, bullish only below 50.
  • Price swings from highs and lows (wicks) or from closes.

For Expert Advisors (5 buffers)

0 the oscillator, 1 regular bullish, 2 regular bearish, 3 hidden bullish, 4 hidden bearish. Buffers 1 to 4 hold a value only on the bar where that divergence was confirmed. Read bar 1 (the last closed bar): if the buffer is not EMPTY_VALUE, a divergence was confirmed there.

When you call the indicator with iCustom, each "input group" counts as one parameter: pass a string for it, for example iCustom(_Symbol, _Period, "DivergenceNoRepaint", "Oscillator", 0, 14, 12, 26, 9, ...).

Inputs: oscillator and its periods, price source, bars to the left and to the right of a swing, minimum and maximum distance, alignment of the swings, earlier swings to compare, regular / hidden, zone filter, bars to calculate, lines and arrows on the price chart, two colours, alerts (pop-up and push).

How it was tested

  • An independent calculation in Python (own code) rebuilt all swings and divergences from the exported bars and the oscillator, for EURUSD H1 with RSI, XAUUSD M15 with the MACD histogram and GBPUSD M30 with Stochastic, regular and hidden divergences on: 98 signals, 0 differences. The RSI values were also checked against Wilder's formula: identical.
  • Repaint test: on every new bar, a test Expert Advisor saved all buffers of the bar that had just closed. At the end of the test the same bars were read again. 42,000 values compared, 0 changed.
  • Validator-style runs in the Strategy Tester: EURUSD H1, XAUUSD D1, GBPUSD M30 and EURUSD M1 (663,241 bars): no errors. Nothing is drawn in a Strategy Tester run without visualization, but all buffers are calculated.
  • The screenshot is a real EURUSD H1 chart of a demo account.

A divergence is a sign that a move is losing strength, not a trading system by itself. Use it together with your own levels, trend and risk rules.

Key Levels: PDH/PDL, weekly and monthly levels, midnight open, Asian range, sweeps Key Levels: PDH/PDL, weekly and monthly levels, midnight open, Asian range, sweeps

Previous day, week and month high and low, New York midnight open, period opens and the Asian range, with sweep marks and one alert per level. Day from broker or New York time. No repaint, buffers for EAs.

OrderGuard - restart-safe order sending for EAs (no duplicate trades) OrderGuard - restart-safe order sending for EAs (no duplicate trades)

An include file that makes the way an EA sends its orders safe: the same signal is never traded twice. It has no trading strategy inside and comes with a small example EA.

StrictJson: RFC 8259 JSON parser and writer for MQL5 StrictJson: RFC 8259 JSON parser and writer for MQL5

One include file that reads and writes JSON in MQL5 and MQL4. It refuses broken JSON and tells you the line and column of the mistake, keeps numbers exact, reads and writes UTF-8 files, and saves your EA's settings to a file and loads them back.

Currency Strength Free MT5 - Eight Currency Scanner Currency Strength Free MT5 - Eight Currency Scanner

Free MT5 dashboard comparing eight major-currency strengths and ranking up to 28 FX pairs from completed candles. Includes broker-prefix/suffix detection, synchronization checks, chart navigation and eight output buffers. Independent MIT-licensed source; no trading operations.