Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

BTC bot

A Pine Script v4 strategy built on RSI (p, 21), EMA (vrsi, 21) and Crossover (cc, 0). It has 6 order rules, 2 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.075% commission. 12 settings; defaults include Strategy Direction long, Higher TF W and Factor 2.

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 BTC bot repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 8 of 8 trades.
How did BTC bot do on BTCUSDT 1D with default settings?
+12.55%
From 26 Jan 2024 to 21 Oct 2026, over 8 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can BTC bot be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does BTC bot use a stop loss?
Yes
strategy.exit sets a stop on line 52, 53, 54, 55.
Does BTC bot run in Zeal Terminal?
Yes
It compiles in 14 ms and runs 1,000 bars in 56 ms, in the browser.

BTCUSDT · 1D · default settings

  • EMA
  • Crossover
  • Crossover
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOctRSI$11,255$20,253Equity from $10,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. 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. The live re-run is not offered here: the script requests BINANCE:BTCUSDT W, which this page cannot load in your browser.
Net profit
+12.55%
$1,255.25
Buy and hold
+102.5%
same period
Closed trades
8
8 won · 0 lost
Profitable
100.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
11.50%
−$1,150.01

One run with the author's default settings, $10,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

    3 settings have no label

    In the settings dialog higherTF (line 10), factor (line 20), length (line 24) show an empty name. The labels on this page come from the variable names.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames security → request.security, rsi → ta.rsi, ema → ta.ema, crossover → ta.crossover, round → math.round.

v4 → v5

Verified

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

  • Line 4: //@version=4 → //@version=5
  • Line 10: input(type = input.resolution) → input.timeframe()
  • Line 11: security → request.security
  • Line 12: security → request.security
  • Line 13: security → request.security
  • Line 27: rsi → ta.rsi
4 more edits
  • Line 28: ema → ta.ema
  • Line 32: crossover → ta.crossover
  • Line 33: crossover → ta.crossover
  • Line 42: round → math.round
⋯// © theCrypster 2020-//@version=4+//@version=5strategy(title = "BTC bot", overlay = true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)⋯//INPUTS-higherTF = input("W", type=input.resolution)+higherTF = input.timeframe("W")-pc = security(syminfo.tickerid, higherTF, close[1], lookahead=true)+pc = request.security(syminfo.tickerid, higherTF, close[1], lookahead=true)-ph = security(syminfo.tickerid, higherTF, high[1], lookahead=true)+ph = request.security(syminfo.tickerid, higherTF, high[1], lookahead=true)-pl = security(syminfo.tickerid, higherTF, low[1], lookahead=true)+pl = request.security(syminfo.tickerid, higherTF, low[1], lookahead=true)PP = 0.0,R1 = 0.0, R2 = 0.0, R3 = 0.0,S1 = 0.0, S2 = 0.0, S3 = 0.0⋯p = close-vrsi = rsi(p, length)+vrsi = ta.rsi(p, length)-pp=ema(vrsi,length)+pp=ta.ema(vrsi,length)d=(vrsi-pp)*5⋯//-low1=crossover(cc,0)+low1=ta.crossover(cc,0)-sell=crossover(close[1],R3) +sell=ta.crossover(close[1],R3) //⋯per(pcnt) =>-    strategy.position_size != 0 ? round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)+    strategy.position_size != 0 ? math.round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)stoploss=input(title=" stop loss", defval=15, minval=0.01)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 6: input() → input.string()
  • Line 20: input() → input.int()
  • Line 24: input() → input.int()
  • Line 43: input() → input.int()
  • Line 45: input() → input.int()
  • Line 46: input() → input.int()
5 more edits
  • Line 47: input() → input.int()
  • Line 48: input() → input.int()
  • Line 49: input() → input.int()
  • Line 50: input() → input.int()
  • Line 51: input() → input.int()
⋯strategy(title = "BTC bot", overlay = true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)-strat_dir_input = input(title="Strategy Direction", defval="long", options=["long", "short", "all"])+strat_dir_input = input.string(title="Strategy Direction", defval="long", options=["long", "short", "all"])strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.all⋯S2 := PP     - (ph - pl)-factor=input(2)+factor=input.int(2)R3 := ph  + factor * (PP   - pl) ⋯// -length=input(21)+length=input.int(21)//⋯    strategy.position_size != 0 ? math.round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)-stoploss=input(title=" stop loss", defval=15, minval=0.01)+stoploss=input.int(title=" stop loss", defval=15, minval=0.01)los = per(stoploss)-q1=input(title=" qty_percent1", defval=25, minval=1)+q1=input.int(title=" qty_percent1", defval=25, minval=1)-q2=input(title=" qty_percent2", defval=25, minval=1)+q2=input.int(title=" qty_percent2", defval=25, minval=1)-q3=input(title=" qty_percent3", defval=25, minval=1)+q3=input.int(title=" qty_percent3", defval=25, minval=1)-tp1=input(title=" Take profit1", defval=3, minval=0.01)+tp1=input.int(title=" Take profit1", defval=3, minval=0.01)-tp2=input(title=" Take profit2", defval=5, minval=0.01)+tp2=input.int(title=" Take profit2", defval=5, minval=0.01)-tp3=input(title=" Take profit3", defval=7, minval=0.01)+tp3=input.int(title=" Take profit3", defval=7, minval=0.01)-tp4=input(title=" Take profit4", defval=10, minval=0.01)+tp4=input.int(title=" Take profit4", defval=10, minval=0.01)strategy.exit("x1", qty_percent = q1, profit = per(tp1), loss = los)⋯

Does it run in Pine Script v6?

Yes

Same 8 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.

Download the v6 script

⋯// © theCrypster 2020-//@version=5+//@version=6strategy(title = "BTC bot", overlay = true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)⋯

Settings

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

SettingDefaultType and rangeFeeds
Strategy Directionlongstring · options ["long", "short", "all"]strat_dir_value
Higher TF (no label in the script)Wtimeframe (written input.resolution)pc ph pl
Factor (no label in the script)2intR3
Length (no label in the script)21intvrsi pp
stop loss15int · min 0.01los
qty_percent125int · min 1exit x1
qty_percent225int · min 1exit x2
qty_percent325int · min 1exit x3
Take profit13int · min 0.01exit x1
Take profit25int · min 0.01exit x2
Take profit37int · min 0.01exit x3
Take profit410int · min 0.01exit x4

What it calculates

  • RSI (rsi, ta.rsi in v5)p, Length (21)vrsi · line 27
  • EMA (ema, ta.ema in v5)vrsi, Length (21)pp · line 28
  • Crossover (crossover, ta.crossover in v5)cc, 0low1 · line 32
  • Crossover (crossover, ta.crossover in v5)close[1], R3sell · line 33

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.

lengthLengthsetting · 21closecloseprice datastrat_dir_inputStrategy Directionsetting · longhigherTFHigher TFsetting · Whighhighprice datalowlowprice datafactorFactorsetting · 2stoploss stop losssetting · 15vrsiRSI→ vrsippEMA→ pplow1Crossover→ low1sellCrossover→ sellstrat_dir_valuestrat_dir_valuevaluepcpcvaluephphvalueplplvaluePPPPvalueR1R1valueR2, S2, S3R2 · S2 +13 valuesR3R3valueS1S1valueppvalueddvalueccccvaluellvaluessvalueloslosvalueentry:buyOpen buystrategy.entryentry:sellOpen sellstrategy.entryexit:x1exit x1strategy.exitexit:x2exit x2strategy.exitexit:x3exit x3strategy.exitexit:x4exit x4strategy.exit

Order rules

OrderFires whenBy defaultLine
Open buy longlOn38
Open sell shortsOn40
Exit x1 stop and limitevery barOn52
Exit x2 stop and limitevery barOn53
Exit x3 stop and limitevery barOn54
Exit x4 stop and limitevery barOn55

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.

8/8trades 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 data3 security call(s), none with lookahead on.
  • 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+12.6%+102.5%8100%—11.5%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+2.6%+5.5%3100%46.6214.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−9.8%+9.8%2467%0.6728.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−9.4%+8.4%956%0.3819.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+12.6%+16.7%8100%—12.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−14.6%+21.5%520%0.0419.9%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+6.1%+148.3%4100%—12.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.7%+17.1%1100%12.653.1%8 May 2026 – 21 Oct 2026

Higher-timeframe data for request.security(): BINANCE:BTCUSDT W (Binance BTCUSDT 1w), fetched from Binance's public market data for each market.

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market0—$0.00
Sideways market4100%$646.17
Falling market4100%$609.08

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

How bad could the drawdown be?

0.0%

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

0%1%
All 8 trades
SideEntryExitBarsP&L
long7 Feb 2026 70,580.304 Mar 2026 72,697.7025$71.14
long7 Feb 2026 70,580.3016 Mar 2026 74,109.3037$121.06
long7 Feb 2026 70,580.3017 Mar 2026 75,520.9038$170.99
long7 Feb 2026 70,580.3017 Apr 2026 77,638.3069$245.88
long8 Jun 2026 63,332.0014 Jun 2026 65,232.006$75.47
long8 Jun 2026 63,332.0015 Jun 2026 66,498.607$128.44
long8 Jun 2026 63,332.0019 Aug 2026 67,765.3072$181.41
long8 Jun 2026 63,332.0019 Aug 2026 69,665.2072$260.85

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
BTC bot this page—v4 strategy+12.6%811.5%
RSI Cross [xaurr] by livetrendrsi emav4 strategy+24.4%5335.3%
Bitpanda Coinrule Template by joshuajcoop01rsi emav5 strategy−2.8%44.6%
RSI with Slow and Fast MA Crossing Strategy (by Coinrule) by Coinrulersi emav5 strategy−2.8%44.6%
RSI of VWAP by mohaneersi emav4 strategyNo trades on this market
EMA SCALPEUR + RSi - SHORT by YukalMoonrsi emav5 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 14 msWith a workaround 1,000 bars in 56 msNot measured
PineTSNo v5 and v6 only—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. PineTS runs Pine Script v5 and v6 only.

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/// © RafaelZioni// © theCrypster 2020//@version=4strategy(title = "BTC bot", overlay = true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)strat_dir_input = input(title="Strategy Direction", defval="long", options=["long", "short", "all"])strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.allstrategy.risk.allow_entry_in(strat_dir_value)//INPUTShigherTF = input("W", type=input.resolution)pc = security(syminfo.tickerid, higherTF, close[1], lookahead=true)ph = security(syminfo.tickerid, higherTF, high[1], lookahead=true)pl = security(syminfo.tickerid, higherTF, low[1], lookahead=true)PP = 0.0,R1 = 0.0, R2 = 0.0, R3 = 0.0,S1 = 0.0, S2 = 0.0, S3 = 0.0PP := (ph + pl + pc) / 3R1 := PP     + (PP   - pl)S1 := PP     - (ph - PP)R2 := PP     + (ph - pl)S2 := PP     - (ph - pl)factor=input(2)R3 := ph  + factor * (PP   - pl) S3 := pl   - 2 * (ph - PP) // length=input(21)//p = closevrsi = rsi(p, length)pp=ema(vrsi,length)d=(vrsi-pp)*5cc=(vrsi+d+pp)/2//low1=crossover(cc,0)sell=crossover(close[1],R3) //l = low1s=sellif l     strategy.entry("buy", strategy.long)if s     strategy.entry("sell", strategy.short)per(pcnt) =>    strategy.position_size != 0 ? round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)stoploss=input(title=" stop loss", defval=15, minval=0.01)los = per(stoploss)q1=input(title=" qty_percent1", defval=25, minval=1)q2=input(title=" qty_percent2", defval=25, minval=1)q3=input(title=" qty_percent3", defval=25, minval=1)tp1=input(title=" Take profit1", defval=3, minval=0.01)tp2=input(title=" Take profit2", defval=5, minval=0.01)tp3=input(title=" Take profit3", defval=7, minval=0.01)tp4=input(title=" Take profit4", defval=10, minval=0.01)strategy.exit("x1", qty_percent = q1, profit = per(tp1), loss = los)strategy.exit("x2", qty_percent = q2, profit = per(tp2), loss = los)strategy.exit("x3", qty_percent = q3, profit = per(tp3), loss = los)strategy.exit("x4", profit = per(tp4), loss = los)