Explainers / Divergence for Many Indicators v4 (Lones
Divergence for Many Indicators v4 (LonesomeTheBlue), explained from the source
Divergence for Many Indicators v4 is an open-source TradingView script by LonesomeTheBlue (about 30,000 boosts). It looks for places where price made a new low or high but an indicator did not, across ten indicators at once, and draws a line and a label. This page walks through what the published code does, what each setting changes, and where it fails. It does not say what price does after a label.
What it is looking for
A divergence here means: price at the latest bar is beyond a recent pivot, while an indicator is not beyond its own value at that pivot. The script calls the low-side version "positive" and the high-side version "negative". Those are its labels, not a forecast.
Step 1: pivots
It finds pivot highs and lows with the Pivot Period setting (default 5, on Close). A pivot is only known 5 bars after it happens, so nothing is checked against a pivot in real time. It keeps the last 20 and checks the newest 10, none older than 100 bars.
Step 2: ten indicators at fixed lengths
MACD, MACD histogram, RSI 14, Stochastic 14/3, CCI 10, Momentum 10, OBV, a volume-weighted MACD, Chaikin Money Flow 21 and MFI 14. You can switch each on or off, and add one external series; you cannot change their lengths.
Step 3: the comparison and the straight-line test
For each indicator it compares the previous bar with a stored pivot: price beyond the pivot, indicator not. Then it draws an imaginary straight line from each point back to the pivot for price and for the indicator, and rejects the pair if any bar in between crosses either line. The Hidden option reverses the comparison.
Step 4: counting and the label
Each indicator that passes counts as one. The label shows their names and the count. Minimum Number of Divergence (default 1) sets how many must agree before anything is drawn. At 1, a single indicator out of ten is enough.
What the settings change (synthetic prices, seeds 1-3)
On random prices with no structure, the defaults drew a label on about 10 of every 100 bars. Minimum 3 cut that to about 4 per 100. Period 3 raised it to about 13; period 10 lowered it to about 6. "Don't Wait for Confirmation" raised it to about 16. When a label appeared, 2 to 3 indicators agreed on average. These are counts on made-up prices; they show how often the test fires, not whether a label means anything.
The alerts
Six alert conditions: positive, negative, positive hidden, negative hidden, any positive and any negative. They fire when the test above passes, nothing more.
Where it fails
- It fires on noise. On random prices the defaults still drew a label about one bar in ten, so a label alone is not evidence of anything.
- Ten indicators are not ten opinions. Most are built from the same closing prices, so they tend to move together; agreement between them counts the same information more than once.
- The default needs only one. Minimum Number of Divergence is 1, so a single indicator draws a label.
- Late by design. Pivots are known 5 bars after the fact, so a label always refers to a turn that has already happened.
- Live-bar flicker. The gate reads the current bar's close, so on an open bar a label can appear and disappear before the bar closes.
- Lines drawn back in time. Divergence lines run from an old pivot to the latest bar, and the pivot markers sit 5 bars back, which flatters how a chart looks in hindsight.
- Fixed lengths. The ten indicators use fixed lengths for every market and timeframe.
- Version 4 code. Written in Pine v4 (2020); it runs but is not the current language.
Also explained: Pivot Point SuperTrend · RSI · Pivot Points High Low · UT Bot Alerts · Repainting
Educational only. Not financial advice. Nothing here is a recommendation to buy or sell anything. Divergence for Many Indicators v4 is by LonesomeTheBlue on TradingView, published under the Mozilla Public License 2.0; this page explains its published open-source code and is not affiliated with the author. Simulation figures come from synthetic random-walk prices and say nothing about how the script trades.
Also explained: Repaint checker, VWAP, Supertrend, RSI, UT Bot Alerts, Nadaraya-Watson Envelope, Squeeze Momentum, What is repainting on TradingView?, Is TradingView backtesting accurate?, Chandelier Exit, WaveTrend Oscillator, QQE MOD, Pivot highs and lows, Hull Suite, Range Filter, Twin Range Filter, HalfTrend, ZigZag++, SSL Hybrid, CM MacD Ultimate MTF, Volume Profile / Fixed Range, ADX and DI, Support Resistance Channels, Market Structure Break & Order Block, Order Block Finder, Pivot Point SuperTrend, Trendlines with Breaks [LuxAlgo], TradingView script selling terms, Support and Resistance Levels with Break, Liquidity Swings [LuxAlgo], Pine Script errors, Breakout Probability (Expo), Did ChatGPT or Claude write your Pine Sc, Lorentzian Classification, SuperTrend AI (Clustering), Machine Learning Adaptive SuperTrend, Dynamic Swing Anchored VWAP, Support and Resistance Power Channel by , Support and Resistance (High Volume Boxe, Trendline Breakouts With Targets by Char, Breakout Finder by LonesomeTheBlue
No TradingView account yet? This affiliate link gives you a $15 coupon toward a paid plan, and we earn a commission if you buy one. The free plan is enough to follow this page.