Divergence Nexus TradingView Indicator

Written by Dominic Walsh · Published

Divergence Nexus is an divergence scanner indicator TradingView traders can run without stacking four panes on one chart. Also, it scans RSI, the MACD histogram, Stochastic %K and CCI against the same price pivots. Then it counts how many of the four agree. Indeed, a small label reads 2/4 or 4/4. A line joins the two pivots that formed the signal. Still, a corner dashboard tracks the latest reading per oscillator.

It is free and open source. Thus, you can add it to any chart from the Divergence Nexus script page on TradingView, and the full Pine source is published there for you to read.

What Divergence Nexus plots on the price chart

The script draws a line between the two pivots behind each divergence. Solid lines mark regular divergences. Dashed lines mark hidden ones. Hence, four colours separate the types: teal, red, blue and orange. A tiny label sits at the newer pivot and reads like R Bull 3/4, giving type, direction and confluence count. Next, diamonds print below or above the signal bar. The background tints faintly once confluence reaches your alert threshold. Then, a six-column dashboard lists RSI, MACD, STOCH and CCI with a status cell per row.

How Divergence Nexus is built

Step one: find pivots, then pair them

Everything starts with pivots. Yet, the script calls the standard pivot high and pivot low routine with a lookback of 5 bars on each side. It runs that routine twice per oscillator: once on price, once on the oscillator itself. Truly, a pivot only enters the record when both confirm on the same bar. So a price high needs the RSI to peak on that exact bar too.

That rule keeps the pairing clean, and it also explains most missed signals. Plainly, if the RSI turns one bar before the price high, nothing gets stored. Each oscillator keeps its own list of the last 10 highs and the last 10 lows. Also, older entries drop off the front.

The detector then compares only the two newest entries in a list. Indeed, it measures the gap between them in bars. That gap must sit between 5 and 100, set by Min Bars Between Pivots and Max Bars Between Pivots. Anything tighter counts as noise. Anything wider counts as unrelated.

Step two: four oscillators, one score

The four engines run with familiar defaults. RSI uses 14. The MACD histogram uses 12, 26 and 9. Stochastic %K uses 14. CCI uses 20 on the HLC3 average. Still, each one feeds the same comparison, so the code stays identical across the four.

The rules follow the textbook. On highs, a higher price high with a lower oscillator high gives a regular bearish divergence. A lower price high with a higher oscillator high gives a hidden bearish one. On lows the logic mirrors that. Two toggles let you switch regular or hidden detection off.

Each oscillator that fires on the same bar adds one point. Thus, that total becomes the confluence score out of four. It drives the label text, the alert gate and the background tint. Hence, min Confluence for Alert starts at 3. One quirk deserves a note: the label anchors to the pivot of whichever oscillator reported last on that bar, while the count covers all four.

How to read the signals

Read the score before the shape. Next, a 4/4 bullish label says RSI, MACD, Stochastic and CCI all pivoted with price and all disagreed with it in the same direction. A 1/4 label says one oscillator did. Then, both draw the same style of line, so the number carries the weight.

Line style tells you the intent. Yet, solid means regular, which points at a possible turn. Dashed means hidden, which points at continuation in the existing direction. Truly, a dashed teal line during a pullback in an uptrend argues the opposite case to a solid red line at a fresh high.

Mind the timing. Plainly, the pivot routine needs 5 bars to the right before it confirms anything. So a divergence line appears at least 5 bars after the pivot printed, and the diamond marks the bar that confirmed it, not the bar that turned. Also, plan entries around that delay rather than against it.

Every Divergence Nexus setting explained

The script exposes 27 inputs, grouped in the settings panel exactly as shown below. Defaults are the published values.

Oscillators

SettingWhat it doesDefaultRange
RSI LengthRSI lookback period142 to 50
MACD FastMACD fast EMA length122 to 50
MACD SlowMACD slow EMA length265 to 100
MACD SignalMACD signal line length92 to 50
Stochastic LengthStochastic %K lookback period142 to 50
CCI LengthCommodity Channel Index lookback period202 to 100
Enable RSIInclude RSI in divergence scanonon / off
Enable MACDInclude MACD histogram in divergence scanonon / off
Enable StochasticInclude Stochastic %K in divergence scanonon / off
Enable CCIInclude CCI in divergence scanonon / off

Detection

SettingWhat it doesDefaultRange
Pivot LookbackBars left/right for pivot detection. Higher = fewer but stronger pivots52 to 20
Min Bars Between PivotsMinimum distance between two pivots to form a valid divergence52 to 30
Max Bars Between PivotsMaximum distance between pivots. Beyond this a divergence is ignored10020 to 300
Detect Regular DivergencesRegular divergences signal potential trend reversalsonon / off
Detect Hidden DivergencesHidden divergences signal trend continuationonon / off

Display

SettingWhat it doesDefaultRange
Show Divergence LinesDraw divergence lines on the price chartonon / off
Show Divergence LabelsShow labels with divergence type and confluence scoreonon / off
Show DashboardDisplay the divergence status dashboardonon / off
Highlight High ConfluenceTint background when high-confluence divergence detectedonon / off
Table PositionDashboard position on charttop_righttop_left, top_center, top_right, bottom_left, bottom_center, bottom_right
Text SizeDashboard text sizesmalltiny, small, normal
Max DrawingsMaximum divergence lines and labels kept on chart5010 to 100

Colors

SettingWhat it doesDefaultRange
Regular BullishColor for regular bullish divergences (reversal up)#26A69A
Regular BearishColor for regular bearish divergences (reversal down)#EF5350
Hidden BullishColor for hidden bullish divergences (continuation up)#2196F3
Hidden BearishColor for hidden bearish divergences (continuation down)#FF9800

Alerts

SettingWhat it doesDefaultRange
Min Confluence for AlertMinimum oscillator agreement (out of 4) to trigger high-confluence alert31 to 4

Alerts built into Divergence Nexus

The script ships 6 alert conditions. Indeed, open the alert dialog on the chart, pick the indicator as the condition source, then choose the event you want. Alerts fire on the close of the bar, so they follow the same confirmed-bar rule the on-chart signals use.

  • Bullish Divergence
  • Bearish Divergence
  • High-Confluence Bullish
  • High-Confluence Bearish
  • Any Divergence
  • Any High-Confluence

Other markets and timeframes

The maths carries no currency assumption. Still, RSI and Stochastic stay bounded between 0 and 100. The MACD histogram and CCI scale with the instrument, yet the test only compares one pivot to another on the same series, so absolute size never matters. Thus, no volume enters the calculation, which removes the usual spot forex problem. Gold, indices, crypto and equities all run on the shipped defaults. Hence, pivot Lookback is the one input worth adjusting, since fast intraday charts throw more pivots than a daily chart.

Limitations worth knowing

This flags disagreement between price and momentum. Next, it does not rank trend, structure or location. A 4/4 bearish label inside a strong uptrend still just means four oscillators lagged the price high. Then, the script carries no stop logic, no target logic and no position sizing.

The same-bar pivot rule costs you signals. Yet, price and the oscillator must pivot on the identical bar, and each pivot needs 5 clean bars on both sides. Divergences that a human eye picks out often fail one of those tests. Truly, the detector also compares only the two most recent pivots, so a three-push divergence gets read as two separate pairs.

There is no higher timeframe view. Plainly, the script calls no external timeframe data, so every reading belongs to the chart you have open. Confluence also measures agreement, not conviction: four weak oscillator turns score the same 4/4 as four decisive ones.

Get Divergence Nexus on TradingView

Open Divergence Nexus on TradingView

If you also trade MetaTrader, the MT4 and MT5 indicator library is available below.

Get the complete indicator library

One email unlocks the full MT4 and MT5 indicator library. Also, this TradingView script stays free on TradingView – the button above adds it to your chart.

Using it alongside MetaTrader

Adding a script on TradingView takes one click, so there is no install step here. Indeed, if you want the same idea on MetaTrader, the MT4 and MT5 indicator installation guide walks through copying files into the data folder and attaching them to a chart. You can also browse the full MetaTrader indicator library, the MT4 indicators section, or the other free TradingView scripts published on this profile. For related chart tools see the MT5 indicators section and the forex trading strategies guides.

External references

Frequently asked questions

Does Divergence Nexus repaint?

The signal flags sit inside a barstate.isconfirmed block, so the diamond, the label and the alert land on a closed bar and stay there. Still, the lines reach back in time by design, because a pivot needs 5 bars on its right side to confirm. Call that lag rather than repainting.

What does the number in the label mean?

It counts how many of the four oscillators reported a divergence on that same bar, out of four. Thus, RSI, MACD histogram, Stochastic %K and CCI each contribute one point. The alert threshold uses the same count and starts at 3.

What is the difference between regular and hidden?

Regular divergence pairs a new price extreme with a weaker oscillator extreme, which argues for a turn. Hence, hidden divergence pairs a shallower price extreme with a stronger oscillator extreme, which argues for continuation. Solid lines show regular. Dashed lines show hidden.

Why did an obvious divergence produce nothing?

Check the pivot rules first. Next, the price pivot and the oscillator pivot must confirm on the same bar. Both need 5 bars either side. Then, the two pivots must sit 5 to 100 bars apart. And only the newest two pivots in each list get compared.

How much should I rely on this indicator?

Treat it as one input, not a decision. Yet, it is a chart analysis tool, not trading advice. Test it on your own markets and timeframes before relying on it. Results are not guaranteed; past performance is not indicative of future results.

Dominic Walsh - Forex trader and MT4/MT5 developer

About the author

Written by Dominic Walsh, a Forex trader and MT4/MT5 indicator, Expert Advisor and script developer. Every tool on forexmt4systems.com is tested on live charts before release and ships with ready-to-use compiled MT4 (.ex4) and MT5 (.ex5) files. Learn more about the trader and developer behind this site.

How we build, test and correct every tool: Editorial & Testing Policy. Trading carries risk; see the disclaimer.

Leave a Comment