Strategy · Pine Script v6 · On the chart

Stella's Bollinger Bands

by stella-entry· code credited to Stella

This strategy plots Bollinger Bands on the price chart and trades a long-only mean-reversion idea.

View on GitHub

GitHub stars3on the repository
Pine versionv6current
Lines of code107
Settings6inputs
LicenceMIT
Last update8 months ago22 Feb 2026

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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

107 lines of Pine Script v6 from strategies/bollinger-bands.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

bollinger-bands.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Stella

//@version=6
strategy("Stella's Bollinger Bands", 
         overlay=true, 
         default_qty_type=strategy.percent_of_equity, 
         default_qty_value=10,
         initial_capital=1000,
         commission_type=strategy.commission.percent,
         commission_value=0.1)

// ============================================
// Bollinger Bands Mean Reversion Strategy
// ボリンジャーバンド平均回帰戦略
// ============================================
// 
// 【English】
// Mean reversion strategy trading off band touches.
// - Long: Price touches or closes below lower band
// - Exit Long: Price touches or closes above upper band
// - Works best in ranging/sideways markets
//
// 【日本語】
// バンドタッチでの平均回帰戦略。
// - ロング: 価格が下部バンドにタッチまたは下抜け
// - 決済: 価格が上部バンドにタッチまたは上抜け
// - レンジ相場で最も効果的

// ----------------------------------------
// Inputs / 入力パラメータ
// ----------------------------------------
length = input.int(20, "BB Length / BB期間", minval=1)
mult = input.float(2.0, "BB Multiplier / BB乗数", minval=0.1, maxval=5.0)

// Entry mode / エントリーモード
entryMode = input.string("Close", "Entry Mode / エントリーモード", 
                          options=["Close", "Touch"])

// Stop Loss / 損切り
useStopLoss = input.bool(true, "Use Stop Loss / 損切り使用")
stopLossPercent = input.float(5.0, "Stop Loss % / 損切り%", minval=0.1, maxval=50)

// Take Profit at opposite band / 利確(対向バンド)
useBandExit = input.bool(true, "Exit at Opposite Band / 対向バンドで決済")

// ----------------------------------------
// Calculations / 計算
// ----------------------------------------

// Bollinger Bands / ボリンジャーバンド
[middle, upper, lower] = ta.bb(close, length, mult)

// Band width (for volatility filter) / バンド幅(ボラティリティフィルター用)
bbWidth = (upper - lower) / middle * 100

// ----------------------------------------
// Entry Conditions / エントリー条件
// ----------------------------------------

// Long conditions / ロング条件
if entryMode == "Close"
    longCondition = close < lower
else
    longCondition = low <= lower

// Exit conditions / 決済条件
if entryMode == "Close"
    exitCondition = close > upper
else
    exitCondition = high >= upper

// ----------------------------------------
// Execute Trades / 取引実行
// ----------------------------------------

// Long entry / ロングエントリー
if longCondition and strategy.position_size == 0
    strategy.entry("Long", strategy.long)

// Exit at upper band / 上部バンドで決済
if useBandExit and exitCondition and strategy.position_size > 0
    strategy.close("Long")

// Stop Loss / 損切り
if useStopLoss and strategy.position_size > 0
    strategy.exit("SL", "Long", stop=strategy.position_avg_price * (1 - stopLossPercent / 100))

// ----------------------------------------
// Plotting / プロット
// ----------------------------------------

// Bollinger Bands / ボリンジャーバンド
plot(middle, "BB Middle", color=color.blue, linewidth=1)
p1 = plot(upper, "BB Upper", color=color.green, linewidth=1)
p2 = plot(lower, "BB Lower", color=color.red, linewidth=1)

// Fill bands / バンド塗りつぶし
fill(p1, p2, color=color.new(color.blue, 90))

// Entry markers / エントリーマーカー
plotshape(longCondition and strategy.position_size == 0, "Long Signal", 
          shape.triangleup, location.belowbar, color.green, size=size.small)

// Band touch highlights / バンドタッチハイライト
bgcolor(low <= lower ? color.new(color.green, 80) : na, title="Lower Band Touch")
bgcolor(high >= upper ? color.new(color.red, 80) : na, title="Upper Band Touch")

Overview

Stella's Bollinger Bands enters when the close is below the lower band, or when the low touches that band if Touch mode is selected, and only while flat. With the opposite-band exit enabled, it closes the long when price reaches the upper band by the same close or touch rule. A percentage stop from the average entry price is on by default and can be turned off. Length, multiplier, entry mode, stop size, and the band exit are the main settings. It does not open short trades.

Details

Published by

stella-entry on GitHub

Code credit

Stella, as written in the script's header

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

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.

Settings

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

SettingTypeDefaultVariable
BB Length / BB期間int20length
BB Multiplier / BB乗数float2.0mult
Entry Mode / エントリーモードstringCloseentryMode
Use Stop Loss / 損切り使用booltrueuseStopLoss
Stop Loss % / 損切り%float5.0stopLossPercent
Exit at Opposite Band / 対向バンドで決済booltrueuseBandExit
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

330 stars

Alert BB + RSI [Alorse] is a multi-symbol mean-reversion strategy designed for cryptocurrency trading. It evaluates Bollinger Bands and the Relative Strength Index (RSI) across up to 20 user-defined ticker symbols simultaneously. The strategy enters long posit

Strategy v4 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of Alert BB + RSI [Alorse]
218 stars

The Mean Reversion Strategy Template calculates a baseline mean using SMA, EMA, or VWAP alongside upper and lower deviation bands based on standard deviation, ATR, or percentage offsets. It generates long and short entries when price touches, bounces from, or

Strategy v6 Mean reversionMoving averages
Updated 3 months ago · None stated GitHub repository of Mean Reversion Strategy Template
106 stars

This strategy backtests a long Bollinger Band deal on the price chart for 3Commas-style bots. It plots short and long simple moving averages, offset bands, and the average entry price of the open deal. A long starts when price crosses the lower band inside a c

Strategy v4 Volatility & bandsMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 3Commas Bollinger Strategy

Bollinger Bands Strategy

by cklose2000
105 stars

This strategy generates buy and sell signals based on Bollinger Band crossovers combined with a simple moving average trend filter. It enters a long position when price crosses above the lower band while trading above the SMA filter line, and enters a short po

Strategy v5 Volatility & bandsMoving averages
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Strategy
104 stars

This strategy combines Bollinger Bands with a short RSI to fade moves that leave the bands and then return. A long requires the prior bar below the lower band and oversold, then a close back inside the band while RSI is between 30 and 50. Shorts mirror that at

Strategy v5 Oscillators & momentumVolatility & bands
Updated 3 years ago · MIT GitHub repository of Bollinger Bands and RSI Strategy
37 stars

This strategy plots Bollinger Bands on the price chart using a simple moving average and a multiple of standard deviation. It places a long stop entry when close crosses above the lower band and a short stop entry when close crosses below the upper band. Pendi

Strategy v5 Volatility & bandsMean reversion
Updated 3 years ago · MIT GitHub repository of Bollinger Bands Strategy directed

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers