Indicator · Pine Script v4 · On the chart

RSI + MACD + BB

by krosenfeld7

This indicator combines the Relative Strength Index, Moving Average Convergence Divergence, and Bollinger Bands to identify setup signals during market consolidation.

View on GitHub

GitHub stars5on the repository
Pine versionv4older, still runs
Lines of code82
Settings11inputs
LicenceApache-2.0
Last update3 years ago12 May 2023

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 indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

82 lines of Pine Script v4 from RSI+MACD+BB/RSI+MACD+BB.txt, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

RSI+MACD+BB.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © krosenfeld7

//@version=4
study(title = "RSI + MACD + BB", shorttitle = "RSI + MACD + BB", overlay = true)

// RSI Section
len = input(14, minval = 1, title = "RSI Length")
src = input(close, "RSI Source", type = input.source)
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

// MACD Section
// Getting inputs
fast_length = input(title = "MACD Fast Length", type = input.integer, defval = 12)
slow_length = input(title = "MACD Slow Length", type = input.integer, defval = 26)
src2 = input(title = "MACD Source", type = input.source, defval = close)
signal_length = input(title = "Signal Smoothing", type = input.integer, minval = 1, maxval = 50, defval = 9)
sma_source = input(title = "Simple MA (Oscillator)", type = input.bool, defval = false)
sma_signal = input(title = "Simple MA (Signal Line)", type = input.bool, defval = false)
// Calculating
fast_ma = sma_source ? sma(src2, fast_length) : ema(src2, fast_length)
slow_ma = sma_source ? sma(src2, slow_length) : ema(src2, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal
value = (hist >= 0 ? (hist[1] < hist ? 1 : 3) : (hist[1] < hist ? 2 : 4))

// Bollinger Bands Section
bollinger_avg_len = 50
length = input(20, minval = 1)
src3 = input(close, title = "BB Source")
mult = input(2.0, minval = 0.001, maxval = 50, title = "BB StdDev")
basis = sma(src3, length)
dev = mult * stdev(src3, length)
upper = basis + dev
lower = basis - dev

band_width_avg = 0.0
for i = 0 to bollinger_avg_len
    band_width_avg += 2 * dev[i]

band_width_avg /= bollinger_avg_len
band_consolidating = band_width_avg > 2 * dev

// Bullish (Long)
// RSI goes overbought
// RSI pullback to below 50 line
// MACD goes into red value = 4
// Entry position at green candle and first tick up on MACD value = 2
// Sideways consolidation

cross70under = crossunder(rsi, 70)
cross50over = crossover(rsi, 50)
cross50under = crossunder(rsi, 50)

validLongRSI = barssince((cross50under and barssince(cross50over) > barssince(cross70under))) == 0
longRSI = (barssince(validLongRSI) < barssince(cross50over)) and (rsi < 50) and not cross50over
long = (close > open and value[1] == 4 and value == 2 and longRSI and band_consolidating) ? 1 : 0

// Bearish (Short)
// RSI goes oversold
// RSI pullback to above 50 line
// MACD goes into green value = 1
// Entry position at red candle and first tick down on MACD value = 3
// Sideways consolidation

cross30over = crossover(rsi, 30)

validShortRSI = barssince((cross50over and barssince(cross50under) > barssince(cross30over))) == 0
shortRSI = (barssince(validShortRSI) < barssince(cross50under)) and (rsi > 50) and not cross50under
short = (close < open and value[1] == 1 and value == 3 and shortRSI and band_consolidating) ? 1 : 0

if long
    label.new(x = bar_index, y = na, text = "Long", yloc = yloc.abovebar, color = color.green)
if short
    label.new(x = bar_index, y = na, text = "Short", yloc = yloc.abovebar, color = color.red)

// Alerts
alertcondition(long, title = "Long Signal", message = "Long @ {{timenow}}: {{ticker}} -> {{interval}}: {{close}}")
alertcondition(short, title = "Short Signal", message = "Short @ {{timenow}}: {{ticker}} -> {{interval}}: {{close}}")

Overview

A long signal requires an RSI pullback under 50 following overbought conditions, a MACD histogram upward turn, a bullish candle, and squeezed Bollinger Bands. Short signals look for an RSI pullback above 50 following oversold conditions, a MACD histogram downward turn, a bearish candle, and consolidation. Custom settings adjust lengths, sources, and standard deviations. Long and short labels plot directly on the price chart with alerts.

Details

Published by

krosenfeld7 on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

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

SettingTypeDefaultVariable
RSI Lengthint14len
RSI Sourcesourceclosesrc
MACD Fast Lengthint12fast_length
MACD Slow Lengthint26slow_length
MACD Sourcesourceclosesrc2
Signal Smoothingint9signal_length
Simple MA (Oscillator)boolfalsesma_source
Simple MA (Signal Line)boolfalsesma_signal
lengthint20length
BB Sourcesourceclosesrc3
BB StdDevfloat2.0mult
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

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

Indicator v5 Oscillators & momentumMoving averages
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup: Vijay Thakare Option Buying Scalping Setup

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

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [Alorse]

LiqSpikeBounceLong Feb2026

by agutinbaigo28
147 stars

LiqSpikeBounceLong Feb2026 is an indicator designed to identify long bounce entries following high-volume liquidation cascades in bearish market contexts. It checks if price is below an exponential moving average, then detects large single-bar drops exceeding

Indicator v5 Volatility & bandsVolume
Updated 6 weeks ago · MIT GitHub repository of LiqSpikeBounceLong Feb2026

8zz反指標v2

by hansai-art
121 stars

The 8zz Contrarian Indicator plots reverse sentiment trading signals directly on the price chart based on tracked retail post activity. It generates bullish signals during retail panic and bearish signals during market euphoria. The indicator features adjustab

Indicator v6 Moving averagesOscillators & momentum
Updated 3 months ago · None stated GitHub repository of 8zz反指標v2
114 stars

ADX Strategy (original) is an overlay indicator that identifies trend-following trade signals using the Average Directional Index (ADX) combined with a Simple Moving Average filter. A long signal is generated when the ADX rises above a user-defined trend level

Indicator v4 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Strategy (original)
56 stars

Double Screened Decision is a multi-timeframe trend and momentum indicator overlaid directly on the price chart. It dynamically selects a higher timeframe based on the active chart resolution to evaluate higher-timeframe MACD, Bollinger Bands, RSI, and Stochas

Indicator v5 TrendMoving averages Repaints
Updated 4 months ago · None stated GitHub repository of Double Screened Decision

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