Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

sma RSI & sudden buy and sell Strategy v1

A Pine Script v5 strategy built on EMA (price, 20), RSI (price, 14) and Highest (price, 20). It has 14 order rules, 7 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. 12 settings; defaults include Length 14, Inst length 10 and Bars 10.

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 sma RSI & sudden buy and sell Strategy v1 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 sma RSI & sudden buy and sell Strategy v1 do on BTCUSDT 1D with default settings?
+7.63%
From 26 Jan 2024 to 21 Oct 2026, over 15 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does sma RSI & sudden buy and sell Strategy v1 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: 15 before, 15 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 sma RSI & sudden buy and sell Strategy v1 use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does sma RSI & sudden buy and sell Strategy v1 run in Zeal Terminal?
Yes
It compiles in 44 ms and runs 1,000 bars in 50 ms, in the browser.

BTCUSDT · 1D · default settings

  • EMA
  • EMA
  • EMA
  • EMA
  • EMA
  • EMA
  • Highest
  • Lowest
  • Crossover
  • Crossover
  • Crossover
  • Crossover
  • Crossover
  • Crossover
  • SMA
  • Crossover
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (12)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOctRSI$1,073,070$2,025,273Equity from $1,000,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference.
Net profit
+7.63%
$76,272.30
Buy and hold
+102.5%
same period
Closed trades
15
7 won · 8 lost
Profitable
46.7%
of closed trades
Profit factor
2.60
gross profit ÷ gross loss
Max drawdown
3.71%
−$37,083.00

One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A short 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

    12 settings have no label

    In the settings dialog length (line 6), inst_length (line 7), bars (line 12), lookbackno2 (line 13), input_ema20 (line 17), input_ema50 (line 19), input_ema100 (line 21), input_ema200 (line 23), input_ema400 (line 25), input_ema800 (line 27), over40 (line 118), over60 (line 119) 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.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Length (no label in the script)14intvrsi buy_diff_rsi sell_diff_rsi sma
Inst length (no label in the script)10intline 94 line 98
Bars (no label in the script)10intline 102 line 110
Lookbackno2 (no label in the script)20inthi2 lo2
Input ema20 (no label in the script)20intema20
Input ema50 (no label in the script)50intema50
Input ema100 (no label in the script)100intema100
Input ema200 (no label in the script)200intema200
Input ema400 (no label in the script)400intema400
Input ema800 (no label in the script)800intema800
Over40 (no label in the script)40intcuu
Over60 (no label in the script)60intcoo

What it calculates

  • EMAprice, Input ema20 (20)ema20 · line 18
  • EMAprice, Input ema50 (50)ema50 · line 20
  • EMAprice, Input ema100 (100)ema100 · line 22
  • EMAprice, Input ema200 (200)ema200 · line 24
  • EMAprice, Input ema400 (400)ema400 · line 26
  • EMAprice, Input ema800 (800)ema800 · line 28
  • RSIprice, Length (14)vrsi · line 29
  • Highestprice, Lookbackno2 (20)hi2 · line 30
  • Lowestprice, Lookbackno2 (20)lo2 · line 31
  • RSIclose[1], Length (14)buy_diff_rsi · line 32
  • RSIclose[1], Length (14)sell_diff_rsi · line 33
  • Crossoverprice, ema800co_800 · line 51
  • Crossoverprice, ema400co_400 · line 52
  • Crossoverprice, ema200co_200 · line 53
  • Crossoverprice, ema100co_100 · line 54
  • Crossoverprice, ema50co_50 · line 55
  • Crossoverprice, ema20co_20 · line 56
  • SMAvrsi, Length (14)sma · line 120
  • Crossoversma, Over60 (60)coo · line 121
  • Crossundersma, Over40 (40)cuu · line 122

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.

input_ema20Input ema20setting · 20input_ema50Input ema50setting · 50input_ema100Input ema100setting · 100input_ema200Input ema200setting · 200input_ema400Input ema400setting · 400input_ema800Input ema800setting · 800lengthLengthsetting · 14lookbackno2Lookbackno2setting · 20closecloseprice dataover60Over60setting · 60over40Over40setting · 40openopenprice dataema20EMA→ ema20ema50EMA→ ema50ema100EMA→ ema100ema200EMA→ ema200ema400EMA→ ema400ema800EMA→ ema800vrsiRSI→ vrsihi2Highest→ hi2lo2Lowest→ lo2buy_diff_rsiRSI→ buy_diff_rsisell_diff_rsiRSI→ sell_diff_rsico_800Crossover→ co_800co_400Crossover→ co_400co_200Crossover→ co_200co_100Crossover→ co_100co_50Crossover→ co_50co_20Crossover→ co_20smaSMA→ smacooCrossover→ coocuuCrossunder→ cuuprice, sudSC, sudBCprice · sudSC +13 valuessudSO, sudBOsudSO · sudBO2 valuessudbcountsudbcountvaluesudscountsudscountvalueclose:SellClose Sellstrategy.closeentry:BuyOpen Buystrategy.entryclose:BuyClose Buystrategy.closeentry:SellOpen Sellstrategy.entry

Order rules

OrderFires whenBy defaultLine
Close Sell(co_200)On75
Open Buy long(co_200)On76
Close Buy(vrsi > 90)On83
Open Sell short(vrsi > 90)On84
Close Sell(vrsi < 10)On86
Open Buy long(vrsi < 10)On87
Close Sell(sudBC < price)On104
Open Buy long(sudBC < price)On105
Close Buy(sudSC > price)On112
Open Sell short(sudSC > price)On113
Close Sell(coo)On124
Open Buy long(coo)On125
Close Buy(cuu)On127
Open Sell short(cuu)On128

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.

3/3trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+7.6%+102.5%1547%2.603.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.5%+5.5%1346%1.901.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.6%+9.8%978%6.820.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.0%+8.4%1527%0.740.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.0%+16.7%1932%0.230.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%1338%1.130.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.1%+148.3%1942%1.930.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%1233%0.930.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 barsTradesWonP&L
Rising market450%$11,432.80
Sideways market1040%$44,058.50
Falling market1100%$20,781.00

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

3.5%

The 95th percentile of the worst drawdown when the same 15 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.4% to 3.5%; the tick is what actually happened, 3.5%. Order luck alone moves it this much.

0%4%
All 15 trades
SideEntryExitBarsP&L
long14 May 2024 62,940.1026 Jun 2024 61,806.0043−$1,134.08
short26 Jun 2024 61,806.0028 Jul 2024 67,896.5032−$6,090.48
long28 Jul 2024 67,896.5013 Aug 2024 59,346.6016−$8,549.85
short13 Aug 2024 59,346.6029 Sep 2024 65,858.0047−$6,511.36
long29 Sep 2024 65,858.0011 Oct 2024 60,326.4012−$5,531.60
short11 Oct 2024 60,326.4023 Oct 2024 67,426.0012−$7,099.61
long23 Oct 2024 67,426.0020 Dec 2024 97,461.9058$30,035.90
short20 Dec 2024 97,461.9020 Apr 2025 85,077.00121$12,384.90
long20 Apr 2025 85,077.003 Jun 2025 105,858.0044$20,781.00
short3 Jun 2025 105,858.004 Jul 2025 109,585.0031−$3,726.77
long4 Jul 2025 109,585.0025 Aug 2025 113,494.0052$3,908.82
short25 Aug 2025 113,494.0021 Apr 2026 75,841.00239$37,652.60
long21 Apr 2026 75,841.003 Jun 2026 66,760.8043−$9,080.13
short3 Jun 2026 66,760.8018 Jun 2026 64,509.4015$2,251.44
long18 Jun 2026 64,509.4018 Oct 2026 81,491.00122$16,981.60

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
sma RSI & sudden buy and sell Strategy v1 this page—v5 strategy+7.6%153.7%
MZ SRSI Strategy V1.0 by MightyZingerema sma highest lowest rsiv4 strategyNo trades on this market
STRATEGY R18-F-BTC by SenatorVonShaftema highest lowest rsiv4 strategy−8.6%1114.4%
Forex bot full strategy with risk management by exlux99lowest highest ema smav4 strategy−26.4%1138.9%
Stochastic RSI by Zeal Terminalrsi highest lowest smav5 indicatorindicator
Bear & Bull Zone Signal Strategy by Solutions1978rsi ema highest lowest smav4 strategyNo trades on this market

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.

  • 5 settings use the untyped input() (line 6, 7, 12, 118, 119). 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

VerifiedDownload the v5 script

Same 15 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 6: input() → input.int()
  • Line 7: input() → input.int()
  • Line 12: input() → input.int()
  • Line 118: input() → input.int()
  • Line 119: input() → input.int()
⋯price = close-length = input( 14 )+length = input.int( 14 )-inst_length = input( 10 )+inst_length = input.int( 10 )var rbc = 0⋯var float rsiSP = 0.0-bars = input(10)+bars = input.int(10)lookbackno2 = input.int(20)⋯    sudS := 0-over40 = input( 40 )+over40 = input.int( 40 )-over60 = input( 60 )+over60 = input.int( 60 )sma =ta.sma(vrsi, 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: 15 before, 15 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.

⋯// © samwillington-//@version=5+//@version=6strategy("sma RSI & sudden buy and sell Strategy v1", overlay=true)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 44 msYes 1,000 bars in 50 msNot measured
PineTSNot testedNot testedNot 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/// © samwillington//@version=5strategy("sma RSI & sudden buy and sell Strategy v1", overlay=true)price = closelength = input( 14 )inst_length = input( 10 )var rbc = 0var float rsiBP = 0.0var rsc = 0var float rsiSP = 0.0bars = input(10)lookbackno2 = input.int(20)rsi_buy = 0rsi_sell = 0//EMA inputsinput_ema20 = input.int(20)ema20 = ta.ema(price, input_ema20)input_ema50 = input.int(50)ema50 = ta.ema(price, input_ema50)input_ema100 = input.int(100)ema100 = ta.ema(price, input_ema100)input_ema200 = input.int(200)ema200 = ta.ema(price, input_ema200)input_ema400 = input.int(400)ema400 = ta.ema(price, input_ema400)input_ema800 = input.int(800)ema800 = ta.ema(price, input_ema800)vrsi = ta.rsi(price, length)hi2 = ta.highest(price, lookbackno2)lo2 = ta.lowest(price, lookbackno2)buy_diff_rsi = vrsi - ta.rsi(close[1], length)sell_diff_rsi = ta.rsi(close[1],length) - vrsi//RSI high lowvar int sudS = 0var int sudB = 0var float sudSO = 0.0var float sudSC = 0.0var float sudBO = 0.0var float sudBC = 0.0var sudBuy = 0var sudSell = 0 var countB = 0var countS = 0var co_800 = falsevar co_400 = falsevar co_200 = falsevar co_100 = falsevar co_50 = falsevar co_20 = falseco_800 := ta.crossover(price , ema800)co_400 := ta.crossover(price , ema400)co_200 := ta.crossover(price , ema200)co_100 := ta.crossover(price , ema100)co_50 := ta.crossover(price , ema50)co_20 := ta.crossover(price , ema20)if(ta.crossunder(price , ema20))    co_20 := falseif(ta.crossunder(price , ema50))    co_50 := falseif(ta.crossunder(price , ema100))    co_100 := falseif(ta.crossunder(price , ema200))    co_200 := falseif(ta.crossunder(price , ema400))    co_400 := falseif(ta.crossunder(price , ema800))    co_800 := false    if((price> ema800) and (price > ema400))    if(co_20)        if(co_50)            if(co_100)                if(co_200)                    strategy.close("Sell")                    strategy.entry("Buy", strategy.long, comment="spl Buy")                    co_20 := false                    co_50 := false                    co_100 := false                    co_200 := false// too much rsiif(vrsi > 90)    strategy.close("Buy")    strategy.entry("Sell", strategy.short, comment="RSI too overbuy")if(vrsi < 10)    strategy.close("Sell")    strategy.entry("Buy", strategy.long, comment="RSI too oversold")var sudbcount = 0  // counting no. of bars till sudden risevar sudscount = 0  // counting no. of bars till sudden decreaseif(sudB == 1)    sudbcount := sudbcount + 1if(sudS == 1)    sudscount := sudscount + 1if((buy_diff_rsi > inst_length) and (hi2 > price))    sudB := 1    sudBO := open    sudBC := closeif((sell_diff_rsi > inst_length) )    sudS := 1    sudSO := open    sudSC := close   if(sudbcount == bars)    if(sudBC < price)        strategy.close("Sell")        strategy.entry("Buy", strategy.long, comment="sudd buy")        sudbcount := 0        sudB := 0    sudbcount := 0    sudB := 0if(sudscount == bars)     if(sudSC > price)        strategy.close("Buy")        strategy.entry("Sell", strategy.short, comment="sudd sell")        sudscount := 0        sudS := 0    sudscount := 0    sudS := 0over40 = input( 40 )over60 = input( 60 )sma =ta.sma(vrsi, length)coo = ta.crossover(sma, over60)cuu = ta.crossunder(sma, over40)if (coo)    strategy.close("Sell")    strategy.entry("Buy", strategy.long, comment="modified buy")if (cuu)    strategy.close("Buy")    strategy.entry("Sell", strategy.short, comment="modefied sell")//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)