Bollinger Bands Strategy with Intraday Intensity Index.pine
//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Bollinger Bands Strategy with Intraday Intensity Index
// by SparkyFlary
//For Educational Purposes
//Results can differ on different markets and can fail at any time. Profit is not guaranteed.
strategy(title="Bollinger Bands Strategy with Intraday Intensity Index", shorttitle="Bollinger Bands Strategy", overlay=true)
BBlength = input(20, title="Bollinger Bands length")
BBtype = input("EMA", title="Bollinger Bands and Standard deviation type", type=input.string, options=["EMA", "SMA"])
BBprice = input(close, title="source")
timeStop = input(20, title="Time-based stop length")
BBmult = input(2.0, title="Bollinger Bands Standard Deviation")
withIII = input(false, title="with Intraday Intensity Index?")
IIIlength = input(21, title="Intraday Intensity Index length")
positionMode = input("Both long and short", options=["Both long and short", "Long only", "Short only"])
earlyExit = input(false)
//function for choosing moving averages
f_ma(type_, src_, len_) =>
float result = 0
if type_ == "SMA"
result := sma(src_, len_)
if type_ == "EMA"
result := ema(src_, len_)
result
//Intraday Intensity Index
k1 = (2 * close - high - low) * volume
k2 = high != low ? high - low : 1
i = k1 / k2
iSum = sum(i, IIIlength)
//standard deviation with exponential option
StdDev_(type_, src_, len_) =>
mean = 0.0
sumSqr = 0.0
variance = 0.0
if len_ > 0
mean := f_ma( type_, src_, len_ )
sumSqr := 0
for counter = 0 to len_ - 1
sumSqr := sumSqr + pow( src_[counter] - mean, 2 )
variance := sumSqr / len_
stdDev = sqrt( variance )
else
stdDev = -1
//Bollinger Bands
BBdev = BBmult * StdDev_(BBtype, BBprice, BBlength)
BBbasis = f_ma(BBtype, BBprice, BBlength)
BBupper = BBbasis + BBdev
BBlower = BBbasis - BBdev
plot(BBupper, title="Bollinger Bands Upper Line")
plot(BBlower, title="Bollinger Bands Lower Line")
plot(BBbasis, title="Bollinger Bands Mid line", color=color.maroon)
//Strategy
buy = close[1]<BBlower[1] and close>BBlower and (withIII ? iSum>0 : 1)
sell = close>BBbasis or (earlyExit?strategy.openprofit>0:0) or barssince(buy)>timeStop
short = close[1]>BBupper[1] and close<BBupper and (withIII ? iSum<0 : 1)
cover = close<BBbasis or (earlyExit?strategy.openprofit>0:0) or barssince(short)>timeStop
if positionMode=="Long only"
strategy.entry(id="enter long", long=true, when=buy)
strategy.close(id="enter long", comment="exit long", when=sell)
else if positionMode=="Short only"
strategy.entry(id="enter short", long=false, when=short)
strategy.close(id="enter short", comment="exit short", when=cover)
else
strategy.entry(id="enter long", long=true, when=buy)
strategy.close(id="enter long", comment="exit long", when=sell)
strategy.entry(id="enter short", long=false, when=short)
strategy.close(id="enter short", comment="exit short", when=cover)
Expand (78 lines)
Overview
Bollinger Bands Strategy with Intraday Intensity Index enters long when price crosses back above the lower band and short when price crosses back below the upper band. An optional Intraday Intensity Index, built from price range and volume, can require positive or negative intensity before entry. Exits close a long above the midline or a short below it, after a set number of bars, or immediately when open profit is positive if early exit is enabled. Direction can be long only, short only, or both. There is no price stop loss.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Bollinger Bands length
int
20
BBlength
Bollinger Bands and Standard deviation type
string
EMA
BBtype
source
source
close
BBprice
Time-based stop length
int
20
timeStop
Bollinger Bands Standard Deviation
float
2.0
BBmult
with Intraday Intensity Index?
bool
false
withIII
Intraday Intensity Index length
int
21
IIIlength
positionMode
string
Both long and short
positionMode
earlyExit
bool
false
earlyExit
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.
This strategy plots Bollinger Bands on the price chart with adjustable length, standard deviation, and offset. It defines buy and sell zones using candle size percentage and body size thresholds. Long positions enter when the lower zone is breached without con
This overlay strategy is built for ES futures on the one-minute chart. It plots a volume-weighted moving average of price opens and standard-deviation bands at Fibonacci ratios, plus a second longer volume-weighted average from a higher-timeframe open. Call an
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
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
This strategy executes trades based on price interactions with standard Bollinger Bands plotted on the price chart. It calculates a simple moving average basis line along with upper and lower standard deviation bands. Long entries are triggered when price cros
This strategy trades on the price chart using multiple indicators. It enters long positions when price dips meet conditions on Bollinger Bands 40 and 20, RSI, MFI, volume and other thresholds. It exits at custom ROI profit levels based on RSI or after timeout