Strategy · Pine Script v5 · On the chart

Bollinger Bands Strategy

by akumidv

This strategy plots a simple moving average basis and upper and lower Bollinger bands on the price chart, with a fill between the bands.

View on GitHub

GitHub stars7on the repository
Pine versionv5runs as is
Lines of code37
Settings3inputs
LicenceGPL-3.0
Last update4 years ago8 Jun 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 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

37 lines of Pine Script v5 from 03_freqtrade/tradingview/naive_bb_pine_script.txt, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

naive_bb_pine_script.txt
//@version=5
strategy("Bollinger Bands Strategy", overlay=true)

length = input.int(20, 'Len SMA', minval=1)
rsiLength = input.int(14, 'Len RSI', minval=1)
mult = input.float(2.0, 'Mult', minval=0.001, maxval=50)
source = close
basis = ta.sma(source, length)

dev = mult * ta.stdev(source, length)
upper = basis + dev
lower = basis - dev
rsi = ta.rsi(source, rsiLength)


plot(basis, "Basis", color=#FF6D00)
p1 = plot(upper, "Upper", color=#2962FF)
p2 = plot(lower, "Lower", color=#2962FF)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))


isLong = rsi > 25 and source <= lower and strategy.position_size == 0
isExit = rsi > 70 and source > basis and strategy.position_size != 0
strategy.entry("BBandLE", strategy.long, when=isLong, comment="BBandLE")
strategy.close(id="BBandLE",  when=isExit, comment="BBandLE Exit")


// Another version
// if (ta.crossover(source, lower))
//     strategy.entry("BBandLE", strategy.long, stop=lower, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="BBandLE")
// else
//     strategy.cancel(id="BBandLE")
// if (ta.crossunder(source, upper)  && rsi > 70)
//     strategy.entry("BBandSE", strategy.short, stop=upper, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="BBandSE")
// else
//     strategy.cancel(id="BBandSE")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)

Overview

Bollinger Bands Strategy also calculates RSI. It opens one long trade when RSI is above 25, price is at or below the lower band, and no position is open. It closes that long when RSI is above 70 and price is above the basis. SMA length, RSI length, and band multiplier are adjustable. There is no stop loss and no short entry in the active rules.

Details

Published by

akumidv on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Volatility & bands, Oscillators & momentum, Mean reversion, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
Len SMAint20length
Len RSIint14rsiLength
Multfloat2.0mult
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

This mean-reversion strategy combines multi-timeframe exponential moving averages, Bollinger Bands, and the Relative Strength Index. It generates long and optional short trade signals when price interacts with the Bollinger Bands alongside RSI threshold confir

Strategy v5 Mean reversionMoving averages
Updated 2 months ago · None stated GitHub repository of MEMA + BB + RSI [Alorse]

Simpleton GROK

by eltonaguiar
4 stars

This strategy plots on the price chart and combines up to seven optional modules that vote for long or short conditions. The modules use a 20-period simple moving average, a five-period RSI, Bollinger Band squeezes, a simplified prior-bar break, stacked expone

Strategy v5 Oscillators & momentumMoving averages
Updated today · None stated GitHub repository of Simpleton GROK

BB RSI Strategy

by infinityhao
3 stars

BB RSI Strategy combines Bollinger Bands, RSI, and multiple simple moving averages directly on the main price chart. It enters long positions when price drops below the lower Bollinger Band while RSI is below a set limit, and enters short positions when price

Strategy v4 Volatility & bandsOscillators & momentum Repaints
Updated 5 years ago · None stated GitHub repository of BB RSI Strategy

Mean Reversion Trading Bot

by BenjaminLettner
1 stars

This strategy executes mean-reversion trades by combining RSI momentum, Bollinger Bands volatility, dynamic ATR stops, and Exponential Moving Averages for trend filtering. It seeks entry opportunities when price reaches extreme Bollinger Band boundaries alongs

Strategy v5 Mean reversionOscillators & momentum
Updated 8 months ago · None stated GitHub repository of Mean Reversion Trading Bot
1 stars

Calculates a reversal confidence score combining Bollinger Band overextension, RSI exhaustion, and price distance from a exponential moving average. The strategy overlays VWAP, EMA, and Bollinger Bands directly on the price chart. Long signals trigger when pri

Strategy v5 Mean reversionOscillators & momentum
Updated 9 months ago · None stated GitHub repository of Reversal Confidence Strategy
1 stars

This strategy plots an anchored volume-weighted average price and two standard-deviation bands on the price chart. It buys dips below the inner band when a short RSI is oversold and an optional EMA trend filter agrees, and it can sell rallies above the inner b

Strategy v6 Mean reversionMoving averages
Updated 3 months ago · MIT GitHub repository of VWAP Reversion Bands [QuantForge]

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