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 indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
24 lines of Pine Script v5 from strategies/ai-bollinger-bands.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.
ai-bollinger-bands.pine
// Source: TradingView Built-in Indicator (Bollinger Bands)
// Attribution: Standard Bollinger Bands implementation matching TradingView's built-in indicator
// Used as input for AI-powered strategy conversion
//@version=5
indicator("Bollinger Bands", overlay=true)
length = input.int(20, minval=1, title="Length")
src = input(close, title="Source")
mult = input.float(2.0, title="StdDev Multiplier")
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
plot(basis, color=color.blue, title="Basis")
p1 = plot(upper, color=color.green, title="Upper Band")
p2 = plot(lower, color=color.red, title="Lower Band")
fill(p1, p2, color=color.new(color.gray, 90), title="BB Fill")
Additional instructions:
- IMPORTANT: Buy when close is above upper band, Sell when close is below lower band. The AI often guesses the opposite (mean reversion). This is a TREND FOLLOWING breakout strategy, not mean reversion.
- The strategy enters/exits on the next candle open after the condition is met (standard Pine Script behavior).
Overview
Bollinger Bands calculates a simple moving average of the selected source as the basis, then places upper and lower bands a chosen number of standard deviations away from that average. A translucent fill marks the area between the bands. Length, price source, and the standard-deviation multiplier are user inputs. It does not generate buy or sell signals, entries, exits, or risk rules.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Length
int
20
length
Source
source
close
src
StdDev Multiplier
float
2.0
mult
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.
The Hampel Filter indicator identifies and filters out price outliers to smooth price data directly on the main chart. It calculates the rolling median and Median Absolute Deviation (MAD) of the chosen source series over a specified length. When a data point e
This overlay indicator plots a Supertrend from an ATR length and factor, four exponential moving averages, and a selectable VWAP or TWAP taken from a chosen timeframe on the price chart. It also shows MACD and stochastic with adjustable lengths, smoothing, ver
This indicator plots trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre
This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B
This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre
This indicator calculates an outlier-filtered moving average based on statistical filtering concepts. It stores close prices in a rolling array over a user-defined length, calculates the mean and standard deviation, and excludes values falling within a specifi