Pine Script v5 · Strategy
Range Filter - B&S Signals - 001 - edited
A Pine Script v5 strategy built on EMA (x - x[1], n). It has 4 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. 11 settings; defaults include Long Stop Loss (%) 1, Short Stop Loss (%) 1 and Long Take(%) 1.
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 Range Filter - B&S Signals - 001 - edited repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Range Filter - B&S Signals - 001 - edited do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- What alerts does Range Filter - B&S Signals - 001 - edited have?
- 2
- Buy Alert; Sell Alert.
- Does Range Filter - B&S Signals - 001 - edited run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L80:C70: 'plot' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download.
- Does Range Filter - B&S Signals - 001 - edited use a stop loss?
- Yes
- strategy.exit sets a stop on line 102, 104.
BTCUSDT · 1D · default settings
- Filter
- Plot
- Buy Signal
- Sell Signal
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $1,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
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 90, 93. The upgraded version below moves each call inside an if block.
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 Start | timestamp('01 Jan 2020 12:00 +0000') | time | inDateRange |
| Backtest End | timestamp('01 Jan 2024 12:00 +0000') | time | inDateRange |
| Long Stop Loss (%) | 1 | float · min 0.0 · step 0.1 | longStopPrice |
| Short Stop Loss (%) | 1 | float · min 0.0 · step 0.1 | shortStopPrice |
| Long Take(%) | 1 | float · min 0.0 · step 0.1 | longTakePrice |
| Short Take (%) | 1 | float · min 0.0 · step 0.1 | shortTakePrice |
| EMA Length | 200 | int | ema |
| Swing Source | close | source | h_band l_band filt longCond shortCond bar_color |
| Swing Period | 20 | int · min 1 | h_band l_band filt |
| Swing Multiplier | 3.5 | float · min 0.0000001 | h_band l_band filt |
| Bar Colors On/Off | false | bool | barcolor |
What it calculates
- EMAmath.abs(x - x[1]), n
avrng · line 22 - EMAavrng, wper
AC · line 23 - EMAclose, EMA Length (200)
ema · line 71
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 Long long | longConditionlongCond and CondIni[1] == -1 | On | 90 |
| Open Short short | shortConditionshortCond and CondIni[1] == 1 | On | 93 |
| Exit Long stop and limit | strategy.position_size > 0 | On | 102 |
| Exit Short stop and limit | strategy.position_size < 0 | On | 104 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Buy Alert | alertcondition | BUY | 99 |
| Sell Alert | alertcondition | SELL | 100 |
Does it repaint?
No
No repainting patterns in the source.
- 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 | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
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 |
|---|---|---|---|---|---|
| Range Filter - B&S Signals - 001 - edited this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
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.
- 2 strategy calls use the when = argument (line 90, 93). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 2 settings use the untyped input() (line 44, 50). 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
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 44: input() → input.source()
- Line 50: input() → input.bool()
- Line 90: when = longCondition → if block
- Line 93: when = shortCondition → if block
⋯//Range Source-rng_src = input(defval=close, title='Swing Source')+rng_src = input.source(defval=close, title='Swing Source')//Range Period⋯//Bar Colors-use_barcolor = input(defval=false, title='Bar Colors On/Off')+use_barcolor = input.bool(defval=false, title='Bar Colors On/Off')//-----------------------------------------------------------------------------------------------------------------------------------------------------------------⋯if inDateRange and close>ema- strategy.entry("Long", strategy.long, when=longCondition)+ if longCondition+ strategy.entry("Long", strategy.long) if inDateRange and close<ema- strategy.entry("Short", strategy.short, when=shortCondition)+ if shortCondition+ strategy.entry("Short", strategy.short)plot(ema)⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L80:C70: 'plot' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// This version is the old version of the Range Filter with less settings to tinker with-//@version=5+//@version=6strategy(title='Range Filter - B&S Signals', shorttitle='RF - B&S Signals', initial_capital=1000, currency=currency.GBP, default_qty_value=100, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.075, overlay=true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 25 ms | Yes 1,000 bars in 79 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/// Credits to the original Script - Range Filter DonovanWall https://www.tradingview.com/script/lut7sBgG-Range-Filter-DW/// This version is the old version of the Range Filter with less settings to tinker with//@version=5strategy(title='Range Filter - B&S Signals', shorttitle='RF - B&S Signals', initial_capital=1000, currency=currency.GBP, default_qty_value=100, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.075, overlay=true)i_startTime = input.time(defval=timestamp('01 Jan 2020 12:00 +0000'), title='Backtest Start')i_endTime = input.time(defval=timestamp('01 Jan 2024 12:00 +0000'), title='Backtest End')inDateRange = time >= i_startTime and time <= i_endTime//-----------------------------------------------------------------------------------------------------------------------------------------------------------------//Functions//-----------------------------------------------------------------------------------------------------------------------------------------------------------------longLossPerc = input.float(title='Long Stop Loss (%)', minval=0.0, step=0.1, defval=1) * 0.01shortLossPerc = input.float(title='Short Stop Loss (%)', minval=0.0, step=0.1, defval=1) * 0.01longTakePerc = input.float(title='Long Take(%)', minval=0.0, step=0.1, defval=1) * 0.01shortTakePerc = input.float(title='Short Take (%)', minval=0.0, step=0.1, defval=1) * 0.01emaLength = input.int(200, title="EMA Length") // Determine stop loss price//Range Size Functionrng_size(x, qty, n) =>// AC = Cond_EMA(abs(x - x[1]), 1, n) wper = n * 2 - 1 avrng = ta.ema(math.abs(x - x[1]), n) AC = ta.ema(avrng, wper) * qty rng_size = AC rng_size//Range Filter Functionrng_filt(x, rng_, n) => r = rng_ var rfilt = array.new_float(2, x) array.set(rfilt, 1, array.get(rfilt, 0)) if x - r > array.get(rfilt, 1) array.set(rfilt, 0, x - r) if x + r < array.get(rfilt, 1) array.set(rfilt, 0, x + r) rng_filt1 = array.get(rfilt, 0) hi_band = rng_filt1 + r lo_band = rng_filt1 - r rng_filt = rng_filt1 [hi_band, lo_band, rng_filt]//-----------------------------------------------------------------------------------------------------------------------------------------------------------------//Inputs//-----------------------------------------------------------------------------------------------------------------------------------------------------------------//Range Sourcerng_src = input(defval=close, title='Swing Source')//Range Periodrng_per = input.int(defval=20, minval=1, title='Swing Period')//Range Size Inputsrng_qty = input.float(defval=3.5, minval=0.0000001, title='Swing Multiplier')//Bar Colorsuse_barcolor = input(defval=false, title='Bar Colors On/Off')//-----------------------------------------------------------------------------------------------------------------------------------------------------------------//Definitions//-----------------------------------------------------------------------------------------------------------------------------------------------------------------//Range Filter Values[h_band, l_band, filt] = rng_filt(rng_src, rng_size(rng_src, rng_qty, rng_per), rng_per)//Direction Conditionsvar fdir = 0.0fdir := filt > filt[1] ? 1 : filt < filt[1] ? -1 : fdirupward = fdir == 1 ? 1 : 0downward = fdir == -1 ? 1 : 0//Trading ConditionlongCond = rng_src > filt and rng_src > rng_src[1] and upward > 0 or rng_src > filt and rng_src < rng_src[1] and upward > 0shortCond = rng_src < filt and rng_src < rng_src[1] and downward > 0 or rng_src < filt and rng_src > rng_src[1] and downward > 0CondIni = 0CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]longCondition = longCond and CondIni[1] == -1shortCondition = shortCond and CondIni[1] == 1//Colorsfilt_color = upward ? #05ff9b : downward ? #ff0583 : #ccccccbar_color = upward and rng_src > filt ? rng_src > rng_src[1] ? #05ff9b : #00b36b : downward and rng_src < filt ? rng_src < rng_src[1] ? #ff0583 : #b8005d : #ccccccema = ta.ema(close,emaLength)//-----------------------------------------------------------------------------------------------------------------------------------------------------------------//Outputs//-----------------------------------------------------------------------------------------------------------------------------------------------------------------longStopPrice = strategy.position_avg_price * (1 - longLossPerc)shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)longTakePrice = strategy.position_avg_price * (1 + longTakePerc)shortTakePrice = strategy.position_avg_price * (1 - shortTakePerc)//Filter Plotfilt_plot = plot(filt, color=filt_color, linewidth=3, title='Filter', transp=67)//Band Plotsh_band_plot = plot(h_band, color=color.new(#05ff9b, 100), title='High Band')l_band_plot = plot(l_band, color=color.new(#ff0583, 100), title='Low Band')//Band Fillsfill(h_band_plot, filt_plot, color=color.new(#00b36b, 92), title='High Band Fill')fill(l_band_plot, filt_plot, color=color.new(#b8005d, 92), title='Low Band Fill')//Bar Colorbarcolor(use_barcolor ? bar_color : na)if inDateRange and close>ema strategy.entry("Long", strategy.long, when=longCondition) if inDateRange and close<ema strategy.entry("Short", strategy.short, when=shortCondition)plot(ema)//Plot Buy and Sell Labelsplotshape(longCondition, title='Buy Signal', text='BUY', textcolor=color.white, style=shape.labelup, size=size.normal, location=location.belowbar, color=color.new(color.green, 0))plotshape(shortCondition, title='Sell Signal', text='SELL', textcolor=color.white, style=shape.labeldown, size=size.normal, location=location.abovebar, color=color.new(color.red, 0))//Alertsalertcondition(longCondition, title='Buy Alert', message='BUY')alertcondition(shortCondition, title='Sell Alert', message='SELL')if strategy.position_size > 0 strategy.exit(id='Long', stop=longStopPrice, limit=longTakePrice)if strategy.position_size < 0 strategy.exit(id='Short', stop=shortStopPrice, limit=shortTakePrice)