Strategy · Pine Script v6 · On the chart

Mean Reversion Bollinger

by pineforge-4pass· code credited to PineForge contributors 2026

This strategy combines Bollinger Bands and the Relative Strength Index (RSI) to execute mean-reversion trades directly on the main price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code41
Settings5inputs
LicenceApache-2.0
Last update7 days ago23 Oct 2026

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

41 lines of Pine Script v6 from validation/ta-bb-rsi-mean-reversion-01/strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

strategy.pine
// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// PF probe 16 — Bollinger mean-reversion with RSI confirm
// Purpose: parity test for combined ta.bb() boundary breach + ta.rsi() OB/OS
// confirmation entry.
//
//@version=6
strategy("Mean Reversion Bollinger", overlay=true, initial_capital=1000000, process_orders_on_close=false, pyramiding=1, commission_type=strategy.commission.percent, commission_value=0, slippage=0, default_qty_type=strategy.fixed, default_qty_value=1)

// === Inputs ===
bbLen  = input.int(20, "BB Length", minval=5)
bbMult = input.float(2.0, "BB Multiplier", step=0.1)
rsiLen = input.int(14, "RSI Length", minval=1)
rsiOB  = input.int(70, "RSI Overbought")
rsiOS  = input.int(30, "RSI Oversold")

// === Indicators ===
[bbMid, bbUpper, bbLower] = ta.bb(close, bbLen, bbMult)
rsiVal = ta.rsi(close, rsiLen)

// === Mean reversion: price at extremes + RSI confirmation ===
longCond  = close < bbLower and rsiVal < rsiOS
shortCond = close > bbUpper and rsiVal > rsiOB

// === Strategy ===
if longCond
    strategy.entry("Long", strategy.long)
if shortCond
    strategy.entry("Short", strategy.short)

// === Exit at midline ===
if strategy.position_size > 0 and close > bbMid
    strategy.close("Long")
if strategy.position_size < 0 and close < bbMid
    strategy.close("Short")

plot(bbUpper, "Upper", color=color.red)
plot(bbMid, "Mid", color=color.gray)
plot(bbLower, "Lower", color=color.green)

Overview

Mean Reversion Bollinger opens long positions when price drops below the lower band with an oversold RSI reading, and opens short positions when price exceeds the upper band with an overbought RSI reading. Trades are closed when price returns to the Bollinger Band midline. Users can adjust the band length, multiplier, RSI period, and overbought/oversold levels. The strategy relies solely on midline exits and does not include a stop loss.

Details

Published by

pineforge-4pass on GitHub

Code credit

PineForge contributors 2026, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingbacktestingparitypine-scriptpinescriptquantitative-financetest-corpustradingview

Settings

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

SettingTypeDefaultVariable
BB Lengthint20bbLen
BB Multiplierfloat2.0bbMult
RSI Lengthint14rsiLen
RSI Overboughtint70rsiOB
RSI Oversoldint30rsiOS
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

Alert BB + RSI [Alorse] is a multi-symbol mean-reversion strategy designed for cryptocurrency trading. It evaluates Bollinger Bands and the Relative Strength Index (RSI) across up to 20 user-defined ticker symbols simultaneously. The strategy enters long posit

Strategy v4 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of Alert BB + RSI [Alorse]
106 stars

A multi-timeframe Dollar Cost Averaging (DCA) trading strategy that combines signals from three RSI indicators, three CCI indicators, and Bollinger Bands. It places up to five weighted scale-in safety orders to lower the average entry price. The script offers

Strategy v5 Oscillators & momentumVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of 3RSI 3CCI BB 5orders DCA Strategy+
104 stars

This strategy combines Bollinger Bands with a short RSI to fade moves that leave the bands and then return. A long requires the prior bar below the lower band and oversold, then a close back inside the band while RSI is between 30 and 50. Shorts mirror that at

Strategy v5 Oscillators & momentumVolatility & bands
Updated 3 years ago · MIT GitHub repository of Bollinger Bands and RSI Strategy

Greeffer RSI Strategy

by SammyEnigma
18 stars

Greeffer RSI Strategy is a trading strategy that generates buy and sell entries based on Bollinger Bands and RSI levels. It places stop orders at upper and lower Bollinger Bands on band crossovers, and adds positions when RSI reaches extreme levels. Users can

Strategy v4 Oscillators & momentumVolatility & bands
Updated 6 years ago · None stated GitHub repository of Greeffer RSI Strategy
13 stars

This strategy overlays the price chart to trade DAX futures during European market hours. It calculates exponential and simple moving averages, RSI, MACD, Bollinger Bands, ATR, and realized volatility to simulate VIX levels. Trades execute when session time fi

Strategy v5 Sessions & timeOscillators & momentum
Updated 8 months ago · Custom licence GitHub repository of ClaudeHedge - DAX Session Strategy
7 stars

This strategy plots a simple moving average basis and upper and lower Bollinger bands on the price chart, with a fill between the bands. It also calculates RSI. It opens one long trade when RSI is above 25, price is at or below the lower band, and no position

Strategy v5 Volatility & bandsOscillators & momentum
Updated 4 years ago · GPL-3.0 GitHub repository of Bollinger Bands Strategy

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers