Strategy · Pine Script v4 · On the chart

Bollinger band (band display 5σ)

by hasnocool

This strategy plots a 20-period simple moving average of the close and Bollinger bands from one through five standard deviations.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code41
Settings0inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

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

41 lines of Pine Script v4 from Bollinger band (band display 5σ).pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Bollinger band (band display 5σ).pine
//@version=4
strategy(title="Bollinger band (band display 5σ)", overlay=true)
//sma算出
pine_sma(x, y) =>
    sum = 0.0
    for i = 0 to y - 1
        sum := sum + x[i] / y
    sum
dev = stdev(close,20)
basis = pine_sma(close,20)
upper_1 = basis + dev
lower_1 = basis - dev
upper_2 = basis + dev * 2
lower_2 = basis - dev * 2
upper_3 = basis + dev * 3
lower_3 = basis - dev * 3
upper_4 = basis + dev * 4
lower_4 = basis - dev * 4
upper_5 = basis + dev * 5
lower_5 = basis - dev * 5
plot(basis, title='25MA線色', color=color.blue, linewidth=2,transp=100)
u1 = plot(upper_1, title='+1σ線色',transp=100)
l1 = plot(lower_1, title='-1σ線色',transp=100)
u2 = plot(upper_2, title='+2σ線色',transp=100)
l2 = plot(lower_2, title='-2σ線色',transp=100)
u3 = plot(upper_3, title='+3σ線色',transp=100, color=color.orange)
l3 = plot(lower_3, title='-3σ線色',transp=100, color=color.orange)
u4 = plot(upper_4, title='+4σ線色',transp=100, color=color.red)
l4 = plot(lower_4, title='-4σ線色',transp=100, color=color.red)
u5 = plot(upper_5, title='+5σ線色',transp=80, color=color.purple)
l5 = plot(lower_5, title='-5σ線色',transp=80,color=color.purple)
fill(u1,l1, title='±1σ帯域色',color=color.aqua, transp=80)
fill(u1,u2, title='+2σ帯域色',color=color.yellow, transp=80)
fill(l1,l2, title='-2σ帯域色',color=color.yellow, transp=80)
fill(u2,u3, title='+3σ帯域色',color=color.orange, transp=80)
fill(l2,l3, title='-3σ帯域色',color=color.orange, transp=80)
fill(u3,u4, title='+4σ帯域色',color=color.red, transp=80)
fill(l3,l4, title='-4σ帯域色',color=color.red, transp=80)
fill(u4,u5, title='+5σ帯域色',color=color.purple, transp=80)
fill(l4,l5, title='-5σ帯域色',color=color.purple, transp=80)
Expand (46 lines)

Overview

Bollinger band (band display 5σ) draws the basis and each upper and lower band on the price chart, then fills the zones between successive bands in different colors. The length and deviation multiples are fixed because no inputs are defined. The shown code contains no order entries, exits, or stop loss.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Volatility & bands

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

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

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]

This overlay strategy offers two selectable entry modes: a Bollinger squeeze on typical price and a simple moving-average cross. It filters trades by weekday, session, date range, and an optional news window, and can restrict direction or invert the side. Risk

Strategy v5 Volatility & bandsMoving averages
Updated today · None stated GitHub repository of Boilerplate Configurable Strategy [Yosiet]
257 stars

This overlay strategy targets one-minute ES futures and plots volume-weighted moving-average bands from the open, scaled by a standard-deviation multiple, plus a slower band from ten-minute opens. A higher-timeframe exponential moving average can filter trades

Strategy v6 Moving averagesVolatility & bands
Updated 6 weeks ago · None stated GitHub repository of ES - Futures 1M No Repaint

STRG-BBForce

by harryguiacorn
219 stars

STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions

Strategy v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of STRG-BBForce
218 stars

This strategy detects price breakouts above rolling highest highs or below lowest lows over a customizable lookback period. It includes optional volume spike and ATR volatility threshold filters, along with bar confirmation rules. Positions are taken upon conf

Strategy v6 BreakoutVolatility & bands
Updated 3 months ago · None stated GitHub repository of Breakout Strategy Template

Bollinger Breakout

by hackingthemarkets
189 stars

This price-chart strategy plots a simple moving average and upper and lower bands built from the standard deviation of close, scaled by separate offset inputs. It enters a fixed quantity long when close crosses above the upper band and a fixed quantity short w

Strategy v4 Volatility & bandsBreakout
Updated 3 years ago · None stated GitHub repository of Bollinger Breakout

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