Pine Script v5 · Strategy
RSI_Boll-TP-SL
A Pine Script v5 strategy built on SMA (close, 200), Stdev (close, 200) and Crossover (source, BBlower). It has 12 order rules, 4 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.05% commission. 16 settings; defaults include Source close, RSI Length 6 and RSI OverSold 50.
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 RSI_Boll-TP-SL repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did RSI_Boll-TP-SL do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Does RSI_Boll-TP-SL run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L51:C13: cannot use 'int' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download.
- Does RSI_Boll-TP-SL use a stop loss?
- Yes
- strategy.exit sets a stop on line 101, 103, 112, 114.
- Does RSI_Boll-TP-SL run in Zeal Terminal?
- Yes
- It compiles in 34 ms and runs 1,000 bars in 62 ms, in the browser.
BTCUSDT · 1D · default settings
- Bollinger Bands SMA Basis Line
- Bollinger Bands Upper Line
- Bollinger Bands Lower Line
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
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
Every trade uses all the equity
default_qty_value is 100% of equity.
-
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 76, 80, 84, 85, 91, 92. 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 |
|---|---|---|---|
| Source | close | source | BBbasis BBdev TrendColor vrsi |
| RSI Length | 6 | int | vrsi |
| RSI OverSold | 50 | int · min 1 | TrendColor rsiCrossOver |
| RSI OverBought | 50 | int · min 1 | TrendColor rsiCrossUnder |
| Bollinger Period Length | 200 | int · min 1 | BBbasis BBdev |
| Bollinger Bands Standard Deviation | 2.0 | float · min 0.001 · max 50 · step 0.1 | BBdev |
| Take Profit: | 0.0 | float · min 0.0 · max 100.0 · step 0.1 | longProfitPrice shortProfitPrice line 99 line 104 |
| Stop Loss: | 0.0 | float · min 0.0 · max 100.0 · step 0.1 | longStopPrice shortStopPrice line 99 line 110 |
| Long Entry | true | bool | entry LONG close LONG line 74 line 83 |
| Short Entry | true | bool | entry SHORT close SHORT line 74 line 90 |
| From Day | 1 | int · min 1 · max 31 | start |
| From Month | 1 | int · min 1 · max 12 | start |
| From Year | 2021 | int · min 2010 | start |
| To Day | 30 | int · min 1 · max 31 | finish |
| To Month | 12 | int · min 1 · max 12 | finish |
| To Year | 2022 | int · min 2010 | finish |
What it calculates
- SMASource (close), Bollinger Period Length (200)
BBbasis · line 19 - StdevSource (close), Bollinger Period Length (200)
BBdev · line 20 - Crossoversource, BBlower
buyEntry · line 24 - Crossundersource, BBupper
sellEntry · line 25 - RSISource (close), RSI Length (6)
vrsi · line 59 - Crossovervrsi, RSI OverSold (50)
rsiCrossOver · line 60 - Crossundervrsi, RSI OverBought (50)
rsiCrossUnder · line 61 - Crossoversource, BBlower
BBCrossOver · line 62 - Crossundersource, BBupper
BBCrossUnder · line 63
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 LONG long | buySignallwindow() and long and (not stoppedOutLong) | On | 76 |
| Open SHORT short | sellSignallwindow() and (not long) and (not stoppedOutShort) | On | 80 |
| Open LONG long | buySignallwindow() and long and (not stoppedOutLong) | On | 84 |
| Close LONG | sellSignallwindow() and (not long) and (not stoppedOutShort) | On | 85 |
| Open SHORT short | sellSignallwindow() and (not long) and (not stoppedOutShort) | On | 91 |
| Close SHORT | buySignallwindow() and long and (not stoppedOutLong) | On | 92 |
| Exit LONG stop and limit | ( strategy.position_size > 0 ) | On | 101 |
| Exit SHORT stop and limit | ( strategy.position_size < 0 ) | On | 103 |
| Exit LONG limit | ( strategy.position_size > 0 ) | On | 106 |
| Exit SHORT limit | ( strategy.position_size < 0 ) | On | 108 |
| Exit LONG stop | ( strategy.position_size > 0 ) | On | 112 |
| Exit SHORT stop | ( strategy.position_size < 0 ) | On | 114 |
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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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 | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
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 |
|---|---|---|---|---|---|
| RSI_Boll-TP-SL this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| 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% |
| Bollinger Bands and RSI Short Selling (by Coinrule) by Coinrule | sma stdev rsi | v5 strategy | +7.6% | 3 | 4.3% |
| Shorting when Bollinger Band Above Price with RSI (by Coinrule) by Coinrule | 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.
- 6 strategy calls use the when = argument (line 76, 80, 84, 85, 91, 92). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 1 setting uses the untyped input() (line 12). 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.
Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 12: input() → input.source()
- Line 76: when = buySignall → if block
- Line 80: when = sellSignall → if block
- Line 84: when = buySignall → if block
- Line 85: when = sellSignall → if block
- Line 91: when = sellSignall → if block
- Line 92: when = buySignall → if block
⋯//---------- RSI --------------price = input(close, title="Source")+price = input.source(close, title="Source")RSIlength = input.int(defval=6,title="RSI Length") ⋯ if long - strategy.entry("LONG", strategy.long, when = buySignall, comment = "ENTER LONG")+ if buySignall+ strategy.entry("LONG", strategy.long, comment = "ENTER LONG") stoppedOutLong := true⋯ else - strategy.entry("SHORT", strategy.short, when = sellSignall, comment = "ENTER SHORT")+ if sellSignall+ strategy.entry("SHORT", strategy.short, comment = "ENTER SHORT") stoppedOutLong := false⋯else if(longEntry)- strategy.entry("LONG", strategy.long, when = buySignall)+ if buySignall+ strategy.entry("LONG", strategy.long)- strategy.close("LONG", when = sellSignall)+ if sellSignall+ strategy.close("LONG") if long ⋯else if(shortEntry)- strategy.entry("SHORT", strategy.short, when = sellSignall)+ if sellSignall+ strategy.entry("SHORT", strategy.short)- strategy.close("SHORT", when = buySignall)+ if buySignall+ strategy.close("SHORT") if not long⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L51:C13: cannot use 'int' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © BigCoinHunter-//@version=5+//@version=6strategy(title="RSI_Boll-TP/SL", overlay=true, ⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 34 ms | With a workaround 1,000 bars in 62 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
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/// © BigCoinHunter//@version=5strategy(title="RSI_Boll-TP/SL", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=1000, currency=currency.USD, commission_value=0.05, commission_type=strategy.commission.percent, process_orders_on_close=true)//----------- get the user inputs --------------//---------- RSI -------------price = input(close, title="Source")RSIlength = input.int(defval=6,title="RSI Length") RSIoverSold = input.int(defval=50, title="RSI OverSold", minval=1)RSIoverBought = input.int(defval=50, title="RSI OverBought", minval=1)//------- Bollinger Bands -----------BBlength = input.int(defval=200, title="Bollinger Period Length", minval=1)BBmult = input.float(defval=2.0, minval=0.001, maxval=50, step=0.1, title="Bollinger Bands Standard Deviation")BBbasis = ta.sma(price, BBlength)BBdev = BBmult * ta.stdev(price, BBlength)BBupper = BBbasis + BBdevBBlower = BBbasis - BBdevsource = closebuyEntry = ta.crossover(source, BBlower)sellEntry = ta.crossunder(source, BBupper)plot(BBbasis, color=color.aqua, title="Bollinger Bands SMA Basis Line")p1 = plot(BBupper, color=color.silver, title="Bollinger Bands Upper Line")p2 = plot(BBlower, color=color.silver, title="Bollinger Bands Lower Line")fill(plot1=p1, plot2=p2, title="Bollinger BackGround", color=color.new(color.aqua,90), fillgaps=false, editable=true)//---------- input TP/SL ---------------tp = input.float(title="Take Profit:", defval=0.0, minval=0.0, maxval=100.0, step=0.1) * 0.01sl = input.float(title="Stop Loss: ", defval=0.0, minval=0.0, maxval=100.0, step=0.1) * 0.01longEntry = input.bool(defval=true, title= 'Long Entry', inline="11")shortEntry = input.bool(defval=true, title='Short Entry', inline="11")//---------- backtest range setup ------------fromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)fromYear = input.int(defval = 2021, title = "From Year", minval = 2010)toDay = input.int(defval = 30, title = "To Day", minval = 1, maxval = 31)toMonth = input.int(defval = 12, title = "To Month", minval = 1, maxval = 12)toYear = input.int(defval = 2022, title = "To Year", minval = 2010)//------------ time interval setup -----------start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start windowfinish = timestamp(toYear, toMonth, toDay, 23, 59) // backtest finish windowwindow() => time >= start and time <= finish ? true : false // create function "within window of time"//------- define the global variables ------var bool long = truevar bool stoppedOutLong = falsevar bool stoppedOutShort = false//--------- Colors ---------------TrendColor = RSIoverBought and (price[1] > BBupper and price < BBupper) and BBbasis < BBbasis[1] ? color.red : RSIoverSold and (price[1] < BBlower and price > BBlower) and BBbasis > BBbasis[1] ? color.green : na//bgcolor(switch2?(color.new(TrendColor,50)):na)//--------- calculate the input/output points -----------longProfitPrice = strategy.position_avg_price * (1 + tp) // tp -> take profit percentagelongStopPrice = strategy.position_avg_price * (1 - sl) // sl -> stop loss percentageshortProfitPrice = strategy.position_avg_price * (1 - tp)shortStopPrice = strategy.position_avg_price * (1 + sl)//---------- RSI + Bollinger Bands Strategy -------------vrsi = ta.rsi(price, RSIlength)rsiCrossOver = ta.crossover(vrsi, RSIoverSold)rsiCrossUnder = ta.crossunder(vrsi, RSIoverBought)BBCrossOver = ta.crossover(source, BBlower)BBCrossUnder = ta.crossunder(source, BBupper)if (not na(vrsi)) if rsiCrossOver and BBCrossOver long := true if rsiCrossUnder and BBCrossUnder long := false//------------------- determine buy and sell points ---------------------buySignall = window() and long and (not stoppedOutLong)sellSignall = window() and (not long) and (not stoppedOutShort)//---------- execute the strategy -----------------if(longEntry and shortEntry) if long strategy.entry("LONG", strategy.long, when = buySignall, comment = "ENTER LONG") stoppedOutLong := true stoppedOutShort := false else strategy.entry("SHORT", strategy.short, when = sellSignall, comment = "ENTER SHORT") stoppedOutLong := false stoppedOutShort := trueelse if(longEntry) strategy.entry("LONG", strategy.long, when = buySignall) strategy.close("LONG", when = sellSignall) if long stoppedOutLong := true else stoppedOutLong := falseelse if(shortEntry) strategy.entry("SHORT", strategy.short, when = sellSignall) strategy.close("SHORT", when = buySignall) if not long stoppedOutShort := true else stoppedOutShort := false //----------------- take profit and stop loss -----------------if(tp>0.0 and sl>0.0) if ( strategy.position_size > 0 ) strategy.exit(id="LONG", limit=longProfitPrice, stop=longStopPrice, comment="Long TP/SL Trigger") else if ( strategy.position_size < 0 ) strategy.exit(id="SHORT", limit=shortProfitPrice, stop=shortStopPrice, comment="Short TP/SL Trigger")else if(tp>0.0) if ( strategy.position_size > 0 ) strategy.exit(id="LONG", limit=longProfitPrice, comment="Long TP Trigger") else if ( strategy.position_size < 0 ) strategy.exit(id="SHORT", limit=shortProfitPrice, comment="Short TP Trigger") else if(sl>0.0) if ( strategy.position_size > 0 ) strategy.exit(id="LONG", stop=longStopPrice, comment="Long SL Trigger") else if ( strategy.position_size < 0 ) strategy.exit(id="SHORT", stop=shortStopPrice, comment="Short SL Trigger")