Strategy · Pine Script v5 · On the chart

Bollinger Bands and RSI Short Selling

by hasnocool· code credited to Coinrule

This strategy executes short trades based on Bollinger Bands and the Relative Strength Index (RSI).

View on GitHub

GitHub stars106on the repository
Pine versionv5runs as is
Lines of code42
Settings5inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

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

42 lines of Pine Script v5 from Bollinger Bands and RSI Short Selling (by Coinrule).pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Bollinger Bands and RSI Short Selling (by Coinrule).pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Coinrule
// Works best on 30m, 45m timeframe
//@version=5
strategy("Bollinger Bands and RSI Short Selling",
         overlay=true,
         initial_capital = 1000,
         default_qty_value = 30,
         default_qty_type = strategy.percent_of_equity,
         commission_type=strategy.commission.percent,
         commission_value=0.1)
//Backtest period
timePeriod = time >= timestamp(syminfo.timezone, 2021, 12, 1, 0, 0)
notInTrade = strategy.position_size <= 0
//Bollinger Bands Indicator
length = input.int(20, minval=1)
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, "Offset", minval = -500, maxval = 500)
plot(basis, "Basis", color=#FF6D00, offset = offset)
p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))
// RSI inputs and calculations
lengthRSI = 14
RSI = ta.rsi(close, lengthRSI)
oversold= input(30)
//Stop Loss and Take Profit for Shorting
Stop_loss= ((input (1))/100)
Take_profit= ((input (7)/100))
shortStopPrice  = strategy.position_avg_price * (1 + Stop_loss)
shortTakeProfit = strategy.position_avg_price * (1 - Take_profit)
//Entry and Exit
strategy.entry(id="short", direction=strategy.short, when=ta.crossover(close, upper) and RSI < 70 and timePeriod and notInTrade)
if (ta.crossover(upper, close) and RSI > 70 and timePeriod)
    strategy.exit(id='close', stop = shortTakeProfit, limit = shortStopPrice)
    
Expand (53 lines)

Overview

Bollinger Bands and RSI Short Selling plots the Bollinger Bands on the price chart and enters a short position when the closing price crosses above the upper band while RSI remains below 70. An exit order with fixed percentage stop-loss and take-profit levels is submitted only when the upper band crosses back below price and RSI rises above 70. Configurable settings include band length, standard deviation multiplier, source, offset, and stop-loss and take-profit percentages.

Details

Published by

hasnocool on GitHub

Code credit

Coinrule, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Volatility & bands, Oscillators & momentum, Mean reversion

Markets

Crypto

Timeframes

M15-H1

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.

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
lengthint20length
Sourcesourceclosesrc
StdDevfloat2.0mult
Offsetint0offset
oversoldint30oversold
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]
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

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