Strategy · Pine Script v4 · On the chart

Bollinger Band Breakout

by hasnocool

Bollinger Band Breakout is a positional strategy combining Bollinger Bands with the Relative Strength Index (RSI).

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code32
Settings2inputs
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

32 lines of Pine Script v4 from Bollinger Band Breakout Positional Strategy- BN -15M.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Bollinger Band Breakout Positional Strategy- BN -15M.pine
//@version=4
strategy(title="Bollinger Band Breakout", shorttitle = "BB-Stoxguru",default_qty_type = strategy.percent_of_equity,default_qty_value = 100, overlay=true)
source = close
start = timestamp (2007, 1,1,0,0) 
end = timestamp (2021,11,05,0,0)
stop_level = (high[1]-low[1])
profit_level = (high[1]-low[1])
length = input(20, minval=1, title = "Period") //Length of the Bollinger Band 
mult = input(2, minval=0.001, maxval=50, title = "Standard Deviation") 
basis = sma(source, length)
dev = mult * stdev(source, length)
upper = basis + dev
lower = basis - dev
band=upper-lower
stop_loss=low-atr(14)
if time >= start 
// and time < end
    strategy.entry("Long", strategy.long, when = crossover(source, upper) and rsi(close,14)>=60 and rsi(close,14)<=70)
    // strategy.entry("Long", strategy.long, when = crossover(source, upper) and rsi(close,14)>60 and band<200)
    // strategy.exit("SL", "Long", stop=stop_loss)
    strategy.close(id="Long", when=crossunder(close, basis))
    strategy.entry("Short", strategy.short, when = crossunder(source, lower) and rsi(close,14)<=40 and rsi(close,14)>=35)
    strategy.close(id="Short", when=crossover(close, basis))
    // strategy.entry("Short", strategy.short, when = crossunder(source, lower) and rsi(close,14)<40 and band<200)
    // plot(upper-lower, color=color.purple,title= "DIFF",style=plot.style_linebr)
plot(basis, color=color.red,title= "SMA")
p1 = plot(upper, color=color.blue,title= "UB")
p2 = plot(lower, color=color.blue,title= "LB")
// fill(p1, p2)
BW = ((upper - lower)) / basis * 100
plot(BW, title="Bollinger bandwidth", color=color.red)
Expand (36 lines)

Overview

Bollinger Band Breakout opens long positions when price crosses above the upper Bollinger Band while 14-period RSI is between 60 and 70. Short entries trigger when price crosses below the lower band while RSI is between 35 and 40. Positions close when price crosses back over the middle basis SMA line. The strategy plots Bollinger Bands and bandwidth directly on the main price chart. Note that default hard stop loss rules are commented out in the code.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Volatility & bands, Oscillators & momentum, Trend, Moving averages

Markets

Indices

Timeframes

M15-H1

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
Periodint20length
Standard Deviationint2mult
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

Momentum Rider DAILY FINAL

by greenpeas007
58 stars

This strategy combines exponential moving averages (EMA 9, 21, 50), RSI, MACD, and Supertrend indicators to enter long positions. It triggers trades using six dynamic setups based on momentum breakouts, EMA crossovers, and pullbacks. Position sizing is compute

Strategy v6 TrendOscillators & momentum Repaints
Updated 4 months ago · Custom licence GitHub repository of Momentum Rider DAILY FINAL

CombinedBinHAndClucV6

by viktors1982
36 stars

CombinedBinHAndClucV6 is a trading strategy based on the popular BinHV45 and ClucMay72018 algorithms. It calculates dual Bollinger Bands, Exponential Moving Averages, Relative Strength Index, Average True Range, and volume metrics across primary and one-hour h

Strategy v4 Volatility & bandsOscillators & momentum Repaints
Updated 2 years ago · None stated GitHub repository of CombinedBinHAndClucV6

BB Swing

by benso87
24 stars

This strategy calculates Bollinger Bands, a configurable moving average slope, Stochastic RSI, ATR, and ADX directly on the price chart. It evaluates trend bias and momentum conditions to generate long and short swing entries using percent-of-equity sizing. Th

Strategy v5 Volatility & bandsOscillators & momentum
Updated 4 years ago · MPL-2.0 GitHub repository of BB Swing

This strategy trades long and short on the price chart using a multi-timeframe TradingLatino setup. It requires EMA 10 to cross or sit above or below EMA 55 on the one-hour, four-hour, and daily charts, together with a positive ADX slope, a directional monitor

Strategy v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ruckard ABCBitcoin TradingLatino A010

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