Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (11)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,000$2,025Equity from $1,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
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.

SettingDefaultType and rangeFeeds
Backtest Starttimestamp('01 Jan 2020 12:00 +0000')timeinDateRange
Backtest Endtimestamp('01 Jan 2024 12:00 +0000')timeinDateRange
Long Stop Loss (%)1float · min 0.0 · step 0.1longStopPrice
Short Stop Loss (%)1float · min 0.0 · step 0.1shortStopPrice
Long Take(%)1float · min 0.0 · step 0.1longTakePrice
Short Take (%)1float · min 0.0 · step 0.1shortTakePrice
EMA Length200intema
Swing Sourceclosesourceh_band l_band filt longCond shortCond bar_color
Swing Period20int · min 1h_band l_band filt
Swing Multiplier3.5float · min 0.0000001h_band l_band filt
Bar Colors On/Offfalseboolbarcolor

What it calculates

  • EMAmath.abs(x - x[1]), navrng · line 22
  • EMAavrng, wperAC · 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.

closecloseprice dataemaLengthEMA Lengthsetting · 200rng_qtySwing Multipliersetting · 3.5rng_perSwing Periodsetting · 20longLossPercLong Stop Loss (%)setting · 1shortLossPercShort Stop Loss (%)setting · 1longTakePercLong Take(%)setting · 1shortTakePercShort Take (%)setting · 1timetimeprice datai_startTimeBacktest Startsetting · timestamp('01 Jan 2…i_endTimeBacktest Endsetting · timestamp('01 Jan 2…avrngEMA→ avrngACEMA→ ACemaEMA→ emawper, r, rfiltwper · r +13 valuesrng_sizerng_sizevaluerng_filt1rng_filt1valuehi_band, lo_bandhi_band · lo_band2 valuesrng_filtrng_filtvalueh_band, l_band, filth_band · l_band +13 valuesfdirfdirvalueupward, downwardupward · downward2 valuesCondIniCondInivaluelongStopPricelongStopPricevalueshortStopPriceshortStopPricevaluelongTakePricelongTakePricevalueshortTakePriceshortTakePricevalueinDateRangeinDateRangeconditionlongConditionlongConditionconditionshortConditionshortConditionconditionlongCond, shortCondlongCond · shortCond2 conditionsfilt_color, bar_colorColourfilt_color · bar_colorentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryexit:Longexit Longstrategy.exitexit:Shortexit Shortstrategy.exitplot:80Filterplotplot:82High Bandplotplot:83Low Bandplotfill:High Band FillHigh Band Fillfillfill:Low Band FillLow Band Fillfillbarcolor:88barcolorbarcolorplot:94plotplotplotshape:96Buy Signalplotshapeplotshape:97Sell Signalplotshapealertcondition:99Buy Alertalertconditionalertcondition:100Sell Alertalertcondition

Order rules

OrderFires whenBy defaultLine
Open Long longlongConditionlongCond and CondIni[1] == -1On90
Open Short shortshortConditionshortCond and CondIni[1] == 1On93
Exit Long stop and limitstrategy.position_size > 0On102
Exit Short stop and limitstrategy.position_size < 0On104

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
Buy AlertalertconditionBUY99
Sell AlertalertconditionSELL100

Does it repaint?

No

No repainting patterns in the source.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—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.

ScriptSharesTypeNetTradesMax drawdown
Range Filter - B&S Signals - 001 - edited this page—v5 strategy0.0%00.0%
EMA Slope AyE by fajardoarelysemav4 strategyNo trades on this market
ROoT by realisticDove62527emav5 strategy−4.7%2259.4%
sachin5986 by mohitesachin78emav4 strategy+32.1%3517.6%
sonu1997 by Sonu1997emav4 strategy+960.7%21,103.8%
Moving Average Crossover by Muh4mm4demav4 strategy+19,990.1%301,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 verified

Neither 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 25 msYes 1,000 bars in 79 msNot measured
PineTSNot testedNot testedNot 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)