OPEN-SOURCE SCRIPT
Mis à jour

Dual Bollinger Trend Oscillator - BBTrend | TR

905
🎯 Overview
Dual Bollinger Trend Oscillator - BBTrend | TR is an innovative oscillator developed by Tiagorocha1989 that leverages two Bollinger Bands® with different periods and standard deviation multipliers to create a unique measure of trend strength and momentum. By comparing the relative positions of short‑term and long‑term bands, BBTrend captures the expansion or contraction of volatility in a way that highlights underlying trend dynamics. With dual display modes (histogram or line), a comprehensive moving average engine, and rich visual customization, this indicator helps traders identify trend direction, strength, and potential reversals with clarity.

🔧 How It Works
BBTrend is built upon two classic Bollinger Bands calculations applied to the same price source:

Short Bollinger Bands – length Short_Len_BB, multiplier Short_Mult_BB

Long Bollinger Bands – length Long_Len_BB, multiplier Long_Mult_BB

From these bands, the indicator computes the absolute differences between the lower bands (shortLo and longLo) and between the upper bands (shortUp and longUp). The core oscillator value is then:

text
BBTrend = (abs(shortLo - longLo) - abs(shortUp - longUp)) / shortMid * 100
where shortMid is the middle line of the short Bollinger Bands (used for normalisation). The result is a dimensionless oscillator that oscillates around zero:

BBTrend > 0 → The gap between lower bands exceeds the gap between upper bands, typically associated with bullish momentum.

BBTrend < 0 → The gap between upper bands exceeds the gap between lower bands, typically associated with bearish momentum.

The indicator can be displayed either as a histogram (default) or as a line. When shown as a histogram, four shades of the bullish/bearish colours indicate the strength of the trend based on whether the value is increasing or decreasing.

An optional moving average (MA_BB) of the BBTrend line can be added (enabled via showMA). Crossovers between BBTrend and this MA provide additional trading signals.

✨ Key Features
🔹 Dual Display Modes

Histogram Mode (default): Visualises BBTrend as coloured columns. The colour intensity reflects trend strength:

Dark shades → strong momentum (value increasing in the same direction)

Light shades → weakening momentum (value decreasing towards zero)

Line Mode: Plots BBTrend as a continuous line, coloured by its position relative to its moving average.

🔹 Customizable Bollinger Bands
Separate control over short and long Bollinger Bands:

Short BB Length (default 10) and Short StdDev (default 1.0)

Long BB Length (default 50) and Long StdDev (default 2.0)

Price Source (default Close)

🔹 Moving Average Engine
When enabled, the indicator plots a moving average of BBTrend with 12 selectable types:
EMA, SMA, RMA, WMA, VWMA, HMA, DEMA, TEMA, TRIMA, FRAMA, SWMA, T3
The T3 MA includes an adjustable T3 Factor for fine‑tuning smoothness.

🔹 Crossover Signals

Zero‑Line Crossovers: Triangles appear on the price chart when BBTrend crosses above or below zero (bullish/bearish signals).

MA Crossovers: When showMA is true, small circles mark crossovers between BBTrend and its moving average.

🔹 Comprehensive Visual Feedback

Color‑Coded Histogram/Line: Uses one of eight color themes (Classic, Modern, Robust, etc.) for bullish and bearish states.

Dynamic Zone Fills: Semi‑transparent fills between the BBTrend line and its moving average when line mode is active.

Background Shading: The chart background changes colour based on the prevailing bias (bullish/bearish).

Color‑Coded Candles: Bars reflect the current BBTrend bias (above/below zero in histogram mode, or above/below MA in line mode).

Live Value Display: Current BBTrend value shown in a floating label near the last bar.

Trend Table: Bullish/Bearish status displayed in a table on the chart.

🔹 Ready‑to‑Use Alerts
Built‑in alert conditions trigger LONG on bullish zero‑line crossovers and SHORT on bearish zero‑line crossovers, as well as for MA crossovers when enabled.

⚙️ Settings Summary
Setting Description Default
Color Choice Select from eight visual themes Classic
Show Histogram If true, display as histogram; if false, as a line true
Show Moving Average Display the moving average of BBTrend false
Price Source Source for Bollinger Bands calculations Close
Short BB Length Period for short Bollinger Bands 10
Long BB Length Period for long Bollinger Bands 50
Short StdDev Standard deviation multiplier for short bands 1.0
Long StdDev Standard deviation multiplier for long bands 2.0
Length MA Moving average period for BBTrend 14
Moving Average Type of moving average (12 options) EMA
T3 Factor Factor for T3 moving average (0–1) 0.7
📈 Practical Applications
🔹 Trend Direction Identification
The sign of BBTrend provides a clear directional bias:

Positive values → bullish trend

Negative values → bearish trend
The magnitude indicates trend strength, with larger absolute values reflecting stronger momentum.

🔹 Zero‑Line Crossovers
Crossovers above/below zero offer simple, intuitive signals:

Crossover above zero → bullish momentum strengthening, potential trend reversal up.

Crossunder below zero → bearish momentum strengthening, potential trend reversal down.
These are highlighted by triangle markers on the price chart.

🔹 Signal‑Line Crossovers (MA Mode)
When the moving average is enabled, crossovers between BBTrend and its MA provide filtered signals:

BBTrend crosses above its MA → bullish signal.

BBTrend crosses below its MA → bearish signal.
These signals help reduce whipsaws in choppy markets.

🔹 Trend Strength & Momentum
The histogram’s shading reveals momentum acceleration:

Darkening colours → increasing momentum in the current direction.

Lightening colours → momentum slowing, possible trend exhaustion or reversal.

🔹 Divergence Trading
Like many oscillators, BBTrend can form divergences with price:

Bullish Divergence: Price makes a lower low while BBTrend makes a higher low → potential upside reversal.

Bearish Divergence: Price makes a higher high while BBTrend makes a lower high → potential downside reversal.
Divergences are most significant when BBTrend is at extreme levels (far from zero).

🔹 Multiple Timeframe Analysis
Compare BBTrend readings across different timeframes: higher‑timeframe BBTrend defines the primary trend direction, while lower‑timeframe BBTrend can be used for entry timing.

🎯 Ideal For
✅ Bollinger Bands Enthusiasts looking for a novel way to compare short‑term and long‑term volatility.
✅ Trend Traders seeking a clear, visual representation of trend direction and strength.
✅ Momentum Traders wanting to measure acceleration and deceleration.
✅ Divergence Traders who rely on oscillator‑price divergences for reversals.
✅ Swing Traders capturing medium‑term trend shifts.
✅ System Developers needing a customisable, dual‑signal oscillator.
✅ Beginner Traders who appreciate straightforward signals and colour‑coded visuals.

📌 Key Takeaways
Dual Bollinger Concept: Combines short and long Bollinger Bands to create a unique momentum oscillator.

Dual Display Modes: Choose histogram (with strength shading) for quick visual assessment, or line mode with moving average for crossover‑based trading.

Normalised Scale: Values are normalised by the short middle band, making readings comparable across instruments and timeframes.

Extensive MA Options: 12 moving average types give complete control over signal smoothing.

Rich Visuals: Colour themes, intensity‑shaded histogram, candle colouring, and background fills provide immediate market context.

Divergence Capability: The oscillator’s unbounded nature makes it suitable for spotting regular and hidden divergences.

Alert‑Ready: Pre‑built alerts for both zero‑line and MA crossovers.

⚠️ Important Notes
BBTrend is an unbounded oscillator; its scale can vary depending on market volatility and the chosen Bollinger Bands parameters. The zero line remains the fixed reference.

The default parameters (short: 10/1.0, long: 50/2.0) are a starting point. Adjust them to match your trading style and instrument characteristics.

When using the moving average, the default length of 14 offers a balanced response; longer lengths smooth the line but increase lag.

Divergences should be confirmed with other technical tools and are most reliable after extended trends.

Always combine BBTrend with proper risk management and additional confirmation before live deployment.

Disclaimer: This indicator is provided for educational and informational purposes only. Past performance does not guarantee future results. Always test thoroughly and align with your personal risk management strategy.
Notes de version
Resolution Previous Problem
Notes de version
Resolution Previous Problem
Notes de version
Resolution Previous Problem
Notes de version
Color Mode – Added 'Heat' option ([#ff0000, #87cefb]).

Dynamic Fill Transparency – Calculates Momentum and Norm_Momentum to set a variable transparency (Fill_Transp) for the overbought/oversold fills, replacing the fixed 0/100 values.

Gradient Candle Colors – Computes a normalized and uses color.from_gradient() to color candles with a smooth transition between down and up colors.

Persistent Trend State – Introduces Trend_ (1 for bull, -1 for bear) that holds the trend direction, used in:

The third fill() (now based on Trend_ instead of a direct.

bgcolor() (now uses Trend_ instead of isBull_/isBear_).

The table and label (display and color based on Trend_).

Label Color – Simplified to use Trend_ colors without transparency.

Clause de non-responsabilité

Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.