Strategy · Pine Script v4 · Own pane

RSI/BB 1minute Study

by SammyEnigma· code credited to Greeffer

This strategy combines the Relative Strength Index with Bollinger Bands to generate mean-reversion entries.

View on GitHub

GitHub stars18on the repository
Pine versionv4older, still runs
Lines of code52
Settings3inputs
LicenceNone statedfile: MPL-2.0
Last update6 years ago15 Oct 2020

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

52 lines of Pine Script v4 from rsi-bb-1min-v0.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

rsi-bb-1min-v0.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Greeffer

//@version=4
strategy("RSI/BB 1minute Study", "BBW/RSI/1m", false, format=format.inherit, 
     scale=scale.right, precision=5, pyramiding=4, default_qty_type=strategy.cash,
     default_qty_value=20, initial_capital=1000, currency=currency.USD,
     commission_type=strategy.commission.percent, commission_value=0.075,
     process_orders_on_close=false, calc_on_every_tick=false)

// R S I
source = close
sell = input(title="Sell", defval=75, minval=0, maxval=100)
buy = input(title="Buy", defval=34, minval=0, maxval=100)
length = input(title="Length", defval=14, minval=1, maxval=500)
myRsi = rsi(source, length)
plot(myRsi, title="myRsi", color=color.blue, linewidth=2, style=plot.style_line, transp=70)
hline(buy, title='buy', color=color.red, linestyle=hline.style_dotted, linewidth=1)
hline(sell, title='sell', color=color.red, linestyle=hline.style_dotted, linewidth=1)

// B o l i n g e r   B a n d s 
//bBands = bb(close, length, mult)
[middle, upper, lower] = bb(source, length, 2)
plot(middle, title="middle", color=color.red, display=display.none)
plot(upper, title="upper", color=color.green, display=display.none)
plot(lower, title="lower", color=color.green, display=display.none)

// B o l l i n g e r  B a n d  W i d t h 
bbWidth = bbw(source, length, 2)
plot(bbWidth, title="bbWidth", color=color.orange, display=display.none)

// S t r a t e g i e s
//if(bbWidth<0.004)
if (crossunder(myRsi, buy) and cross(source, lower))
    //strategy.entry(id, long, qty, limit, stop, oca_name, oca_type, comment, when)
    strategy.entry("long0", strategy.long, 100, stop=strategy.position_avg_price +
         strategy.position_avg_price*0.1, oca_name="long0",
         oca_type=strategy.oca.reduce, when=strategy.position_size <= 0)
    strategy.exit("long0", oca_name="long0", qty_percent=20, stop=strategy.position_avg_price +
         strategy.position_avg_price*0.1, trail_price=upper, trail_offset=2, when=strategy.position_size > 0)

if (crossover(myRsi, sell) and cross(source, upper))
    //strategy.entry(id, long, qty, limit, stop, oca_name, oca_type, comment, when)
    strategy.entry("short0", strategy.short, 100, stop=strategy.position_avg_price +
         strategy.position_avg_price*0.1, oca_name="long0", oca_type=strategy.oca.reduce,
         when=strategy.position_size > 0)
    strategy.exit("short0", oca_name="long0", qty_percent=20, stop=strategy.position_avg_price +
         strategy.position_avg_price*0.1, trail_price=lower, trail_offset=2, when=strategy.position_size > 0)
  
// A l e r t c o n d i t i o n s 
//alertcondition(crossunder(myRsi, buy) and crossunder(close, lower), title='Buy', message='{"direction":"buy","ticker":"{{ticker}}","frame":"1minute","close":"{{close}}","time":"{{time}}"}')
//alertcondition(crossover(myRsi, sell) and crossover(close, upper), title='Sell', message='{"direction":"sell","ticker":"{{ticker}}","frame":"1minute","close":"{{close}}","time":"{{time}}"}')

Overview

RSI/BB 1minute Study plots the RSI oscillator and threshold lines in a separate pane, while calculating hidden Bollinger Bands and band width. Long entries trigger when RSI crosses under the buy level while price crosses the lower band, and short entries occur when RSI crosses above the sell level while price crosses the upper band. Exits utilize trailing stops pegged to the opposite band. Configurable settings include RSI length and buy and sell thresholds.

Details

Published by

SammyEnigma on GitHub

Code credit

Greeffer, as written in the script's header

Type

Strategy, Pine Script v4

Draws

Separate pane below the chart

Category

Oscillators & momentum, Volatility & bands, Mean reversion

Markets

Any symbol

Timeframes

M1-M5

Risk Notes

  • The strategy can add several entries in the same direction

Settings

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

SettingTypeDefaultVariable
Sellint75sell
Buyint34buy
Lengthint14length
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 strategy combines Larry Williams' Vix Fix synthetic volatility indicator with Bollinger Bands. It calculates standard and inverted Williams Vix Fix metrics, displaying them as histogram columns with standard deviation bands in a separate pane. Long entrie

Strategy v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Williams Vix Fix Strategy [Alorse]

2xTP, SL to Entry

by hasnocool
106 stars

This strategy executes mean-reversion trades based on Bollinger Bands and the Stochastic Oscillator. Long orders trigger when price dips below the lower band alongside a bullish Stochastic crossover, with an optional oversold threshold. Short orders execute on

Strategy v5 Mean reversionOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 2xTP, SL to Entry
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
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

Calculates a combination of the Relative Strength Index, MACD histogram, and Bollinger Bands contraction to identify long trade entries. The strategy signals a long position on a bullish bar when the MACD histogram turns upward while negative, RSI remains belo

Strategy v4 Oscillators & momentumVolatility & bands
Updated 3 years ago · Apache-2.0 GitHub repository of RSI + MACD + BB Long Strategy (Not Good)

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers