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
- 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
VerifiedSame 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)⋯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.
⋯// © 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Strategy Direction | long | string · options ["long", "short", "all"] | strat_dir_value |
| Higher TF (no label in the script) | W | timeframe (written input.resolution) | pc ph pl |
| Factor (no label in the script) | 2 | int | R3 |
| Length (no label in the script) | 21 | int | vrsi pp |
| stop loss | 15 | int · min 0.01 | los |
| qty_percent1 | 25 | int · min 1 | exit x1 |
| qty_percent2 | 25 | int · min 1 | exit x2 |
| qty_percent3 | 25 | int · min 1 | exit x3 |
| Take profit1 | 3 | int · min 0.01 | exit x1 |
| Take profit2 | 5 | int · min 0.01 | exit x2 |
| Take profit3 | 7 | int · min 0.01 | exit x3 |
| Take profit4 | 10 | int · min 0.01 | exit x4 |
What it calculates
- RSI (
rsi,ta.rsiin v5)p, Length (21)vrsi · line 27 - EMA (
ema,ta.emain v5)vrsi, Length (21)pp · line 28 - Crossover (
crossover,ta.crossoverin v5)cc, 0low1 · line 32 - Crossover (
crossover,ta.crossoverin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open buy long | l | On | 38 |
| Open sell short | s | On | 40 |
| Exit x1 stop and limit | every bar | On | 52 |
| Exit x2 stop and limit | every bar | On | 53 |
| Exit x3 stop and limit | every bar | On | 54 |
| Exit x4 stop and limit | every bar | On | 55 |
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 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +12.6% | +102.5% | 8 | 100% | — | 11.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +2.6% | +5.5% | 3 | 100% | 46.62 | 14.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −9.8% | +9.8% | 24 | 67% | 0.67 | 28.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −9.4% | +8.4% | 9 | 56% | 0.38 | 19.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +12.6% | +16.7% | 8 | 100% | — | 12.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −14.6% | +21.5% | 5 | 20% | 0.04 | 19.9% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +6.1% | +148.3% | 4 | 100% | — | 12.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.7% | +17.1% | 1 | 100% | 12.65 | 3.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 0 | — | $0.00 |
| Sideways market | 4 | 100% | $646.17 |
| Falling market | 4 | 100% | $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.
All 8 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 7 Feb 2026 70,580.30 | 4 Mar 2026 72,697.70 | 25 | $71.14 |
| long | 7 Feb 2026 70,580.30 | 16 Mar 2026 74,109.30 | 37 | $121.06 |
| long | 7 Feb 2026 70,580.30 | 17 Mar 2026 75,520.90 | 38 | $170.99 |
| long | 7 Feb 2026 70,580.30 | 17 Apr 2026 77,638.30 | 69 | $245.88 |
| long | 8 Jun 2026 63,332.00 | 14 Jun 2026 65,232.00 | 6 | $75.47 |
| long | 8 Jun 2026 63,332.00 | 15 Jun 2026 66,498.60 | 7 | $128.44 |
| long | 8 Jun 2026 63,332.00 | 19 Aug 2026 67,765.30 | 72 | $181.41 |
| long | 8 Jun 2026 63,332.00 | 19 Aug 2026 69,665.20 | 72 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| BTC bot this page | — | v4 strategy | +12.6% | 8 | 11.5% |
| RSI Cross [xaurr] by livetrend | rsi ema | v4 strategy | +24.4% | 53 | 35.3% |
| Bitpanda Coinrule Template by joshuajcoop01 | rsi ema | v5 strategy | −2.8% | 4 | 4.6% |
| RSI with Slow and Fast MA Crossing Strategy (by Coinrule) by Coinrule | rsi ema | v5 strategy | −2.8% | 4 | 4.6% |
| RSI of VWAP by mohanee | rsi ema | v4 strategy | No trades on this market | ||
| EMA SCALPEUR + RSi - SHORT by YukalMoon | rsi ema | v5 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 14 ms | With a workaround 1,000 bars in 56 ms | Not measured |
| PineTS | No 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)