Pine Script v5 · Strategy
RSI Average Swing Bot
A Pine Script v5 strategy built on RSI (ohlc4, 50). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 4 settings; defaults include Longexit 0.65 and Shortexit 0.35.
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 Average Swing Bot repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 10 of 10 trades.
- How did RSI Average Swing Bot do on BTCUSDT 1D with default settings?
- +2.21%
- From 26 Jan 2024 to 21 Oct 2026, over 37 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does RSI Average Swing Bot 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: 37 before, 43 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 RSI Average Swing Bot use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does RSI Average Swing Bot run in Zeal Terminal?
- Yes
- It compiles in 12 ms and runs 1,000 bars in 31 ms, in the browser.
BTCUSDT · 1D · default settings
- HLine
- HLine
- HLine
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +2.21%
- $22,146.50
- Buy and hold
- +102.5%
- same period
- Closed trades
- 37
- 7 won · 30 lost
- Profitable
- 18.9%
- of closed trades
- Profit factor
- 1.29
- gross profit ÷ gross loss
- Max drawdown
- 3.54%
- −$35,963.30
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
2 settings have no label
In the settings dialog longexit (line 20), shortexit (line 22) 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 24, 25, 27, 28. 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 |
|---|---|---|---|
| Entries Type | |||
| Allow Long entries | true | bool | entry long close long line 23 |
| Allow Short entries | true | bool | entry short close short line 26 |
| Longexit (no label in the script) | 0.65 | float · step 0.05 | close long |
| Shortexit (no label in the script) | 0.35 | float · step 0.05 | close short |
What it calculates
- RSIohlc4, 50
rsiohlc4 · line 7 - RSIclose, 50
rsiclose · line 8 - RSIopen, 50
rsiopen · line 9 - RSIhigh, 50
rsihigh · line 10 - RSIhlc3, 50
rsihlc3 · line 11 - RSIhl2, 50
rsihl2 · line 12
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 | longrsi_avg > 0.5 and rsi_avg[1]< 0.5 | On | 24 |
| Close long | longexit or short | On | 25 |
| Open short short | shortrsi_avg < 0.5 and rsi_avg[1] >0.5 | On | 27 |
| Close short | shortexit or long | On | 28 |
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, and the live replay matched history.
- 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 | +2.2% | +102.5% | 37 | 19% | 1.29 | 3.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.7% | +5.5% | 38 | 16% | 0.68 | 1.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.0% | +9.8% | 41 | 20% | 1.06 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 20 | 30% | 1.64 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 48 | 17% | 0.73 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 36 | 22% | 1.60 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.0% | +148.3% | 35 | 14% | 0.50 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 43 | 26% | 1.38 | 0.0% | 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 | 1 | 0% | −$717.88 |
| Sideways market | 35 | 20% | $26,134.60 |
| Falling market | 1 | 0% | −$3,270.21 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
5.1%
The 95th percentile of the worst drawdown when the same 37 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.2% to 5.1%; the tick is what actually happened, 3.4%. Order luck alone moves it this much.
All 37 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 25 Jun 2024 60,293.30 | 2 Jul 2024 62,900.00 | 7 | −$2,606.70 |
| long | 2 Jul 2024 62,900.00 | 3 Jul 2024 62,135.50 | 1 | −$764.54 |
| short | 3 Jul 2024 62,135.50 | 16 Jul 2024 64,724.10 | 13 | −$2,588.60 |
| long | 16 Jul 2024 64,724.10 | 4 Aug 2024 60,698.00 | 19 | −$4,026.07 |
| short | 4 Aug 2024 60,698.00 | 24 Aug 2024 64,037.20 | 20 | −$3,339.25 |
| long | 24 Aug 2024 64,037.20 | 28 Aug 2024 59,415.00 | 4 | −$4,622.24 |
| short | 28 Aug 2024 59,415.00 | 19 Sep 2024 61,760.00 | 22 | −$2,344.98 |
| long | 19 Sep 2024 61,760.00 | 3 Oct 2024 60,649.30 | 14 | −$1,110.71 |
| short | 3 Oct 2024 60,649.30 | 5 Oct 2024 62,086.00 | 2 | −$1,436.73 |
| long | 5 Oct 2024 62,086.00 | 10 Oct 2024 60,636.00 | 5 | −$1,449.99 |
| short | 10 Oct 2024 60,636.00 | 12 Oct 2024 62,540.00 | 2 | −$1,903.98 |
| long | 12 Oct 2024 62,540.00 | 12 Nov 2024 88,648.00 | 31 | $26,108.00 |
| short | 25 Feb 2025 91,552.90 | 23 Apr 2025 93,443.00 | 57 | −$1,890.11 |
| long | 23 Apr 2025 93,443.00 | 27 Aug 2025 111,763.00 | 126 | $18,320.20 |
| short | 27 Aug 2025 111,763.00 | 28 Aug 2025 111,262.00 | 1 | $501.21 |
| long | 28 Aug 2025 111,262.00 | 30 Aug 2025 108,377.00 | 2 | −$2,884.61 |
| short | 30 Aug 2025 108,377.00 | 4 Sep 2025 111,706.00 | 5 | −$3,328.32 |
| long | 4 Sep 2025 111,706.00 | 7 Sep 2025 110,188.00 | 3 | −$1,517.74 |
| short | 7 Sep 2025 110,188.00 | 9 Sep 2025 112,065.00 | 2 | −$1,877.25 |
| long | 9 Sep 2025 112,065.00 | 26 Sep 2025 108,994.00 | 17 | −$3,070.74 |
| short | 26 Sep 2025 108,994.00 | 30 Sep 2025 114,312.00 | 4 | −$5,317.48 |
| long | 30 Sep 2025 114,312.00 | 12 Oct 2025 110,644.00 | 12 | −$3,667.57 |
| short | 12 Oct 2025 110,644.00 | 14 Oct 2025 115,166.00 | 2 | −$4,521.60 |
| long | 14 Oct 2025 115,166.00 | 15 Oct 2025 113,028.00 | 1 | −$2,137.87 |
| short | 15 Oct 2025 113,028.00 | 27 Oct 2025 114,559.00 | 12 | −$1,531.28 |
| long | 27 Oct 2025 114,559.00 | 30 Oct 2025 110,021.00 | 3 | −$4,538.11 |
| short | 30 Oct 2025 110,021.00 | 15 Jan 2026 96,951.80 | 77 | $13,069.50 |
| long | 15 Jan 2026 96,951.80 | 17 Jan 2026 95,550.90 | 2 | −$1,400.84 |
| short | 17 Jan 2026 95,550.90 | 6 Feb 2026 62,909.90 | 20 | $32,641.10 |
| long | 18 Apr 2026 77,072.00 | 20 Apr 2026 73,801.80 | 2 | −$3,270.21 |
| short | 20 Apr 2026 73,801.80 | 22 Apr 2026 76,336.10 | 2 | −$2,534.34 |
| long | 22 Apr 2026 76,336.10 | 20 May 2026 76,834.40 | 28 | $498.22 |
| short | 20 May 2026 76,834.40 | 21 May 2026 77,552.20 | 1 | −$717.88 |
| long | 21 May 2026 77,552.20 | 23 May 2026 75,539.50 | 2 | −$2,012.74 |
| short | 23 May 2026 75,539.50 | 26 May 2026 77,322.00 | 3 | −$1,782.51 |
| long | 26 May 2026 77,322.00 | 27 May 2026 75,930.00 | 1 | −$1,392.00 |
| short | 27 May 2026 75,930.00 | 20 Aug 2026 69,334.80 | 85 | $6,595.23 |
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 Average Swing Bot this page | — | v5 strategy | +2.2% | 37 | 3.5% |
| Triple RSI strategy by Trade_by_DB | rsi | v5 strategy | +3.2% | 2 | 3.3% |
| Hobbiecode - RSI + Close previous day by hobbiecode | rsi | v5 strategy | +1.2% | 63 | 4.2% |
| dirt cheap yet elegant RSI Strategy by SparkyFlary | rsi | v4 strategy | −11.4% | 8 | 20.5% |
| RSI Classic Strategy (by Coinrule) by Coinrule | rsi | v4 strategy | +7.5% | 6 | 7.2% |
| RSITrendStrategy by email_analysts | rsi | v4 strategy | +69.2% | 22 | 38.6% |
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.
- 4 strategy calls use the when = argument (line 24, 25, 27, 28). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- No v6-only features. v6 is not needed to run this script.
Same 37 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 24: when = long → if block
- Line 25: when = longexit or short → if block
- Line 27: when = short → if block
- Line 28: when = shortexit or long → if block
⋯if(long_only)- strategy.entry("long",strategy.long,when=long)+ if long+ strategy.entry("long",strategy.long)- strategy.close("long",when=longexit or short)+ if longexit or short+ strategy.close("long")if(short_only)- strategy.entry("short",strategy.short,when=short)+ if short+ strategy.entry("short",strategy.short)- strategy.close("short",when=shortexit or long)+ if shortexit or long+ strategy.close("short")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: 37 before, 43 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.
⋯// © exlux99-//@version=5+//@version=6strategy("RSI Average Swing Bot")⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 12 ms | Yes 1,000 bars in 31 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“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/// © exlux99//@version=5strategy("RSI Average Swing Bot")long_only=input.bool(true, title="Allow Long entries", group="Entries Type")short_only=input.bool(true, title="Allow Short entries", group="Entries Type")rsiohlc4= ta.rsi(ohlc4,50)/100rsiclose= ta.rsi(close,50)/100rsiopen= ta.rsi(open,50)/100rsihigh= ta.rsi(high,50)/100rsihlc3= ta.rsi(hlc3,50)/100rsihl2= ta.rsi(hl2,50)/100hline(0.3, color=color.white, linestyle=hline.style_dashed, linewidth=2)hline(0.5, color=color.white, linestyle=hline.style_dotted, linewidth=2)hline(0.7, color=color.white, linestyle=hline.style_dashed, linewidth=2)rsi_avg = (rsiohlc4+rsiclose+rsiopen+rsihigh+rsihl2+rsihlc3)/6culoare = rsi_avg > 0.50? color.green : rsi_avg<0.50 ? color.red : color.yellowplot(rsi_avg,color=culoare )long = rsi_avg > 0.5 and rsi_avg[1]< 0.5longexit = rsi_avg >= input.float(0.65, step=0.05)short = rsi_avg < 0.5 and rsi_avg[1] >0.5shortexit=rsi_avg<=input.float(0.35, step=0.05)if(long_only) strategy.entry("long",strategy.long,when=long) strategy.close("long",when=longexit or short)if(short_only) strategy.entry("short",strategy.short,when=short) strategy.close("short",when=shortexit or long)