Indicator · Pine Script v5 · Own pane

[CBB] Rising Falling Color Band

by codybbrown· code credited to bright_infinite

Calculates custom exponential moving averages and standard deviation envelopes based on price offsets and lookback windows.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code119
Settings11inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago11 Apr 2023

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

119 lines of Pine Script v5 from cbb-indicator-trend-bands-RisingFallingColorBand.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

cbb-indicator-trend-bands-RisingFallingColorBand.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © bright_infinite
// =============================================================================
// https://www.tradingview.com/pine-script-docs/en/v5/language/Arrays.html#using-an-array-as-a-stack
// =============================================================================
//@version=5
indicator("[CBB] Rising Falling Color Band", shorttitle="Rising Falling Color Band")
// -----------------------------------------------------------------------------
len                 = input.int(50, title="MA Length")
window              = input.int(3, title="Lookback Window")
vis_squeeze         = input.bool(true, title="Show Squeeze Color")
vis_squeeze_band    = input.bool(false, title="Show Squeeze Band")
vis_meanrev_zone    = input.bool(false, title="Show Mean Reversion Zone")
vis_trend_zones     = input.bool(false, title="Show Trend Zones")
inp_col_dark        = input.color(color.rgb(200,200,200,90), title="Channel Color (dark)")
inp_col_light       = input.color(color.rgb(0,0,0,0), title="Channel Color (light)")
inp_col_mode        = input.bool(true, title="Dark Mode")

// =============================================================================
//  MOVING AVS
// =============================================================================
ochl                = ta.ema(open-close[window] + hl2, len)
hlhl                = ta.ema(high-low[window]   + hl2, len)
hllc                = ta.ema(high-low[window]   + low-close + hl2, len)
hlhc                = ta.ema(high-low[window]   + high-close + hl2, len)
lchc                = ta.ema(low-close[window]  + high-close + ohlc4, len)

// Mean Envelope
ma1                 = hlhl
ma2                 = hllc
ma2a                = hlhc

col_blk             = inp_col_light
col_gray            = inp_col_dark
pl_ma1              = plot(ma1, color=col_gray)
pl_ma2              = plot(ma2, color=col_gray)
pl_ma20             = plot(vis_meanrev_zone ? ma2a : na, color=col_blk, linewidth=2)
pl_lchc             = plot(vis_meanrev_zone ? lchc : na, color=col_blk, linewidth=2)
fill(pl_ma20, pl_lchc, (inp_col_mode == true ? inp_col_dark : inp_col_light))

std_34              = input.float(2.5, title="Std Wide Env")
std_34a             = input.float(1.25, title="Std wide Env a")

// StDevs
std_ma3             = ta.ema(open-close[window]+hl2 + ta.stdev(open-close[window] + hl2, len) * std_34, len)
std_ma4             = ta.ema(open-close[window]+hl2 - ta.stdev(open-close[window] + hl2, len) * std_34, len)
std_ma3a            = ta.ema(open-close[window]+hl2 + ta.stdev(open-close[window] + hl2, len) * std_34a, len)
std_ma4a            = ta.ema(open-close[window]+hl2 - ta.stdev(open-close[window] + hl2, len) * std_34a, len)
std_ma5             = ochl + ta.stdev(ochl, len) * 2.5
std_ma6             = ochl - ta.stdev(ochl, len) * 2.5

color hiBand        = color.from_gradient(low, lchc, std_ma3, color.rgb(0,0,0,100), color.red)
color loBand        = color.from_gradient(high, std_ma4, lchc, color.red, color.rgb(0,0,0,100))

pl_ma3              = plot(vis_trend_zones ? std_ma3 : na, color=color.red)
pl_ma3a             = plot(vis_trend_zones ? std_ma3a : na, color=color.maroon)
pl_ma4              = plot(vis_trend_zones ? std_ma4 : na, color=color.red)
pl_ma4a             = plot(vis_trend_zones ? std_ma4a : na, color=color.maroon)
pl_ma5              = plot(vis_squeeze_band ? std_ma5 : na, color=color.black)
pl_ma6              = plot(vis_squeeze_band ? std_ma6 : na, color=color.black)

// Color outer trend bands according to distance from outer most moving av
fill(pl_ma3a, pl_ma3, hiBand)
fill(pl_ma4a, pl_ma4, loBand)

// Fill squeeze band
// fill(pl_ma3, pl_ma4, color.rgb(255,0,0,95))
// fill(pl_ma5, pl_ma6, color.rgb(0,0,0,90))

// Squeeze condition/color
cond_squeeze        = (std_ma5 < std_ma3a) and (std_ma6 > std_ma4a) and (high < std_ma5) and (low > std_ma6)
col_squeeze         = cond_squeeze ? color.rgb(255, 221, 72) : na
barcolor(vis_squeeze ? col_squeeze : na)



// =============================================================================
//  RISING/FALLING
// =============================================================================
rH                  = ta.rising(high, 5)
vw_rH               = ta.valuewhen(rH, high, 0)

fL                  = ta.falling(low, 5)
vw_fL               = ta.valuewhen(fL, low, 0)

// plot(vw_rH)
// plot(vw_fL, color=color.red)

// // -----------------------------------------------------------------------------
// var lows = array.new_float(0)
// flushLows = false

// // Remove last element from the stack when `_cond` is true.
// array_pop(id, cond) => cond and array.size(id) > 0 ? array.pop(id) : float(na)

// if ta.rising(high, 1)
//     // Rising highs; push a new low on the stack.
//     array.push(lows, low)
//     // Force the return type of this `if` block to be the same as that of the next block.
//     bool(na)
// else if array.size(lows) >= 4 or low < array.min(lows)
//     // We have at least 4 lows or price has breached the lowest low;
//     // sort lows and set flag indicating we will plot and flush the levels.
//     array.sort(lows, order.ascending)
//     flushLows := true

// // If needed, plot and flush lows.
// lowLevel = array_pop(lows, flushLows)
// plot(lowLevel, "Low 1", low > lowLevel ? color.silver : color.purple, 2, plot.style_linebr)
// lowLevel := array_pop(lows, flushLows)
// plot(lowLevel, "Low 2", low > lowLevel ? color.silver : color.purple, 3, plot.style_linebr)
// lowLevel := array_pop(lows, flushLows)
// plot(lowLevel, "Low 3", low > lowLevel ? color.silver : color.purple, 4, plot.style_linebr)
// lowLevel := array_pop(lows, flushLows)
// plot(lowLevel, "Low 4", low > lowLevel ? color.silver : color.purple, 5, plot.style_linebr)

// if flushLows
//     // Clear remaining levels after the last 4 have been plotted.
//     array.clear(lows)

Overview

[CBB] Rising Falling Color Band plots dynamic channel bands, mean reversion zones, and squeeze indicators in a separate pane. Users can adjust the moving average length, lookback window, standard deviation multipliers, and toggle visibilities for squeeze bands, mean reversion zones, and trend zones.

Details

Published by

codybbrown on GitHub

Code credit

bright_infinite, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Moving averages, Volatility & bands, Mean reversion

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

momentum-trading-strategypinescripttrading-strategiestradingviewvolatility-tradingtrading-indcators

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
MA Lengthint50len
Lookback Windowint3window
Show Squeeze Colorbooltruevis_squeeze
Show Squeeze Bandboolfalsevis_squeeze_band
Show Mean Reversion Zoneboolfalsevis_meanrev_zone
Show Trend Zonesboolfalsevis_trend_zones
Channel Color (dark)colorcolor.rgb(200,200,200,90)inp_col_dark
Channel Color (light)colorcolor.rgb(0,0,0,0)inp_col_light
Dark Modebooltrueinp_col_mode
Std Wide Envfloat2.5std_34
Std wide Env afloat1.25std_34a
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This indicator builds a channel from a Hull moving average of the source and an ATR scaled by a band multiplier, then normalizes price inside that channel into a 0 to 100 oscillator. It smooths the result with a weighted moving average and plots the line in a

Indicator v6 Mean reversionVolatility & bands
Updated 3 months ago · None stated GitHub repository of Radiant Mean Reversion Channels [Pineify]
3 stars

This indicator estimates how many bars typically pass before a custom skew measure falls back below its exponential moving average. It builds the skew from smoothed upside and downside true-range deviations, then applies five fixed EMA lengths from 2 to 110. O

Indicator v5 Mean reversionMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of Average Bars Before Reversion

This indicator plots trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [Alorse]

Kalman Percentile Bands

by NQ-stats-MX
15 stars

Kalman Percentile Bands plots a volatility-adaptive Kalman mean along with three empirical percentile bands on each side of the price chart. It calculates a local-level Kalman filter as the fair value mean, normalizes price deviations by an EWMA of volatility,

Indicator v6 Mean reversionVolatility & bands
Updated 2 weeks ago · MIT GitHub repository of Kalman Percentile Bands
6 stars

This indicator classifies price action into four distinct market regimes: Trend, Expansion, Compression, or Mean Reversion. It determines states using a simplified Hurst exponent estimate, ADX slope thresholds, and realized volatility measurements. Based on th

Indicator v6 TrendVolatility & bands
Updated 8 weeks ago · MIT GitHub repository of Capital41 Regime Matrix v3

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers