Strategy · Pine Script v4 · On the chart

BB RSI Strategy

by infinityhao

BB RSI Strategy combines Bollinger Bands, RSI, and multiple simple moving averages directly on the main price chart.

View on GitHub

Repaints

GitHub stars3on the repository
Pine versionv4older, still runs
Lines of code56
Settings6inputs
LicenceNone statedfile: MPL-2.0
Last update5 years ago25 Mar 2021

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

56 lines of Pine Script v4 from BB RSI Strategy.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

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

//@version=4
strategy("BB RSI Strategy", overlay=true, calc_on_every_tick = true, initial_capital = 18500,
     currency = currency.USD, commission_type = strategy.commission.cash_per_order, commission_value = 30)

// Input Section
length   = input(35, minval=1, title = "BB: SMA")
mult     = input(2.0, minval=0.001, maxval=50, title = "Standard Deviation")
rsiLength= input(21, minval=1, title = "RSI length")
shortRSI = input(70, minval=1, maxval=100, title = "Short RSI percent")
longRSI  = input(40, minval=1, maxval=100, title = "Long RSI percent")
MAVisible= input(true, title = "Moving Averages Visible")

// Bollinger Bands
basis = sma(close, length)
dev = mult * stdev(close, length)
upperBand = basis + dev
lowerBand = basis - dev

// Moving Averages
ma50 = sma(close,50)
ma100 = sma(close,100)
ma150 = sma(close,150)
ma200 = sma(close,200)

// RSI
strength = rsi(close, rsiLength)

p1 = plot(upperBand, color=color.gray)
p2 = plot(lowerBand, color=color.gray)
fill(p1, p2)
p3 = plot(MAVisible?ma50:na, color=color.red)
p4 = plot(MAVisible?ma100:na, color=color.blue)
p5 = plot(MAVisible?ma150:na, color=color.green)
p6 = plot(MAVisible?ma200:na, color=color.orange)

// Order Units
amount = 0.1 * (strategy.initial_capital + strategy.netprofit) - strategy.losstrades
qty = floor(amount / close)

// Strategy Section
longCondition = close < lowerBand and strength < longRSI
shortCondition = close > upperBand and strength > shortRSI

// Order Execution Section
if (longCondition)
    strategy.order("Long", strategy.long, qty, when=strategy.position_size < qty * 5)

if (shortCondition)
    strategy.order("Short", strategy.short, qty, when=strategy.position_size > 0)

// Create alert conditions
alertcondition(longCondition and (strategy.long == true), message="BB RSI Strategy @ {{close}}")
alertcondition(shortCondition and (strategy.short == true),  message="BB RSI Strategy @ {{close}}")

Overview

BB RSI Strategy enters long positions when price drops below the lower Bollinger Band while RSI is below a set limit, and enters short positions when price exceeds the upper band while RSI is high. Position size is dynamically calculated from account equity and past losing trades. Settings control band length, standard deviation, RSI period, and visibility of four SMAs. Note that it calculates on every tick and lacks explicit stop-loss or take-profit exit rules.

Details

Published by

infinityhao on GitHub

Type

Strategy, Pine Script v4

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy can add several entries in the same direction
  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
BB: SMAint35length
Standard Deviationfloat2.0mult
RSI lengthint21rsiLength
Short RSI percentint70shortRSI
Long RSI percentint40longRSI
Moving Averages VisiblebooltrueMAVisible
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

This mean-reversion strategy combines multi-timeframe exponential moving averages, Bollinger Bands, and the Relative Strength Index. It generates long and optional short trade signals when price interacts with the Bollinger Bands alongside RSI threshold confir

Strategy v5 Mean reversionMoving averages
Updated 2 months ago · None stated GitHub repository of MEMA + BB + RSI [Alorse]
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

Simpleton GROK

by eltonaguiar
4 stars

This strategy plots on the price chart and combines up to seven optional modules that vote for long or short conditions. The modules use a 20-period simple moving average, a five-period RSI, Bollinger Band squeezes, a simplified prior-bar break, stacked expone

Strategy v5 Oscillators & momentumMoving averages
Updated 2 days ago · None stated GitHub repository of Simpleton GROK

Mean Reversion Trading Bot

by BenjaminLettner
1 stars

This strategy executes mean-reversion trades by combining RSI momentum, Bollinger Bands volatility, dynamic ATR stops, and Exponential Moving Averages for trend filtering. It seeks entry opportunities when price reaches extreme Bollinger Band boundaries alongs

Strategy v5 Mean reversionOscillators & momentum
Updated 8 months ago · None stated GitHub repository of Mean Reversion Trading Bot
1 stars

Calculates a reversal confidence score combining Bollinger Band overextension, RSI exhaustion, and price distance from a exponential moving average. The strategy overlays VWAP, EMA, and Bollinger Bands directly on the price chart. Long signals trigger when pri

Strategy v5 Mean reversionOscillators & momentum
Updated 9 months ago · None stated GitHub repository of Reversal Confidence Strategy
1 stars

This strategy plots an anchored volume-weighted average price and two standard-deviation bands on the price chart. It buys dips below the inner band when a short RSI is oversold and an optional EMA trend filter agrees, and it can sell rallies above the inner b

Strategy v6 Mean reversionMoving averages
Updated 3 months ago · MIT GitHub repository of VWAP Reversion Bands [QuantForge]

More Volatility & bands 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