Pine Script v5 · Strategy
Bollinger Bands and RSI Short Selling (by Coinrule)
A Pine Script v5 strategy built on SMA (close, 20), Stdev (close, 20) and RSI (close, lengthRSI). It has 2 order rules, 1 entry among them, and trades short only with the default settings. Exits use a stop loss and a profit target. Each trade commits 30% of equity and pays 0.1% commission. 7 settings; defaults include Length 20, Source close and StdDev 2.0.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does Bollinger Bands and RSI Short Selling (by Coinrule) repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Bollinger Bands and RSI Short Selling (by Coinrule) do on BTCUSDT 1D with default settings?
- +7.62%
- From 26 Jan 2024 to 21 Oct 2026, over 3 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Bollinger Bands and RSI Short Selling (by Coinrule) run in Pine Script v6?
- No
- The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 3 before, 3 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Bollinger Bands and RSI Short Selling (by Coinrule) use a stop loss?
- Yes
- strategy.exit sets a stop on line 40.
- Does Bollinger Bands and RSI Short Selling (by Coinrule) run in Zeal Terminal?
- Yes
- It compiles in 14 ms and runs 1,000 bars in 46 ms, in the browser.
BTCUSDT · 1D · default settings
- Basis
- Upper
- Lower
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +7.62%
- $76.18
- Buy and hold
- +102.5%
- same period
- Closed trades
- 3
- 2 won · 1 lost
- Profitable
- 66.7%
- of closed trades
- Profit factor
- 3.68
- gross profit ÷ gross loss
- Max drawdown
- 4.30%
- −$42.99
One run with the author's default settings, $1,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
1 setting does nothing
“Oversold” is declared but never read.
-
Note
4 settings have no label
In the settings dialog length (line 16), oversold (line 31), Stop_loss (line 33), Take_profit (line 34) show an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 38. The upgraded version below moves each call inside an if block.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Length (no label in the script) | 20 | int · min 1 | basis dev |
| Source | close | source | basis dev |
| StdDev | 2.0 | float · min 0.001 · max 50 | dev |
| Offset | 0 | int · min -500 · max 500 | Upper Lower Basis |
| Oversold (no label in the script) | 30 | int | unused |
| Stop loss (no label in the script) | 1 | int | shortStopPrice |
| Take profit (no label in the script) | 7 | int | shortTakeProfit |
What it calculates
- SMASource (close), Length (20)
basis · line 19 - StdevSource (close), Length (20)
dev · line 20 - RSIclose, lengthRSI
RSI · line 30
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open short short | ta.crossover(close, upper) and RSI < 70 and timePeriod and notInTrade | On | 38 |
| Exit close stop and limit | (ta.crossover(upper, close) and RSI > 70 and timePeriod) | On | 40 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +7.6% | +102.5% | 3 | 67% | 3.68 | 4.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.6% | +5.5% | 2 | 50% | 4.91 | 1.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +4.9% | +9.8% | 5 | 40% | 1.44 | 10.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −12.2% | +8.4% | 5 | 0% | 0.00 | 12.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +5.7% | +16.7% | 3 | 33% | 1.98 | 28.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −5.6% | +21.5% | 3 | 33% | 0.44 | 10.5% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −8.7% | +148.3% | 4 | 25% | 0.40 | 16.7% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −6.6% | +17.1% | 6 | 17% | 0.16 | 7.7% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 2 | 50% | −$28.03 |
| Sideways market | 1 | 100% | $104.21 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
2.8%
The 95th percentile of the worst drawdown when the same 3 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.8% to 2.8%; the tick is what actually happened, 2.8%. Order luck alone moves it this much.
All 3 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 16 May 2024 66,206.50 | 31 Oct 2024 72,344.80 | 168 | −$28.41 |
| short | 16 Dec 2024 104,464.00 | 12 May 2025 104,118.00 | 147 | $0.38 |
| short | 14 Aug 2025 123,306.00 | 25 Aug 2026 78,992.80 | 376 | $104.21 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Bollinger Bands and RSI Short Selling (by Coinrule) this page | — | v5 strategy | +7.6% | 3 | 4.3% |
| Bottom catch strategy by footlz | sma stdev rsi | v4 strategy | +3.9% | 3 | 7.1% |
| Madri by Mdemoio | rsi sma stdev | v4 strategy | +25.0% | 4 | 36.4% |
| Shorting when Bollinger Band Above Price with RSI (by Coinrule) by Coinrule | sma stdev rsi | v5 strategy | No trades on this market | ||
| RSI_Boll-TP-SL by BigCoinHunter | sma stdev rsi | v5 strategy | No trades on this market | ||
| FMC by oliverbadaoui | sma rsi stdev | v4 strategy | +139.5% | 44 | 111.9% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 1 strategy call uses the when = argument (line 38). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 4 settings use the untyped input() (line 17, 31, 33, 34). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 3 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 17: input() → input.source()
- Line 31: input() → input.int()
- Line 33: input() → input.int()
- Line 34: input() → input.int()
- Line 38: when = ta.crossover(close, upper) and RSI < 70 and timePeriod and notInTrade → if block
⋯length = input.int(20, minval=1)-src = input(close, title="Source")+src = input.source(close, title="Source")mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")⋯RSI = ta.rsi(close, lengthRSI)-oversold= input(30)+oversold= input.int(30)//Stop Loss and Take Profit for Shorting-Stop_loss= ((input (1))/100)+Stop_loss= ((input.int (1))/100)-Take_profit= ((input (7)/100))+Take_profit= ((input.int (7)/100))shortStopPrice = strategy.position_avg_price * (1 + Stop_loss)⋯//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(close, upper) and RSI < 70 and timePeriod and notInTrade+ strategy.entry(id="short", direction=strategy.short)if (ta.crossover(upper, close) and RSI > 70 and timePeriod)⋯Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 3 before, 3 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// Works best on 30m, 45m timeframe-//@version=5+//@version=6strategy("Bollinger Bands and RSI Short Selling",⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 14 ms | With a workaround 1,000 bars in 46 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
Zeal Terminal's engine currently reads an order side written as direction = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 38) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// 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=5strategy("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 periodtimePeriod = time >= timestamp(syminfo.timezone, 2021, 12, 1, 0, 0)notInTrade = strategy.position_size <= 0//Bollinger Bands Indicatorlength = 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 + devlower = basis - devoffset = 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 calculationslengthRSI = 14RSI = ta.rsi(close, lengthRSI)oversold= input(30)//Stop Loss and Take Profit for ShortingStop_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 Exitstrategy.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)