Pine Script v5 · Strategy
Short Term RSI and SMA Percentage Change
A Pine Script v5 strategy built on RSI (close, 14) and SMA (close, 9). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.1% commission. 4 settings; defaults include Length 14, Trail Long Loss (%) 5 and Trail Short Loss (%) 5.
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 Short Term RSI and SMA Percentage Change repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 3 of 3 trades.
- How did Short Term RSI and SMA Percentage Change do on BTCUSDT 1D with default settings?
- −1.39%
- From 26 Jan 2024 to 21 Oct 2026, over 32 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Short Term RSI and SMA Percentage Change 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: 32 before, 32 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 Short Term RSI and SMA Percentage Change use a stop loss?
- Yes
- strategy.exit sets a stop on line 49.
- Does Short Term RSI and SMA Percentage Change run in Zeal Terminal?
- Yes
- It compiles in 22 ms and runs 1,000 bars in 61 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −1.39%
- −$13.92
- Buy and hold
- +102.5%
- same period
- Closed trades
- 32
- 12 won · 20 lost
- Profitable
- 37.5%
- of closed trades
- Profit factor
- 0.98
- gross profit ÷ gross loss
- Max drawdown
- 29.21%
- −$309.12
One run with the author's default settings, $1,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
1 setting does nothing
“Show Date Range” is declared but never read.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
1 setting has no label
In the settings dialog length (line 17) shows 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.
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 |
|---|---|---|---|
| Show Date Range | true | bool | unused |
| Length (no label in the script) | 14 | int | rsi |
| Trail Long Loss (%) | 5 | float · min 0.0 · step 0.1 | longStopPrice stopValue |
| Trail Short Loss (%) | 5 | float · min 0.0 · step 0.1 | shortStopPrice stopValue |
What it calculates
- RSIclose, Length (14)
rsi · line 18 - SMAclose, 9
SMA9 · line 21 - SMAclose, 100
SMA100 · line 22
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 | (buyCondition1 and buyCondition2 and buyCondition3 and timePeriod) | On | 30 |
| Exit Exit stop and limit | every bar | On | 49 |
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 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 | −1.4% | +102.5% | 32 | 38% | 0.98 | 29.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +9.2% | +5.5% | 6 | 50% | 1.95 | 11.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +89.4% | +9.8% | 36 | 44% | 1.89 | 17.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +6.1% | +8.4% | 11 | 36% | 1.23 | 11.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −28.1% | +16.7% | 58 | 36% | 0.82 | 45.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.9% | +21.5% | 17 | 41% | 1.02 | 17.9% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +29.4% | +148.3% | 38 | 34% | 1.30 | 33.6% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +2.6% | +17.1% | 11 | 36% | 1.11 | 17.2% | 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 | 16 | 44% | −$66.59 |
| Sideways market | 16 | 31% | $53.66 |
| 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?
42.4%
The 95th percentile of the worst drawdown when the same 32 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 21.7% to 42.4%; the tick is what actually happened, 28.5%. Order luck alone moves it this much.
All 32 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 5 May 2024 64,012.00 | 23 May 2024 67,874.30 | 18 | $58.22 |
| long | 23 May 2024 67,969.60 | 11 Jun 2024 67,552.60 | 19 | −$8.59 |
| long | 12 Jun 2024 68,264.00 | 21 Jun 2024 63,434.30 | 9 | −$76.21 |
| long | 21 Jul 2024 68,165.30 | 25 Jul 2024 64,155.40 | 4 | −$59.09 |
| long | 25 Jul 2024 65,799.90 | 31 Jul 2024 64,837.40 | 6 | −$15.18 |
| long | 1 Aug 2024 65,354.00 | 4 Aug 2024 58,423.40 | 3 | −$96.96 |
| long | 22 Sep 2024 63,578.80 | 1 Oct 2024 62,565.10 | 9 | −$14.37 |
| long | 4 Oct 2024 62,086.00 | 10 Oct 2024 59,678.90 | 6 | −$32.06 |
| long | 11 Oct 2024 62,540.00 | 23 Oct 2024 65,580.40 | 12 | $35.16 |
| long | 23 Oct 2024 66,668.60 | 1 Nov 2024 69,099.60 | 9 | $27.20 |
| long | 1 Nov 2024 69,496.00 | 25 Nov 2024 93,947.40 | 24 | $285.64 |
| long | 25 Nov 2024 93,010.00 | 5 Dec 2024 93,657.90 | 10 | $5.47 |
| long | 5 Dec 2024 96,945.60 | 9 Dec 2024 96,054.10 | 4 | −$12.40 |
| long | 9 Dec 2024 97,276.50 | 18 Dec 2024 100,827.00 | 9 | $37.76 |
| long | 18 Dec 2024 100,204.00 | 20 Dec 2024 92,588.80 | 2 | −$88.32 |
| long | 20 Dec 2024 97,805.40 | 27 Dec 2024 94,458.10 | 7 | −$37.83 |
| long | 2 Jan 2025 96,984.80 | 7 Jan 2025 97,123.80 | 5 | −$0.57 |
| long | 14 Jan 2025 96,560.90 | 27 Jan 2025 100,837.00 | 13 | $42.53 |
| long | 27 Jan 2025 102,083.00 | 2 Feb 2025 99,486.80 | 6 | −$28.76 |
| long | 3 Feb 2025 101,329.00 | 24 Feb 2025 93,389.80 | 21 | −$81.92 |
| long | 27 Apr 2025 93,749.30 | 29 May 2025 106,111.00 | 32 | $121.79 |
| long | 29 May 2025 105,590.00 | 5 Jun 2025 100,565.00 | 7 | −$52.53 |
| long | 6 Jun 2025 104,288.00 | 13 Jun 2025 104,761.00 | 7 | $2.54 |
| long | 13 Jun 2025 106,067.00 | 21 Jun 2025 101,455.00 | 8 | −$45.91 |
| long | 23 Jun 2025 105,334.00 | 1 Aug 2025 113,957.00 | 39 | $76.96 |
| long | 7 Aug 2025 117,472.00 | 15 Aug 2025 117,141.00 | 8 | −$5.01 |
| long | 15 Aug 2025 117,342.00 | 24 Aug 2025 111,535.00 | 9 | −$53.32 |
| long | 12 Sep 2025 116,029.00 | 24 Sep 2025 111,220.00 | 12 | −$42.68 |
| long | 3 Oct 2025 122,232.00 | 10 Oct 2025 118,426.00 | 7 | −$31.14 |
| long | 20 Apr 2026 75,841.00 | 16 May 2026 78,099.60 | 26 | $25.24 |
| long | 21 Aug 2026 78,338.00 | 10 Sep 2026 77,206.90 | 20 | −$15.35 |
| long | 10 Sep 2026 76,568.70 | 8 Oct 2026 82,289.00 | 28 | $66.78 |
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 |
|---|---|---|---|---|---|
| Short Term RSI and SMA Percentage Change this page | — | v5 strategy | −1.4% | 32 | 29.2% |
| SRJ RSI Outperformer Strategy by Sapt_Jash | rsi sma | v5 strategy | +0.6% | 8 | 2.4% |
| RSI SMA Crossover Strategy by reees | rsi sma | v5 strategy | +39.8% | 42 | 30.8% |
| Short In Downtrend Below MA100 (Coinrule) by Coinrule | sma rsi | v4 strategy | −34.5% | 99 | 45.4% |
| Simple RSI and SMA Long and Short (by Coinrule) by Coinrule | rsi sma | v5 strategy | −3.0% | 2 | 17.7% |
| Maximized Moving Average Crossing (by Coinrule) by Coinrule | sma rsi | v4 strategy | −6.6% | 9 | 13.3% |
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.
- 2 settings use the untyped input() (line 12, 17). 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 32 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 12: input() → input.bool()
- Line 17: input() → input.int()
⋯ commission_value=0.1)-showDate = input(defval=true, title='Show Date Range')+showDate = input.bool(defval=true, title='Show Date Range')timePeriod = time >= timestamp(syminfo.timezone, 2022, 5, 1, 0, 0)⋯//RSI-length = input(14)+length = input.int(14)rsi = ta.rsi(close, length)⋯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: 32 before, 32 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.
⋯// © Coinrule-//@version=5+//@version=6strategy("Short Term RSI and SMA Percentage Change",⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 22 ms | Yes 1,000 bars in 61 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/// © Coinrule//@version=5strategy("Short Term RSI and SMA Percentage Change", overlay=true, initial_capital=1000, process_orders_on_close=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)showDate = input(defval=true, title='Show Date Range')timePeriod = time >= timestamp(syminfo.timezone, 2022, 5, 1, 0, 0)notInTrade = strategy.position_size <= 0//==================================Buy Conditions============================================//RSIlength = input(14)rsi = ta.rsi(close, length)buyCondition1 = rsi > 50//MASMA9 = ta.sma(close, 9)SMA100 = ta.sma(close, 100)plot(SMA9, color = color.green)plot(SMA100, color = color.blue)buyCondition2 = (SMA9 > SMA100)//Calculating MA Percentage ChangebuyMA = (close/SMA9)buyCondition3 = buyMA >= 0.06if (buyCondition1 and buyCondition2 and buyCondition3 and timePeriod) //and buyCondition strategy.entry("Long", strategy.long)//==================================Sell Conditions============================================// Configure trail stop level with input optionslongTrailPerc = input.float(title='Trail Long Loss (%)', minval=0.0, step=0.1, defval=5) * 0.01shortTrailPerc = input.float(title='Trail Short Loss (%)', minval=0.0, step=0.1, defval=5) * 0.01// Determine trail stop loss priceslongStopPrice = 0.0shortStopPrice = 0.0longStopPrice := if strategy.position_size > 0 stopValue = close * (1 - longTrailPerc) math.max(stopValue, longStopPrice[1])else 0shortStopPrice := if strategy.position_size < 0 stopValue = close * (1 + shortTrailPerc) math.min(stopValue, shortStopPrice[1])else 999999 strategy.exit('Exit', stop = longStopPrice, limit = shortStopPrice)