Pine Script v5 · Strategy
Bull Trend Filtered StochRSI (BTFS)
A Pine Script v5 strategy built on Highest or EMA (high,filter_ema_len, 30), RSI (close, 14) and SMA or Stoch (7). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays no commission. 8 settings; defaults include Filter ema len 6, EMA donchian len 30 and K 7.
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 Bull Trend Filtered StochRSI (BTFS) repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
- How did Bull Trend Filtered StochRSI (BTFS) do on BTCUSDT 1D with default settings?
- +36.89%
- From 26 Jan 2024 to 21 Oct 2026, over 21 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Bull Trend Filtered StochRSI (BTFS) 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: 21 before, 20 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 Bull Trend Filtered StochRSI (BTFS) use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Bull Trend Filtered StochRSI (BTFS) run in Zeal Terminal?
- Yes
- It compiles in 16 ms and runs 1,000 bars in 39 ms, in the browser.
BTCUSDT · 1D · default settings
- K
- D
- Upper Band
- Middle Band
- Lower Band
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +36.89%
- $368,864.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 21
- 9 won · 12 lost
- Profitable
- 42.9%
- of closed trades
- Profit factor
- 1.59
- gross profit ÷ gross loss
- Max drawdown
- 21.54%
- −$281,976.00
One run with the author's default settings, $1,000,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 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.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
3 settings have no label
In the settings dialog filter_ema_len (line 6), ema_donchian_len (line 7), lowerband (line 22) 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Filter ema len (no label in the script) | 6 | int | ema |
| EMA donchian len (no label in the script) | 30 | int | ema |
| K | 7 | int · min 1 | k |
| D | 4 | int · min 1 | d |
| RSI Length | 14 | int · min 1 | rsi1 |
| Stochastic Length | 14 | int · min 1 | k |
| RSI Source | close | source | rsi1 |
| Lowerband (no label in the script) | 35 | int | h11 longCondition shortCondition hline |
What it calculates
- Highest / EMAta.ema(high,filter_ema_len), EMA donchian len (30)
ema · line 8 - RSIRSI Source (close), RSI Length (14)
rsi1 · line 15 - SMA / Stochta.stoch(rsi1, rsi1, rsi1, lengthStoch), K (7)
k · line 16 - SMAk, D (4)
d · line 17 - Crossunderk, Lowerband (35)
shortCondition · line 30
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 Up long | (longCondition) | On | 29 |
| Close Up | (shortCondition) | On | 32 |
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 | +36.9% | +102.5% | 21 | 43% | 1.59 | 21.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +11.0% | +5.5% | 16 | 31% | 1.65 | 8.8% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +75.5% | +9.8% | 17 | 59% | 1.86 | 29.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +24.6% | +8.4% | 14 | 29% | 2.03 | 9.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +55.9% | +16.7% | 17 | 47% | 1.65 | 28.6% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +28.5% | +21.5% | 13 | 38% | 2.41 | 7.7% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −19.0% | +148.3% | 24 | 38% | 0.77 | 45.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +9.0% | +17.1% | 18 | 39% | 1.54 | 10.3% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (Filter ema len 7, EMA donchian len 30) made +22.1% before 26 Dec 2025 and +17.2% after it, against +16.9% for the defaults. 59% of the 56 combinations made money in-sample and 100% out-of-sample.
| EMA donchian len ↓ · Filter ema len → | 3 | 4 | 5 | 6 | 7 | 8 | 10 |
|---|---|---|---|---|---|---|---|
| 15 | −11% | −8% | −11% | −9% | −9% | −15% | −14% |
| 18 | −9% | +3% | −3% | +0% | +0% | −4% | +6% |
| 21 | −3% | −1% | −6% | −4% | −4% | +0% | +1% |
| 26 | +8% | +7% | +1% | +12% | +13% | +0% | +2% |
| 30 | +15% | +11% | −0% | +20% | +22% | +8% | +11% |
| 36 | +7% | +4% | +0% | +9% | +10% | −1% | +1% |
| 42 | +14% | −7% | −10% | +0% | +1% | −10% | −2% |
| 51 | +16% | +5% | +1% | +3% | +3% | −9% | −3% |
| EMA donchian len ↓ · Filter ema len → | 3 | 4 | 5 | 6 | 7 | 8 | 10 |
|---|---|---|---|---|---|---|---|
| 15 | +20% | +23% | +23% | +23% | +22% | +21% | +21% |
| 18 | +21% | +22% | +21% | +23% | +23% | +21% | +21% |
| 21 | +17% | +20% | +19% | +19% | +19% | +17% | +20% |
| 26 | +13% | +15% | +14% | +16% | +16% | +14% | +18% |
| 30 | +7% | +11% | +14% | +17% | +17% | +15% | +16% |
| 36 | +11% | +5% | +9% | +10% | +10% | +9% | +16% |
| 42 | +16% | +11% | +14% | +16% | +16% | +14% | +15% |
| 51 | +16% | +15% | +18% | +19% | +19% | +17% | +18% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. 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 | 10 | 50% | $218,021.00 |
| Sideways market | 9 | 33% | $161,890.00 |
| Falling market | 2 | 50% | −$11,047.50 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
31.3%
The 95th percentile of the worst drawdown when the same 21 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 14.0% to 31.3%; the tick is what actually happened, 18.6%. Order luck alone moves it this much.
All 21 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 29 Feb 2024 62,432.10 | 11 Mar 2024 68,955.90 | 11 | $104,494.00 |
| long | 14 Mar 2024 73,072.40 | 16 Mar 2024 69,499.80 | 2 | −$53,999.50 |
| long | 18 May 2024 67,024.00 | 1 Jun 2024 67,540.00 | 14 | $8,087.63 |
| long | 6 Jun 2024 71,108.00 | 13 Jun 2024 68,264.00 | 7 | −$42,338.80 |
| long | 21 Jul 2024 67,140.00 | 3 Aug 2024 61,498.30 | 13 | −$85,392.80 |
| long | 25 Sep 2024 64,262.70 | 5 Oct 2024 62,086.00 | 10 | −$31,529.70 |
| long | 15 Oct 2024 66,084.00 | 5 Nov 2024 67,850.00 | 21 | $24,033.20 |
| long | 9 Nov 2024 76,509.80 | 29 Nov 2024 95,644.00 | 20 | $230,920.00 |
| long | 14 Dec 2024 101,424.00 | 23 Dec 2024 95,186.30 | 9 | −$70,992.10 |
| long | 19 Jan 2025 104,556.00 | 1 Feb 2025 102,430.00 | 13 | −$22,033.90 |
| long | 22 Apr 2025 87,516.20 | 29 May 2025 107,782.00 | 37 | $245,746.00 |
| long | 11 Jun 2025 110,274.00 | 20 Jun 2025 104,659.00 | 9 | −$66,559.60 |
| long | 4 Jul 2025 109,585.00 | 25 Jul 2025 118,341.00 | 21 | $99,115.10 |
| long | 13 Aug 2025 120,134.00 | 20 Aug 2025 112,873.00 | 7 | −$80,965.00 |
| long | 2 Oct 2025 118,595.00 | 15 Oct 2025 113,028.00 | 13 | −$59,078.10 |
| long | 6 Jan 2026 93,859.70 | 22 Jan 2026 89,454.70 | 16 | −$56,294.70 |
| long | 16 Mar 2026 72,815.30 | 25 Mar 2026 70,556.70 | 9 | −$35,459.00 |
| long | 14 Apr 2026 74,418.00 | 18 May 2026 77,457.70 | 34 | $45,247.20 |
| long | 21 Jul 2026 65,255.50 | 30 Jul 2026 63,984.30 | 9 | −$22,461.20 |
| long | 20 Aug 2026 69,334.80 | 5 Sep 2026 79,660.80 | 16 | $168,371.00 |
| long | 21 Sep 2026 81,178.00 | 7 Oct 2026 85,549.90 | 16 | $69,954.20 |
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 |
|---|---|---|---|---|---|
| Bull Trend Filtered StochRSI (BTFS) this page | — | v5 strategy | +36.9% | 21 | 21.5% |
| Bear & Bull Zone Signal Strategy by Solutions1978 | rsi ema highest stoch sma | v4 strategy | No trades on this market | ||
| sma RSI & sudden buy and sell Strategy v1 by samwillington | ema rsi highest sma | v5 strategy | +7.6% | 15 | 3.7% |
| RSI Mean Reversion Bot Strategy by Solutions1978 | rsi ema stoch sma | v4 strategy | No trades on this market | ||
| All in One Strategy no RSI Label - For higher dollar crypto by Solutions1978 | rsi ema highest stoch sma | v4 strategy | No trades on this market | ||
| All in One Strategy by Solutions1978 | rsi ema highest stoch sma | v4 strategy | No 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.
- 4 settings use the untyped input() (line 6, 7, 14, 22). 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 21 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 14: input() → input.source()
- Line 22: input() → input.int()
⋯/////high filter...upper donchian channel of ema... or highest ema for a given amount of candles-filter_ema_len= input(6)+filter_ema_len= input.int(6)-ema_donchian_len = input(30)+ema_donchian_len = input.int(30)ema=ta.highest(ta.ema(high,filter_ema_len),ema_donchian_len)⋯lengthStoch = input.int(14, "Stochastic Length", minval=1)-src = input(close, title="RSI Source")+src = input.source(close, title="RSI Source")rsi1 = ta.rsi(src, lengthRSI)⋯hline(50, "Middle Band", color=color.new(#787B86, 50))-lowerband=input(35)+lowerband=input.int(35)h11 = hline(lowerband, "Lower Band", color=#787B86)⋯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: 21 before, 20 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.
⋯// © SnarkyPuppy-//@version=5+//@version=6strategy("Filtered Stoch", overlay=false, default_qty_value = 100, default_qty_type=strategy.percent_of_equity)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 16 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/// © SnarkyPuppy//@version=5strategy("Filtered Stoch", overlay=false, default_qty_value = 100, default_qty_type=strategy.percent_of_equity)/////high filter...upper donchian channel of ema... or highest ema for a given amount of candlesfilter_ema_len= input(6)ema_donchian_len = input(30)ema=ta.highest(ta.ema(high,filter_ema_len),ema_donchian_len)////////////////////////basic stoch rsi with max val 100 and min val 0.. entry above lowerband preset 35smoothK = input.int(7, "K", minval=1)smoothD = input.int(4, "D", minval=1)lengthRSI = input.int(14, "RSI Length", minval=1)lengthStoch = input.int(14, "Stochastic Length", minval=1)src = input(close, title="RSI Source")rsi1 = ta.rsi(src, lengthRSI)k = math.min(100, math.max(0,ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)))d = math.max(math.min(ta.sma(k, smoothD),80),35)plot(k, "K", color=#2962FF)plot(d, "D", color=#FF6D00)h0 = hline(80, "Upper Band", color=#787B86)hline(50, "Middle Band", color=color.new(#787B86, 50))lowerband=input(35)h11 = hline(lowerband, "Lower Band", color=#787B86)fill(h0, h11, color=color.rgb(33, 150, 243, 90), title="Background")ematrend= close>ema ? 1 : 0bgcolor(ematrend==1?color.rgb(76, 175, 79, 80):na)longCondition = k>lowerband and ematrend==1if (longCondition) strategy.entry("Up", strategy.long)shortCondition = ta.crossunder(k,lowerband)if (shortCondition) strategy.close("Up", shortCondition)