1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
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
25 lines of Pine Script v4 from Bollinger Blast Buy Unholy Grail.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
Bollinger Blast Buy Unholy Grail.pine
//@version=4
// strategy "bollinger-band-trading-strategy" taken from bettersystemtrader.com
// Entry: Buy on the Open the day after a stock closes above the top Bollinger Band
// Exit: Exit on the Open the day after a stock closes below the lower Bollinger Band
// In Nicks book, he uses 100 period Bollinger Bands so we’ll do the same. The upper Bollinger Band will be 3 deviations from the central line, the lower Bollinger Band will be 1 deviation below the central line.
// money management added
strategy(title = "Bollinger Blast Buy Unholy Grail",calc_on_order_fills=false,calc_on_every_tick =false, initial_capital=20000,commission_value=.25,overlay = true,default_qty_type = strategy.cash, default_qty_value = 20000)
period=input(10, title="Bollinger period", minval = 5, step =5)
multipup=input(3, title="Boll multipler up", minval= 0.1)
multidown = input(1, title="Boll multipler up", minval= 0.1)
stop_loss=input(10, "Stop loss %", minval = 1, step = 1)
bollup = sma(close,period)+stdev(close,period)*multipup
bolldo = sma(close, period)-stdev(close,period)*multidown
//entry
entry = crossover(close,bollup)
strategy.entry("Long", true, when = entry)
exitup = crossunder(close,bolldo)
strategy.close("Long", when = exitup, comment ="cLOSE up")
sl = -1*stop_loss/100*strategy.initial_capital
close_Stop = strategy.openprofit < sl
strategy.close("Compra", when = close_Stop, comment= "Stop loss")
b1 = plot(bollup, title = "Boll+")
b2= plot(bolldo, title = "Boll-")
fill(b1, b2, color=color.purple)
Expand (25 lines)
Overview
The upper band is a simple moving average plus a larger standard-deviation multiple, and the lower band uses a smaller multiple. It enters long when close crosses above the upper band and closes that long when close crosses below the lower band. A percent stop input exists, but the stop closes a different order id than the entry, so it may not exit the position. Period and both multipliers are adjustable.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Bollinger period
int
10
period
Boll multipler up
int
3
multipup
Boll multipler up
int
1
multidown
Stop loss %
int
10
stop_loss
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.
Calculates standard Bollinger Bands and identifies band expansion breakouts where upper and lower bands move in opposite directions. It enters long positions when price breaks above the upper band with a high candle body percentage, and enters short positions
This strategy plots VWMA-based Bollinger bands on the 1-minute ES futures price chart for volatility analysis and potential breakout identification. It calculates dynamic long and short stop loss and take profit levels using percentage inputs relative to entry
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
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
This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the
This strategy plots exponential-moving-average Bollinger bands on the price chart and calculates RSI. It opens a long position when close crosses above the upper band while RSI is at or above a threshold, the date filter allows trading, and no position is open