Pine Script v4 · Strategy
B-Xtrender [Backtest Edition] @QuantTherapy
A Pine Script v4 strategy built on RSI or EMA (close, i_short_l2, 15) and EMA or SMA (close, 200). It has 7 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 16 settings; defaults include [Backtest] From Month 1, [Backtest] From Day 1 and [Backtest] From Year 2010.
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 B-Xtrender [Backtest Edition] @QuantTherapy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 38 of 38 trades.
- How did B-Xtrender [Backtest Edition] @QuantTherapy do on BTCUSDT 1D with default settings?
- +24.32%
- From 26 Jan 2024 to 21 Oct 2026, over 87 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can B-Xtrender [Backtest Edition] @QuantTherapy 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 B-Xtrender [Backtest Edition] @QuantTherapy use a stop loss?
- Yes
- strategy.exit sets a stop on line 88, 90.
- Does B-Xtrender [Backtest Edition] @QuantTherapy run in Zeal Terminal?
- Yes
- It compiles in 27 ms and runs 1,000 bars in 75 ms, in the browser.
BTCUSDT · 1D · default settings
- B-Xtrender Osc. - Histogram
- B-Xtrender Trend - Histogram
- B-Xtrender Trend - Line
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +24.32%
- $24,319.80
- Buy and hold
- +102.5%
- same period
- Closed trades
- 87
- 43 won · 44 lost
- Profitable
- 49.4%
- of closed trades
- Profit factor
- 1.28
- gross profit ÷ gross loss
- Max drawdown
- 26.66%
- −$30,759.40
One run with the author's default settings, $100,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
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
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 63, 64, 65, 66. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 34
transp = on line 34, 37, 38, 39, 51, 52. v5 folds the transparency into the colour with color.new(c, transp).
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 rsi → ta.rsi, ema → ta.ema, sma → ta.sma, max → math.max, min → math.min.
- 4 strategy calls use the when = argument (line 63, 64, 65, 66). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 87 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 6: input(type = input.integer) → input.int()
- Line 7: input(type = input.integer) → input.int()
- Line 8: input(type = input.integer) → input.int()
- Line 9: input(type = input.integer) → input.int()
- Line 10: input(type = input.integer) → input.int()
16 more edits
- Line 11: input(type = input.integer) → input.int()
- Line 31: rsi → ta.rsi
- Line 31: ema → ta.ema
- Line 31: ema → ta.ema
- Line 32: rsi → ta.rsi
- Line 32: ema → ta.ema
- Line 34: transp = 40 → color.new(shortXtrenderCol, 40)
- Line 37: transp = 90 → color.new(longXtrenderCol, 90)
- Line 38: transp = 100 → color.new(#000000, 100)
- Line 39: transp = 100 → color.new(macollongXtrenderCol, 100)
- Line 41: ema → ta.ema
- Line 41: sma → ta.sma
- Line 51: transp = 10 → color.new(color.lime, 10)
- Line 52: transp = 10 → color.new(color.red, 10)
- Line 71: max → math.max
- Line 76: min → math.min
⋯// © QuantTherapy-//@version=4+//@version=5strategy("B-Xtrender [Backtest Edition] @QuantTherapy")// === DATE & TIME SELECTION ===-i_fromMonth = input(defval = 1, title = "[Backtest] From Month", type = input.integer, minval = 1, maxval = 12)+i_fromMonth = input.int(defval = 1, title = "[Backtest] From Month", minval = 1, maxval = 12)-i_fromDay = input(defval = 1, title = "[Backtest] From Day", type = input.integer, minval = 1, maxval = 31)+i_fromDay = input.int(defval = 1, title = "[Backtest] From Day", minval = 1, maxval = 31)-i_fromYear = input(defval = 2010, title = "[Backtest] From Year", type = input.integer, minval = 1970)+i_fromYear = input.int(defval = 2010, title = "[Backtest] From Year", minval = 1970)-i_thruMonth = input(defval = 1, title = "[Backtest] Thru Month", type = input.integer, minval = 1, maxval = 12)+i_thruMonth = input.int(defval = 1, title = "[Backtest] Thru Month", minval = 1, maxval = 12)-i_thruDay = input(defval = 1, title = "[Backtest] Thru Day", type = input.integer, minval = 1, maxval = 31)+i_thruDay = input.int(defval = 1, title = "[Backtest] Thru Day", minval = 1, maxval = 31)-i_thruYear = input(defval = 2345, title = "[Backtest] Thru Year", type = input.integer, minval = 1970)+i_thruYear = input.int(defval = 2345, title = "[Backtest] Thru Year", minval = 1970)// === DATE & TIME RANGE FUNCTIONS ===⋯i_ma_type = input("EMA", title="[MA Filter] type", options = ["SMA", "EMA"])-shortTermXtrender = rsi( ema(close, i_short_l1) - ema(close, i_short_l2), i_short_l3 ) - 50+shortTermXtrender = ta.rsi( ta.ema(close, i_short_l1) - ta.ema(close, i_short_l2), i_short_l3 ) - 50-longTermXtrender = rsi( ema(close, i_long_l1), i_long_l2 ) - 50+longTermXtrender = ta.rsi( ta.ema(close, i_long_l1), i_long_l2 ) - 50shortXtrenderCol = shortTermXtrender > 0 ? shortTermXtrender > shortTermXtrender[1] ? color.lime : #228B22 : shortTermXtrender > shortTermXtrender[1] ? color.red : #8B0000-plot(shortTermXtrender, color=shortXtrenderCol, style=plot.style_columns, linewidth=1, title="B-Xtrender Osc. - Histogram", transp = 40)+plot(shortTermXtrender, color=color.new(shortXtrenderCol, 40), style=plot.style_columns, linewidth=1, title="B-Xtrender Osc. - Histogram")longXtrenderCol = longTermXtrender> 0 ? longTermXtrender > longTermXtrender[1] ? color.lime : #228B22 : longTermXtrender > longTermXtrender[1] ? color.red : #8B0000macollongXtrenderCol = longTermXtrender > longTermXtrender[1] ? color.lime : color.red-plot(longTermXtrender , color=longXtrenderCol, style=plot.style_columns, linewidth=2, title="B-Xtrender Trend - Histogram", transp = 90)+plot(longTermXtrender , color=color.new(longXtrenderCol, 90), style=plot.style_columns, linewidth=2, title="B-Xtrender Trend - Histogram")-plot(longTermXtrender , color=#000000 , style=plot.style_line, linewidth=5, title="B-Xtrender Trend - Line", transp = 100)+plot(longTermXtrender , color=color.new(#000000, 100) , style=plot.style_line, linewidth=5, title="B-Xtrender Trend - Line")-plot(longTermXtrender , color=macollongXtrenderCol, style=plot.style_line, linewidth=3, title="B-Xtrender Trend - Line", transp = 100)+plot(longTermXtrender , color=color.new(macollongXtrenderCol, 100), style=plot.style_line, linewidth=3, title="B-Xtrender Trend - Line")// === INIT MA FILTER-ma = i_ma_type == "EMA" ? ema(close, i_ma_len) : sma(close, i_ma_len)+ma = i_ma_type == "EMA" ? ta.ema(close, i_ma_len) : ta.sma(close, i_ma_len)maFilterLong = true⋯closeShort = shortTermXtrender > 0 or longTermXtrender > 0 -plotshape(long[1]==true and long[2]==false ? 0 : na , location=location.absolute, style=shape.labelup , color=color.lime, size=size.small, transp=10)+plotshape(long[1]==true and long[2]==false ? 0 : na , location=location.absolute, style=shape.labelup , color=color.new(color.lime, 10), size=size.small)-plotshape(short[1]==true and short[2]==false ? 0 : na, location=location.absolute, style=shape.labeldown, color=color.red , size=size.small, transp=10)+plotshape(short[1]==true and short[2]==false ? 0 : na, location=location.absolute, style=shape.labeldown, color=color.new(color.red, 10) , size=size.small)plotshape(closeLong[1]==true and closeLong[2]==false⋯ stopValue = close - sl_val- max(stopValue, longStopPrice[1])+ math.max(stopValue, longStopPrice[1])else⋯ stopValue = close + sl_val- min(stopValue, shortStopPrice[1])+ math.min(stopValue, shortStopPrice[1])else⋯Same 87 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 22: input() → input.int()
- Line 23: input() → input.int()
- Line 24: input() → input.int()
- Line 25: input() → input.int()
- Line 26: input() → input.int()
- Line 28: input() → input.bool()
7 more edits
- Line 29: input() → input.int()
- Line 30: input() → input.string()
- Line 55: input() → input.float()
- Line 63: when = toLong → if block
- Line 64: when = closeLong → if block
- Line 65: when = toShort → if block
- Line 66: when = closeShort → if block
⋯// === LONG/ SHORT EXTRENDER SELECTION ===-i_short_l1 = input(5 , title="[Short] L1")+i_short_l1 = input.int(5 , title="[Short] L1")-i_short_l2 = input(20, title="[Short] L2")+i_short_l2 = input.int(20, title="[Short] L2")-i_short_l3 = input(15, title="[Short] L3")+i_short_l3 = input.int(15, title="[Short] L3")-i_long_l1 = input(20, title="[Long] L1")+i_long_l1 = input.int(20, title="[Long] L1")-i_long_l2 = input(15, title="[Long] L2")+i_long_l2 = input.int(15, title="[Long] L2")// === TSL SELECTION ===-i_ma_use = input(true , title="[MA Filter] Yes/No" )+i_ma_use = input.bool(true , title="[MA Filter] Yes/No" )-i_ma_len = input(200 , title="[MA Filter] length" )+i_ma_len = input.int(200 , title="[MA Filter] length" )-i_ma_type = input("EMA", title="[MA Filter] type", options = ["SMA", "EMA"])+i_ma_type = input.string("EMA", title="[MA Filter] type", options = ["SMA", "EMA"])shortTermXtrender = ta.rsi( ta.ema(close, i_short_l1) - ta.ema(close, i_short_l2), i_short_l3 ) - 50⋯ or closeShort[1]==true and closeShort[2]==false ? 0 : na, location=location.absolute, style=shape.circle, color=color.orange , size=size.small)-i_perc = input(defval = 20.0, title = "[TSL-%] Percent" , minval = 0.1 )+i_perc = input.float(defval = 20.0, title = "[TSL-%] Percent" , minval = 0.1 )i_src = close // constant for calculation⋯ strategy.close_all()-strategy.entry("Long", strategy.long, when = toLong ) +if toLong+ strategy.entry("Long", strategy.long ) -strategy.close("Long", when = closeLong)+if closeLong+ strategy.close("Long")-strategy.entry("Short", strategy.short, when = toShort) +if toShort+ strategy.entry("Short", strategy.short) -strategy.close("Short", when = closeShort)+if closeShort+ strategy.close("Short")// Calculate SL⋯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: 87 before, 114 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.
⋯// © QuantTherapy-//@version=5+//@version=6strategy("B-Xtrender [Backtest Edition] @QuantTherapy")⋯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 |
|---|---|---|---|
| [Backtest] From Month | 1 | int (written input.integer) · min 1 · max 12 | start |
| [Backtest] From Day | 1 | int (written input.integer) · min 1 · max 31 | start |
| [Backtest] From Year | 2010 | int (written input.integer) · min 1970 | start |
| [Backtest] Thru Month | 1 | int (written input.integer) · min 1 · max 12 | finish |
| [Backtest] Thru Day | 1 | int (written input.integer) · min 1 · max 31 | finish |
| [Backtest] Thru Year | 2345 | int (written input.integer) · min 1970 | finish |
| [Backtest] Trade Direction | strategy.direction.all | value · options [strategy.direction.all, strategy.direction.long, strategy.direction.short] | line 20 |
| [Short] L1 | 5 | int | shortTermXtrender |
| [Short] L2 | 20 | int | shortTermXtrender |
| [Short] L3 | 15 | int | shortTermXtrender |
| [Long] L1 | 20 | int | longTermXtrender |
| [Long] L2 | 15 | int | longTermXtrender |
| [MA Filter] Yes/No | true | bool | line 44 |
| [MA Filter] length | 200 | int | ma |
| [MA Filter] type | EMA | string · options ["SMA", "EMA"] | ma |
| [TSL-%] Percent | 20.0 | float · min 0.1 | sl_val |
What it calculates
- RSI / EMA (
rsi,ta.rsiin v5)ema(close, i_short_l1) - ema(close, i_short_l2), [Short] L3 (15)shortTermXtrender · line 31 - RSI / EMA (
rsi,ta.rsiin v5)ema(close, i_long_l1), [Long] L2 (15)longTermXtrender · line 32 - EMA / SMA (
ema,ta.emain v5)close, [MA Filter] length (200) · chosen by [MA Filter] typema · line 41
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 |
|---|---|---|---|
| Close | not f_isDate() and strategy.position_size != 0 | On | 62 |
| Open Long long | toLonglong and f_isDate() | On | 63 |
| Close Long | closeLongshortTermXtrender < 0 or longTermXtrender < 0 | On | 64 |
| Open Short short | toShortshort and f_isDate() | On | 65 |
| Close Short | closeShortshortTermXtrender > 0 or longTermXtrender > 0 | On | 66 |
| Exit TSL Long stop | (strategy.position_size > 0) | On | 88 |
| Exit TSL Short stop | (strategy.position_size < 0) | On | 90 |
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 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 | +24.3% | +102.5% | 87 | 49% | 1.28 | 26.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +12.9% | +5.5% | 76 | 53% | 1.88 | 4.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.7% | +9.8% | 32 | 38% | 1.17 | 1.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 33 | 24% | 1.04 | 0.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.1% | +16.7% | 30 | 43% | 1.83 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 29 | 31% | 1.04 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.1% | +148.3% | 39 | 33% | 0.82 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 31 | 32% | 1.13 | 0.1% | 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 | 11 | 36% | $4,825.08 |
| Sideways market | 36 | 56% | $5,976.91 |
| Falling market | 40 | 48% | $13,517.80 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
31.1%
The 95th percentile of the worst drawdown when the same 87 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 14.4% to 31.1%; the tick is what actually happened, 25.1%. Order luck alone moves it this much.
All 87 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 13 Aug 2024 59,346.60 | 14 Aug 2024 60,587.20 | 1 | −$1,240.52 |
| short | 15 Aug 2024 58,683.40 | 16 Aug 2024 57,541.10 | 1 | $1,142.34 |
| short | 17 Aug 2024 58,874.60 | 18 Aug 2024 59,492.00 | 1 | −$617.40 |
| short | 19 Aug 2024 58,427.30 | 20 Aug 2024 59,438.50 | 1 | −$1,011.15 |
| short | 30 Aug 2024 59,359.00 | 31 Aug 2024 59,124.00 | 1 | $235.01 |
| short | 1 Sep 2024 58,974.00 | 2 Sep 2024 57,301.80 | 1 | $1,672.23 |
| short | 3 Sep 2024 59,132.10 | 4 Sep 2024 57,487.70 | 1 | $1,644.38 |
| short | 5 Sep 2024 57,970.90 | 6 Sep 2024 56,180.00 | 1 | $1,790.90 |
| short | 7 Sep 2024 53,963.00 | 8 Sep 2024 54,160.90 | 1 | −$197.89 |
| short | 9 Sep 2024 54,869.90 | 10 Sep 2024 57,042.00 | 1 | −$2,172.06 |
| short | 11 Sep 2024 57,636.00 | 12 Sep 2024 57,338.00 | 1 | $297.99 |
| long | 21 Sep 2024 63,201.10 | 2 Oct 2024 60,804.90 | 11 | −$2,396.13 |
| long | 15 Oct 2024 66,084.00 | 27 Oct 2024 67,092.80 | 12 | $1,008.76 |
| long | 29 Oct 2024 69,962.20 | 4 Nov 2024 68,776.00 | 6 | −$1,186.22 |
| long | 7 Nov 2024 75,572.00 | 27 Nov 2024 91,965.20 | 20 | $16,393.20 |
| long | 17 Dec 2024 106,059.00 | 19 Dec 2024 100,204.00 | 2 | −$5,854.64 |
| long | 7 Jan 2025 102,236.00 | 9 Jan 2025 95,060.60 | 2 | −$7,174.99 |
| long | 16 Jan 2025 100,497.00 | 29 Jan 2025 101,336.00 | 13 | $838.17 |
| long | 31 Jan 2025 104,723.00 | 1 Feb 2025 102,430.00 | 1 | −$2,293.38 |
| short | 27 Feb 2025 84,250.10 | 28 Feb 2025 84,708.60 | 1 | −$458.48 |
| short | 1 Mar 2025 84,349.90 | 2 Mar 2025 86,064.50 | 1 | −$1,714.59 |
| short | 10 Mar 2025 80,734.50 | 11 Mar 2025 78,595.90 | 1 | $2,138.62 |
| short | 12 Mar 2025 82,933.00 | 13 Mar 2025 83,680.10 | 1 | −$747.13 |
| short | 14 Mar 2025 81,115.80 | 15 Mar 2025 83,983.20 | 1 | −$2,867.41 |
| short | 7 Apr 2025 78,430.00 | 8 Apr 2025 79,163.20 | 1 | −$733.24 |
| short | 9 Apr 2025 76,322.40 | 10 Apr 2025 82,615.20 | 1 | −$6,292.80 |
| short | 11 Apr 2025 79,607.30 | 12 Apr 2025 83,423.80 | 1 | −$3,816.53 |
| long | 23 Apr 2025 93,443.00 | 27 May 2025 109,435.00 | 34 | $15,991.80 |
| long | 11 Jun 2025 110,274.00 | 13 Jun 2025 105,672.00 | 2 | −$4,602.65 |
| long | 27 Jun 2025 106,947.00 | 25 Jul 2025 118,341.00 | 28 | $11,393.90 |
| long | 12 Aug 2025 118,686.00 | 17 Aug 2025 117,381.00 | 5 | −$1,305.34 |
| long | 17 Sep 2025 116,789.00 | 23 Sep 2025 112,651.00 | 6 | −$4,137.97 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$5,820.50 |
| short | 18 Oct 2025 106,432.00 | 19 Oct 2025 107,185.00 | 1 | −$753.32 |
| short | 23 Oct 2025 107,567.00 | 24 Oct 2025 110,078.00 | 1 | −$2,510.74 |
| short | 31 Oct 2025 108,323.00 | 1 Nov 2025 109,608.00 | 1 | −$1,285.14 |
| short | 4 Nov 2025 106,583.00 | 5 Nov 2025 101,497.00 | 1 | $5,085.82 |
| short | 6 Nov 2025 103,885.00 | 7 Nov 2025 101,346.00 | 1 | $2,539.12 |
| short | 8 Nov 2025 103,339.00 | 9 Nov 2025 102,313.00 | 1 | $1,026.14 |
| short | 10 Nov 2025 104,723.00 | 11 Nov 2025 106,011.00 | 1 | −$1,288.18 |
| short | 12 Nov 2025 103,059.00 | 13 Nov 2025 101,654.00 | 1 | $1,404.63 |
| short | 14 Nov 2025 99,692.00 | 15 Nov 2025 94,594.00 | 1 | $5,098.03 |
| short | 16 Nov 2025 95,596.20 | 17 Nov 2025 94,261.40 | 1 | $1,334.78 |
| short | 18 Nov 2025 92,215.10 | 19 Nov 2025 92,960.80 | 1 | −$745.69 |
| short | 20 Nov 2025 91,555.00 | 21 Nov 2025 86,637.20 | 1 | $4,917.74 |
| short | 22 Nov 2025 85,129.40 | 23 Nov 2025 84,739.80 | 1 | $389.67 |
| short | 24 Nov 2025 86,830.00 | 25 Nov 2025 88,300.00 | 1 | −$1,470.01 |
| short | 26 Nov 2025 87,370.00 | 27 Nov 2025 90,484.00 | 1 | −$3,114.04 |
| short | 18 Dec 2025 86,243.20 | 19 Dec 2025 85,516.40 | 1 | $726.82 |
| short | 26 Jan 2026 86,670.40 | 27 Jan 2026 88,347.10 | 1 | −$1,676.72 |
| short | 28 Jan 2026 89,250.00 | 29 Jan 2026 89,300.00 | 1 | −$50.01 |
| short | 30 Jan 2026 84,650.20 | 31 Jan 2026 84,260.50 | 1 | $389.66 |
| short | 1 Feb 2026 78,741.10 | 2 Feb 2026 76,968.20 | 1 | $1,772.88 |
| short | 3 Feb 2026 78,738.60 | 4 Feb 2026 75,770.20 | 1 | $2,968.39 |
| short | 5 Feb 2026 73,165.80 | 6 Feb 2026 62,909.90 | 1 | $10,256.00 |
| short | 7 Feb 2026 70,580.30 | 8 Feb 2026 69,289.40 | 1 | $1,290.89 |
| short | 9 Feb 2026 70,330.40 | 10 Feb 2026 70,138.00 | 1 | $192.38 |
| short | 11 Feb 2026 68,841.30 | 12 Feb 2026 67,082.50 | 1 | $1,758.76 |
| short | 13 Feb 2026 66,272.20 | 14 Feb 2026 68,854.00 | 1 | −$2,581.80 |
| short | 15 Feb 2026 69,822.90 | 16 Feb 2026 68,832.60 | 1 | $990.35 |
| short | 23 Mar 2026 67,859.00 | 24 Mar 2026 70,906.40 | 1 | −$3,047.45 |
| short | 28 Mar 2026 66,407.30 | 29 Mar 2026 66,377.00 | 1 | $30.24 |
| short | 30 Mar 2026 66,010.90 | 31 Mar 2026 66,797.40 | 1 | −$786.45 |
| short | 1 Apr 2026 68,284.50 | 2 Apr 2026 68,113.90 | 1 | $170.57 |
| short | 3 Apr 2026 66,902.00 | 4 Apr 2026 66,964.30 | 1 | −$62.30 |
| short | 5 Apr 2026 67,300.40 | 6 Apr 2026 69,034.20 | 1 | −$1,733.76 |
| long | 11 May 2026 82,210.10 | 14 May 2026 79,313.60 | 3 | −$2,896.46 |
| short | 29 May 2026 73,617.50 | 30 May 2026 73,460.80 | 1 | $156.74 |
| short | 31 May 2026 73,884.40 | 1 Jun 2026 73,674.40 | 1 | $209.99 |
| short | 2 Jun 2026 71,408.90 | 3 Jun 2026 66,760.80 | 1 | $4,648.06 |
| short | 4 Jun 2026 64,142.80 | 5 Jun 2026 63,886.00 | 1 | $256.76 |
| short | 6 Jun 2026 61,056.50 | 7 Jun 2026 60,884.60 | 1 | $171.85 |
| short | 8 Jun 2026 63,332.00 | 9 Jun 2026 63,086.00 | 1 | $246.01 |
| short | 10 Jun 2026 61,730.00 | 11 Jun 2026 61,511.00 | 1 | $219.01 |
| short | 12 Jun 2026 63,626.00 | 13 Jun 2026 63,580.00 | 1 | $46.00 |
| short | 14 Jun 2026 64,458.00 | 15 Jun 2026 65,746.40 | 1 | −$1,288.44 |
| short | 26 Jun 2026 59,794.60 | 27 Jun 2026 60,097.30 | 1 | −$302.63 |
| short | 28 Jun 2026 60,029.00 | 29 Jun 2026 59,577.00 | 1 | $452.00 |
| short | 30 Jun 2026 60,260.20 | 1 Jul 2026 58,624.70 | 1 | $1,635.49 |
| short | 2 Aug 2026 62,823.70 | 3 Aug 2026 63,570.00 | 1 | −$746.36 |
| short | 4 Aug 2026 63,520.00 | 5 Aug 2026 64,106.60 | 1 | −$586.55 |
| short | 13 Aug 2026 63,480.00 | 14 Aug 2026 63,490.90 | 1 | −$10.87 |
| short | 15 Aug 2026 63,043.60 | 16 Aug 2026 63,086.00 | 1 | −$42.45 |
| short | 17 Aug 2026 62,900.00 | 18 Aug 2026 64,532.10 | 1 | −$1,632.11 |
| long | 21 Aug 2026 73,027.00 | 3 Sep 2026 77,340.00 | 13 | $4,312.99 |
| long | 4 Sep 2026 81,270.40 | 8 Sep 2026 79,112.00 | 4 | −$2,158.37 |
| long | 21 Sep 2026 81,178.00 | 30 Sep 2026 83,663.70 | 9 | $2,485.65 |
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 |
|---|---|---|---|---|---|
| B-Xtrender [Backtest Edition] @QuantTherapy this page | — | v4 strategy | +24.3% | 87 | 26.7% |
| MACD, RSI, & RVOL Strategy by BobBarker42069 | rsi ema sma | v4 strategy | +32.6% | 1 | 1.5% |
| IFR2 - RSI2 by jocker.soad | rsi sma ema | v4 strategy | No trades on this market | ||
| Vin's Playzone Strategy by Vvaz_ | ema rsi sma | v5 strategy | −908.1% | 21 | 3,570.5% |
| Momentum Explosion 2CCI RSI by capam | ema sma rsi | v4 strategy | +24.1% | 6 | 42.3% |
| 3 x EMA + Stochastic RSI + ATR by tomimarson | ema rsi sma | v4 strategy | −42.3% | 18 | 44.8% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 27 ms | Yes 1,000 bars in 75 ms | Not measured |
| PineTS | No v5 and v6 only | — | 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. 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/// © QuantTherapy//@version=4strategy("B-Xtrender [Backtest Edition] @QuantTherapy")// === DATE & TIME SELECTION ===i_fromMonth = input(defval = 1, title = "[Backtest] From Month", type = input.integer, minval = 1, maxval = 12)i_fromDay = input(defval = 1, title = "[Backtest] From Day", type = input.integer, minval = 1, maxval = 31)i_fromYear = input(defval = 2010, title = "[Backtest] From Year", type = input.integer, minval = 1970)i_thruMonth = input(defval = 1, title = "[Backtest] Thru Month", type = input.integer, minval = 1, maxval = 12)i_thruDay = input(defval = 1, title = "[Backtest] Thru Day", type = input.integer, minval = 1, maxval = 31)i_thruYear = input(defval = 2345, title = "[Backtest] Thru Year", type = input.integer, minval = 1970)// === DATE & TIME RANGE FUNCTIONS ===f_isDate() => // create function "within window of dates" start = timestamp(i_fromYear, i_fromMonth, i_fromDay, 00, 00) // date start finish = timestamp(i_thruYear, i_thruMonth, i_thruDay, 23, 59) // date finish isDate = time >= start and time <= finish // current date is "within window of dates" // === TRADE DIRECTION ===i_tradeDirection = input(title="[Backtest] Trade Direction", defval=strategy.direction.all, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short]) strategy.risk.allow_entry_in(i_tradeDirection)// === LONG/ SHORT EXTRENDER SELECTION ===i_short_l1 = input(5 , title="[Short] L1")i_short_l2 = input(20, title="[Short] L2")i_short_l3 = input(15, title="[Short] L3")i_long_l1 = input(20, title="[Long] L1")i_long_l2 = input(15, title="[Long] L2")// === TSL SELECTION ===i_ma_use = input(true , title="[MA Filter] Yes/No" )i_ma_len = input(200 , title="[MA Filter] length" )i_ma_type = input("EMA", title="[MA Filter] type", options = ["SMA", "EMA"])shortTermXtrender = rsi( ema(close, i_short_l1) - ema(close, i_short_l2), i_short_l3 ) - 50longTermXtrender = rsi( ema(close, i_long_l1), i_long_l2 ) - 50shortXtrenderCol = shortTermXtrender > 0 ? shortTermXtrender > shortTermXtrender[1] ? color.lime : #228B22 : shortTermXtrender > shortTermXtrender[1] ? color.red : #8B0000plot(shortTermXtrender, color=shortXtrenderCol, style=plot.style_columns, linewidth=1, title="B-Xtrender Osc. - Histogram", transp = 40)longXtrenderCol = longTermXtrender> 0 ? longTermXtrender > longTermXtrender[1] ? color.lime : #228B22 : longTermXtrender > longTermXtrender[1] ? color.red : #8B0000macollongXtrenderCol = longTermXtrender > longTermXtrender[1] ? color.lime : color.redplot(longTermXtrender , color=longXtrenderCol, style=plot.style_columns, linewidth=2, title="B-Xtrender Trend - Histogram", transp = 90)plot(longTermXtrender , color=#000000 , style=plot.style_line, linewidth=5, title="B-Xtrender Trend - Line", transp = 100)plot(longTermXtrender , color=macollongXtrenderCol, style=plot.style_line, linewidth=3, title="B-Xtrender Trend - Line", transp = 100)// === INIT MA FILTERma = i_ma_type == "EMA" ? ema(close, i_ma_len) : sma(close, i_ma_len)maFilterLong = truemaFilterShort = trueif i_ma_use maFilterLong := close > ma ? true : false maFilterShort := close < ma ? true : falselong = shortTermXtrender > 0 and longTermXtrender > 0 and maFilterLongcloseLong = shortTermXtrender < 0 or longTermXtrender < 0 short = shortTermXtrender < 0 and longTermXtrender < 0 and maFilterShortcloseShort = shortTermXtrender > 0 or longTermXtrender > 0 plotshape(long[1]==true and long[2]==false ? 0 : na , location=location.absolute, style=shape.labelup , color=color.lime, size=size.small, transp=10)plotshape(short[1]==true and short[2]==false ? 0 : na, location=location.absolute, style=shape.labeldown, color=color.red , size=size.small, transp=10)plotshape(closeLong[1]==true and closeLong[2]==false or closeShort[1]==true and closeShort[2]==false ? 0 : na, location=location.absolute, style=shape.circle, color=color.orange , size=size.small)i_perc = input(defval = 20.0, title = "[TSL-%] Percent" , minval = 0.1 )i_src = close // constant for calculationsl_val = i_src * i_perc / 100toLong = long and f_isDate()toShort = short and f_isDate()// === WHEN POSITION IS OPEN AN DATE IS OUT OF BOUND CLOSE ALL TRADESif not f_isDate() and strategy.position_size != 0 strategy.close_all()strategy.entry("Long", strategy.long, when = toLong ) strategy.close("Long", when = closeLong)strategy.entry("Short", strategy.short, when = toShort) strategy.close("Short", when = closeShort)// Calculate SLlongStopPrice = 0.0, shortStopPrice = 0.0longStopPrice := if (strategy.position_size > 0) stopValue = close - sl_val max(stopValue, longStopPrice[1])else 0shortStopPrice := if (strategy.position_size < 0) stopValue = close + sl_val min(stopValue, shortStopPrice[1])else syminfo.mintick*1000000// For TSL Visualisation on Chart // plot(series=(strategy.position_size > 0) ? longStopPrice : na,// color=color.fuchsia, style = plot.style_circles,// linewidth=1, title="Long Trail Stop") // plot(series=(strategy.position_size < 0) ? shortStopPrice : na,// color=color.fuchsia, style = plot.style_circles,// linewidth=1, title="Short Trail Stop")if (strategy.position_size > 0) strategy.exit(id="TSL Long", stop=longStopPrice)if (strategy.position_size < 0) strategy.exit(id="TSL Short", stop=shortStopPrice)