TrendPine Script v6

BBTrend Pine Script — Complete TradingView Guide

BBTrend is a trend-momentum oscillator in Pine Script that measures the asymmetry between dual Bollinger Band pairs — one fast (20-period) and one slow (50-period) — to identify directional bias and trend strength. When the lower bands are wider apart than the upper bands, the histogram turns green (downward pressure); when the upper bands diverge more, it turns red (upward pressure). A zero-line crossover marks a potential trend reversal. Developed as an enhancement of John Bollinger's original 1983 band theory, BBTrend strips away price noise and presents pure volatility imbalance as a colour-coded histogram that any trader can read in seconds. It works across all asset classes — stocks, crypto, forex, and futures — on timeframes from 5-minute intraday charts to Daily and Weekly position-trading charts. This complete guide covers the full Pine Script v6 implementation, all configurable parameters, three proven trading strategies, and step-by-step instructions for generating a customised BBTrend script instantly with Pineify.

What Is the BBTrend Indicator?

The BBTrend indicator is a momentum oscillator that computes the asymmetry between two Bollinger Band pairs of different lengths, used to determine the prevailing trend direction and its strength as a percentage-normalised histogram. It was published by Alex (LazyBear) on TradingView in 2014, building on the Bollinger Band theory introduced by John Bollinger in 1983. LazyBear is one of the most-followed public script authors on TradingView, with thousands of indicators used by traders worldwide.

The core formula is:

BBTrend = (|short_lower − long_lower| − |short_upper − long_upper|) / short_middle × 100

Each variable in the formula has a precise meaning:

  • short_lower / short_upper: The lower and upper bands of the fast Bollinger Band (default length = 20), computed via ta.bb(source, 20, mult).
  • long_lower / long_upper: The lower and upper bands of the slow Bollinger Band (default length = 50), computed via ta.bb(source, 50, mult).
  • short_middle: The SMA of the fast Bollinger Band — used as the normalisation divisor to express the result as a percentage, making it comparable across different asset price levels.
  • mult: The standard-deviation multiplier applied to both bands (default 2.0), which controls band width.

When the lower bands are further apart than the upper bands (positive BBTrend), bearish volatility is dominating — price is being pushed downward. When the upper bands are further apart (negative BBTrend), bullish volatility is dominating. This directional interpretation is the opposite of what many traders expect at first glance, so reading the colour coding is essential.

BBTrend is applicable across all liquid asset classes: equities (stocks, ETFs), cryptocurrency (BTC, ETH, major altcoins), foreign exchange (EUR/USD, GBP/JPY, USD/JPY), and futures (ES, NQ, crude oil, gold). It performs best on 15-minute to Daily charts where there is sufficient volatility for the dual-band asymmetry to produce meaningful signals. On very short timeframes (1m, 3m), noise degrades signal quality unless lengths are reduced.

Best Markets

Stocks · Crypto · Forex · Futures

Best Timeframes

15m, 1H, 4H, Daily

Overlay

No — separate oscillator panel

BBTrend Pine Script Code

The Pine Script v6 code below implements the complete BBTrend oscillator — including the dual ta.bb() calculation and a four-state colour histogram. Copy the code, open the TradingView Pine Script editor (Alt+P), paste it in, and click Add to chart to see the BBTrend histogram in a separate panel below your price chart. You can change the short_bb_length and long_bb_length constants at the top of the script to adapt it to your preferred timeframe without modifying the formula logic.

Pine Script v6
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify

//@version=6
indicator(title="BBTrend", overlay=false, max_labels_count=500)

// BBTrend core function
// Compares the asymmetry between the short and long Bollinger Band lower vs upper distances
// Normalised by the short middle band × 100 to produce a percentage oscillator
p_ta_bbtrend(series float source, simple int short_bb_length, simple int long_bb_length, simple float mult) =>
    [short_middle, short_upper, short_lower] = ta.bb(source, short_bb_length, mult)
    [long_middle,  long_upper,  long_lower]  = ta.bb(source, long_bb_length,  mult)
    bbtrend = (math.abs(short_lower - long_lower) - math.abs(short_upper - long_upper)) / short_middle * 100
    bbtrend

// Calculate BBTrend: short length = 20, long length = 50, multiplier = 2
p_ind_1 = p_ta_bbtrend(close, 20, 50, 2)

// Dynamic histogram colouring
// Bright green: rising positive; dim green: falling positive
// Bright red: falling negative; dim red: rising negative
p_ind_1_hist_color = switch
    p_ind_1 > 0 and p_ind_1 >= p_ind_1[1] => color.rgb(8, 153, 129, 25)
    p_ind_1 > 0 and p_ind_1 <  p_ind_1[1] => color.rgb(8, 153, 129, 50)
    p_ind_1 < 0 and p_ind_1 >  p_ind_1[1] => color.rgb(242, 54, 69, 50)
    p_ind_1 < 0 and p_ind_1 <= p_ind_1[1] => color.rgb(242, 54, 69, 25)
    => color.rgb(8, 153, 129, 50)

plot(p_ind_1, "BBTrend", style = plot.style_columns, color = p_ind_1_hist_color)
hline(0, "BBTrend - Zero line")

Chart Preview

BBTrend indicator Pine Script code example in TradingView — dual Bollinger Band trend histogram

BBTrend Parameters

ParameterDefault ValueDescriptionRecommended Range
short_bb_length20Lookback period for the fast Bollinger Band. Smaller values make the indicator react faster to recent price changes. Used as the normalisation denominator (short_middle).10–30 (20 is standard)
long_bb_length50Lookback period for the slow Bollinger Band. Represents the broader trend context. The gap between short_bb_length and long_bb_length controls indicator sensitivity.40–100 (50 is standard; 100 for weekly charts)
mult2.0Standard-deviation multiplier applied equally to both Bollinger Band pairs. Higher values widen both bands, reducing the frequency of asymmetry signals.1.5–2.5 (2.0 is John Bollinger's default)
sourcecloseThe price series fed into both ta.bb() calls. Most traders use close; substituting hlc3 (typical price) smooths intrabar noise.close (standard) or hlc3

Tuning Guide by Trading Style

  • Scalping (5m charts): short_bb_length 10, long_bb_length 25, mult 2.0 — tighter lengths deliver faster zero-line crossovers
  • Day trading (15m–1H charts): short_bb_length 20, long_bb_length 50, mult 2.0 — standard LazyBear settings
  • Swing trading (4H–Daily charts): short_bb_length 20, long_bb_length 50, mult 2.0–2.5 — wider bands filter minor reversals
  • Position trading (Daily–Weekly): short_bb_length 20, long_bb_length 100, mult 2.1 — larger gap between lengths identifies major trend regimes

BBTrend Trading Strategies

BBTrend generates three categories of actionable signals: zero-line crossovers for trend reversals, histogram colour transitions for momentum acceleration, and divergence against price for exhaustion setups. Each strategy below uses numbered conditions for precise implementation in Pine Script or TradingView alert rules.

Strategy 1 — Zero-Line Crossover Trend Entry

Market environment: trending markets after consolidation · Best timeframe: 1H, 4H, Daily

A BBTrend zero-line crossover — from positive to negative — signals a shift from downward to upward volatility dominance. Pair with ta.ema(close, 200) to confirm the trade is in the primary trend direction.

  1. Calculate BBTrend with default parameters (20, 50, 2.0)
  2. Detect bullish cross: ta.crossunder(bbtrend, 0) (value crosses from positive to negative — bullish)
  3. Long entry filter: close is above EMA(200) on the same timeframe
  4. Long entry: open of the next bar after the crossunder
  5. Exit: BBTrend crosses back above zero OR close drops below EMA(200)

Strategy 2 — Colour Momentum Continuation

Market environment: established trends · Best timeframe: 15m, 1H

In a confirmed trend, BBTrend bars of increasing intensity (bright red falling further below zero) indicate accelerating bullish momentum — a "riding the histogram" continuation technique. Combine with ta.rsi(close, 14) to avoid overextended entries.

  1. Confirm bullish trend: BBTrend < 0 for at least 3 consecutive bars
  2. Long entry: BBTrend value is lower than the previous bar (histogram bar grows more negative) AND RSI(14) is between 45 and 65 (not overbought)
  3. Add to position on each subsequent intensifying bar
  4. Exit signal: BBTrend bar turns dim red (value is still negative but rising toward zero — momentum is fading)
  5. Stop loss: 1× ATR(14) below entry

Strategy 3 — BBTrend + Bollinger Bands Divergence Reversal

Market environment: trend exhaustion at key levels · Best timeframe: 4H, Daily

When price makes a new high or low but BBTrend fails to extend in the same direction, a divergence signals exhaustion before reversal. Pair with ta.bb(close, 20, 2) upper/lower band touches as the trigger point.

  1. Price makes a new 20-bar high AND touches the upper Bollinger Band
  2. Bearish divergence: BBTrend value is less negative than at the previous swing high (failing to confirm the price high)
  3. Short entry: next bar after divergence confirmation
  4. Target: the Bollinger Band middle SMA (mean-reversion target)
  5. Stop loss: above the recent price high by 0.5× ATR(14)

Disclaimer: The strategies above are for educational purposes only and do not constitute investment advice. Past performance does not guarantee future results. Always apply proper risk management and position sizing.

How to Generate BBTrend in Pineify

  1. 1

    Open Pineify

    Go to pineify.app and sign in — a free account gives full access to the AI Coding Agent. No credit card required.

  2. 2

    Click "New Indicator"

    Select "Indicator" as the script type from the creation menu. Pineify will open the AI coding workspace with a blank Pine Script v6 template.

  3. 3

    Describe your BBTrend setup

    Type a prompt such as: "Add a BBTrend oscillator using a 20-period fast Bollinger Band and a 50-period slow Bollinger Band with a 4-colour histogram showing trend direction and momentum strength."

  4. 4

    Copy the generated script to TradingView

    Click "Copy to TradingView" to copy the complete Pine Script v6 code, then paste it into the TradingView Pine Script editor (Alt+P) and click "Add to chart" to see the BBTrend histogram in a separate indicator panel.

  5. 5

    Adjust parameters in TradingView settings

    Open the indicator settings panel to change the short length (default 20), long length (default 50), and multiplier (default 2.0). Try lengths 10/25 for scalping on 5-minute charts or 20/100 for Daily swing trading.

Frequently Asked Questions

Build Your BBTrend Script in Seconds

Skip the manual coding. Pineify's AI Coding Agent generates complete, ready-to-use BBTrend Pine Script indicators — with custom lengths, colour logic, and alert conditions — instantly for free.

Try Pineify Free