Indicator · Pine Script v5 · Own pane

Breakout Bollinger Band and Keltner Channel

by hayashi19· code credited to HayashiHitsuji

This indicator turns Bollinger Bands, Keltner Channels or the average of both into a single normalised line in a separate pane, computed from Heikin Ashi close prices over a 200-bar window by default.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code68
Settings7inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago10 Jan 2022

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

68 lines of Pine Script v5 from indicator/INDICATOR Breakout Bollinger Band & Keltner Channel (林19).pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

INDICATOR Breakout Bollinger Band & Keltner Channel (林19).pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HayashiHitsuji

//@version=5
indicator("INDICATOR: Breakout Bollinger Band & Keltner Channel (林19)", shorttitle = "I BBKC (林19)", overlay = false)

////////////////////////////////////////////////////////////////////////////////
// INDICATOR INPUT /////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

// Input: indicator type value =================================================
band_type   = input.session('BB%B', "Band Type", options = ['BBKC', 'BB%B', 'KC%K'])

src = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)
band_period = input.int(200, "Band Value")
band_mult   = input.float(1.0, "Band Mult")

smooth      = input.bool(false, "Use smooth band?")
band_smooth = input.int(9, "Smooth Value")

upper_break = input.float(1.0, "Bullish Breakout")
lower_break = input.float(0.0, "Bearish Breakout")
// ========================================================================== //

////////////////////////////////////////////////////////////////////////////////
// INDICATOR CALCULATION & ALGORITHM ///////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

// Algo: set the bollinger band & keltner channel ==============================
[bb_mid, bb_upper, bb_lower] = ta.bb(src, band_period, band_mult)
[kc_mid, kc_upper, kc_lower] = ta.kc(src, band_period, band_mult)
// ========================================================================== //

// Calc: bb & kc calculation ===================================================
bbpb = smooth ? ta.ema((src - bb_lower) / (bb_upper - bb_lower), band_smooth) : 
         (src - bb_lower) / (bb_upper - bb_lower)
         
kcpk = smooth ? ta.ema((src - kc_lower) / (kc_upper - kc_lower), band_smooth) : 
         (src - kc_lower) / (kc_upper - kc_lower)
         
bbkc = smooth ? ta.ema((src - math.avg(bb_lower, kc_lower)) / (math.avg(bb_upper, kc_upper) - math.avg(bb_lower, kc_lower)), band_smooth) : 
         (src - math.avg(bb_lower, kc_lower)) / (math.avg(bb_upper, kc_upper) - math.avg(bb_lower, kc_lower))
         
band =  band_type == 'BBKC' ? bbkc : 
             band_type == 'BB%B' ? bbpb :
                 kcpk
// ========================================================================== //

// Algo: set color for inticator ===============================================
band_color  = band > upper_break ? color.lime : band < lower_break ? color.red : color.white
long        = ta.crossover(band, 0) ? color.lime : ta.crossover(band, 1) ? color.green : na
short       = ta.crossunder(band, 1) ? color.red : ta.crossunder(band, 0) ? color.maroon : na
// ========================================================================== //

////////////////////////////////////////////////////////////////////////////////
// PLOT INDICATOR //////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

// Plot: indicator and breakout line ===========================================
hline(upper_break, color = color.lime, linestyle = hline.style_solid, title = "Upper Breakout")
hline(lower_break, color = color.red, linestyle = hline.style_solid, title = "Lower Breakout")

hline(0.5, title = "Mid Breakout")

plot(band, color = band_color, linewidth = 2, title = "Band")
plot(1, color = long, style = plot.style_columns)
plot(1, color = short, style = plot.style_columns)
// ========================================================================== //

Overview

The line is coloured lime above a bullish breakout level, red below a bearish level and white between, with horizontal reference lines for the levels and midpoint. An option smooths the line with an EMA. The band type, period and multiplier are selectable.

Details

Published by

hayashi19 on GitHub

Code credit

HayashiHitsuji, as written in the script's header

Draws

Separate pane below the chart

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.

Settings

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

SettingTypeDefaultVariable
Band TypesessionBB%Bband_type
Band Valueint200band_period
Band Multfloat1.0band_mult
Use smooth band?boolfalsesmooth
Smooth Valueint9band_smooth
Bullish Breakoutfloat1.0upper_break
Bearish Breakoutfloat0.0lower_break
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

Chop and Explode

by capissimo
114 stars

This indicator measures market consolidation and breakout phases by computing a scaled Relative Strength Index (RSI) on normalized price data. It identifies chop zones when the RSI oscillates between 40 and 60, highlighting tight consolidation between 45 and 5

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of Chop and Explode

Squeeze Momentum

by mihakralj
99 stars

This indicator plots Squeeze Momentum in a separate pane. It compares Bollinger Bands with a Keltner Channel to mark a squeeze when the bands sit inside the channel. Momentum is a linear regression of price relative to a Donchian midline and an SMA, shown as a

Indicator v6 Volatility & bandsOscillators & momentum
Updated 4 weeks ago · Apache-2.0 GitHub repository of Squeeze Momentum

ATR Breakout

by TamaraKGreen
46 stars

This indicator plots the 100-bar percent rank of ATR in a separate pane and draws a midline at 50. It colors that midline green, red, or gray by comparing the close with the open a set number of bars earlier against a multiple of ATR across a lookback window.

Indicator v5 Volatility & bandsBreakout
Updated 7 weeks ago · None stated GitHub repository of ATR Breakout

Renko Acceleration

by f-cksociety
11 stars

Calculates the time elapsed between consecutive bars to measure market speed and volatility, designed primarily for Renko chart blocks where bar duration varies. In Momentum mode, it contrasts the current duration against a 100-period moving average baseline,

Indicator v4 Volatility & bandsOscillators & momentum
Updated 4 years ago · MPL-2.0 GitHub repository of Renko Acceleration

CRT + Turtle Soup Scanner

by alboogycOdR
6 stars

Calculates CRT session range boundaries and detects Turtle Soup setups to identify potential breakout signals. The script tracks session high, low, and midpoint values to determine intraday bias while measuring price break distances against ATR thresholds. It

Indicator v5 SMC / ICT / price actionSessions & time
Updated 7 months ago · None stated GitHub repository of CRT + Turtle Soup Scanner

EMA Breakout

by jerryinyang
5 stars

This indicator calculates and plots the exponential moving average on the chart, along with Keltner Channel bands. It applies optional filters based on Keltner Channel and Money Flow to identify breakout signals. Breakouts occur when price crosses the EMA with

Indicator v4 TrendMoving averages
Updated 2 years ago · None stated GitHub repository of EMA Breakout

More Volatility & bands scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers