Pine Script v5 · Strategy
Simple RSI and SMA Long and Short (by Coinrule)
A Pine Script v5 strategy built on RSI (close, 14) and SMA (close, 100). 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 commits 30% of equity and pays 0.1% commission. 2 settings; defaults include Length 14.
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 Simple RSI and SMA Long and Short (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 Simple RSI and SMA Long and Short (by Coinrule) do on BTCUSDT 1D with default settings?
- −3.01%
- From 26 Jan 2024 to 21 Oct 2026, over 2 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Simple RSI and SMA Long and Short (by Coinrule) run in Pine Script v6?
- Yes
- Same 2 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
- Does Simple RSI and SMA Long and Short (by Coinrule) use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Simple RSI and SMA Long and Short (by Coinrule) run in Zeal Terminal?
- Yes
- It compiles in 9 ms and runs 1,000 bars in 39 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −3.01%
- −$30.15
- Buy and hold
- +102.5%
- same period
- Closed trades
- 2
- 0 won · 2 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- 0.00
- gross profit ÷ gross loss
- Max drawdown
- 17.69%
- −$176.92
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
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
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.
-
Note
Uses an argument v6 removed
when = on line 26, 27, 28, 29. 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 |
|---|---|---|---|
| Show Date Range | true | bool | unused |
| Length (no label in the script) | 14 | int | rsi |
What it calculates
- RSIclose, Length (14)
rsi · line 18 - SMAclose, 100
fastEMA · line 20 - SMAclose, 150
slowEMA · line 21
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 | bullish and timePeriod | On | 26 |
| Close Exit | bearishta.crossover(slowEMA, fastEMA) and rsi < 50 | On | 27 |
| Open Short short | bearish and timePeriod | On | 28 |
| Close Exit | bullishta.crossover(fastEMA, slowEMA) and rsi > 50 | On | 29 |
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 | −3.0% | +102.5% | 2 | 0% | 0.00 | 17.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.6% | +5.5% | 3 | 33% | 0.89 | 4.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −33.2% | +9.8% | 5 | 40% | 0.07 | 38.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −2.8% | +8.4% | 2 | 50% | 0.25 | 3.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −27.1% | +16.7% | 6 | 17% | 0.12 | 33.6% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +12.3% | +21.5% | 1 | 100% | 366.87 | 0.7% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −14.5% | +148.3% | 3 | 0% | 0.00 | 42.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +8.7% | +17.1% | 1 | 100% | 266.85 | 1.4% | 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% | −$21.31 |
| Sideways market | 1 | 0% | −$8.55 |
| 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?
3.0%
The 95th percentile of the worst drawdown when the same 2 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 3.0% to 3.0%; the tick is what actually happened, 3.0%. Order luck alone moves it this much.
All 2 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 11 Nov 2024 88,648.00 | 2 Apr 2025 82,516.30 | 142 | −$21.31 |
| short | 2 Apr 2025 82,516.30 | 3 Oct 2026 84,753.60 | 549 | −$8.55 |
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 |
|---|---|---|---|---|---|
| Simple RSI and SMA Long and Short (by Coinrule) this page | — | v5 strategy | −3.0% | 2 | 17.7% |
| 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% |
| Maximized Moving Average Crossing (by Coinrule) by Coinrule | sma rsi | v4 strategy | −6.6% | 9 | 13.3% |
| RSI Mean Reversion Strategy by Zeal Terminal | rsi sma | v5 strategy | +2.2% | 16 | 1.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 26, 27, 28, 29). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 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 2 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()
- Line 26: when = bullish and timePeriod → if block
- Line 27: when = bearish → if block
- Line 28: when = bearish and timePeriod → if block
- Line 29: when = bullish → if block
⋯ 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, 1, 1, 0, 0)⋯//RSI-length = input(14)+length = input.int(14)rsi = ta.rsi(close, length)⋯bearish = ta.crossover(slowEMA, fastEMA) and rsi < 50-strategy.entry("Long", strategy.long, when=bullish and timePeriod)+if bullish and timePeriod+ strategy.entry("Long", strategy.long)-strategy.close("Exit", when=bearish)+if bearish+ strategy.close("Exit")-strategy.entry("Short", strategy.short, when=bearish and timePeriod)+if bearish and timePeriod+ strategy.entry("Short", strategy.short)-strategy.close("Exit", when=bullish)+if bullish+ strategy.close("Exit")Does it run in Pine Script v6?
Yes
Same 2 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯// © Coinrule-//@version=5+//@version=6strategy('RSI and SMA',⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 9 ms | Yes 1,000 bars in 39 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('RSI and SMA', overlay=true, initial_capital=1000, process_orders_on_close=true, default_qty_type=strategy.percent_of_equity, default_qty_value=30, commission_type=strategy.commission.percent, commission_value=0.1)showDate = input(defval=true, title='Show Date Range')timePeriod = time >= timestamp(syminfo.timezone, 2022, 1, 1, 0, 0)notInTrade = strategy.position_size <= 0//==================================Buy Conditions============================================//RSIlength = input(14)rsi = ta.rsi(close, length)//SMAfastEMA = ta.sma(close, 100)slowEMA = ta.sma(close, 150)plot(fastEMA, color = color.green)plot(slowEMA, color = color.blue)bullish = ta.crossover(fastEMA, slowEMA) and rsi > 50bearish = ta.crossover(slowEMA, fastEMA) and rsi < 50strategy.entry("Long", strategy.long, when=bullish and timePeriod)strategy.close("Exit", when=bearish)strategy.entry("Short", strategy.short, when=bearish and timePeriod)strategy.close("Exit", when=bullish)