Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Range Breaker

A Pine Script v5 strategy built on Highest (len) and Lowest (len). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a profit target and no stop loss. Each trade commits 10% of equity and pays 0.07% commission. 4 settings; defaults include Swing Lookback 20 and Stop Target Percentage 5.

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 Breaker repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 10 of 10 trades.
How did Range Breaker do on BTCUSDT 1D with default settings?
−3.87%
From 26 Jan 2024 to 21 Oct 2026, over 39 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
What alerts does Range Breaker have?
4
Long Entry Alert; Short Entry Alert; Long Exit Alert; Short Exit Alert.
Does Range Breaker run in Pine Script v6?
Yes
Same 39 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. The v6 script can be downloaded below.
Does Range Breaker use a stop loss?
No
Its exits set a profit target but no stop.

BTCUSDT · 1D · default settings

  • 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 (4)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$96,129$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. Lines, boxes and labels are the script's own drawings, the most recent ones its limits keep.
Net profit
−3.87%
−$3,870.81
Buy and hold
+102.5%
same period
Closed trades
39
21 won · 18 lost
Profitable
53.8%
of closed trades
Profit factor
0.73
gross profit ÷ gross loss
Max drawdown
7.13%
−$7,172.67

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 stop loss

    strategy.exit is used without a stop, loss or trailing stop.

  • 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.

SettingDefaultType and rangeFeeds
Backtest Time Period
Begin Backtest at Start DatetrueboolinTradeWindow
Start DateThis start date is in the time zone of the exchange " + "where the chart's instrument trades. It doesn't use the time " + "zone of the chart or of your computer.timestamp("1 Jan 2020")timeinTradeWindow
Swing Lookback20int · min 3highIndex lowIndex swingHigh swingLow
Stop Target Percentage5float · step 0.1longStopTarget shortStopTarget

What it calculates

  • Highestlenupper · line 23
  • Lowestlenlower · line 24

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.

swingLookbackSwing Lookbacksetting · 20closecloseprice datastopTargetPercentStop Target Percentagesetting · 5timetimeprice databacktestStartDateStart Datesetting · timestamp("1 Jan 20…upperHighest→ upperlowerLowest→ lowerhighIndex, lowIndex, swingHigh, swingLowhighIndex · lowIndex +24 valueslongStopTarget, shortStopTargetlongStopTarget · shortS…2 valueslongConditionlongConditionconditionshortConditionshortConditionconditioninTradeWindowinTradeWindowconditionlongEntryCondition, shortEntryConditionlongEntryCondition · sh…2 conditionslongExitCondition, shortExitConditionlongExitCondition · sho…2 conditionsentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryexit:Long Stop Targetexit Long Stop Targetstrategy.exitexit:Short Stop Targetexit Short Stop Targetstrategy.exitalertcondition:53Long Entry Alertalertconditionalertcondition:54Short Entry Alertalertconditionalertcondition:55Long Exit Alertalertconditionalertcondition:56Short Exit Alertalertcondition

Order rules

OrderFires whenBy defaultLine
Open Long longlongConditionOn38
Open Short shortshortConditionOn40
Exit Long Stop Target limitevery barOn43
Exit Short Stop Target limitevery barOn44

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

Alerts

AlertCallMessageLine
Long Entry AlertalertconditionEnter Long Position53
Short Entry AlertalertconditionEnter Short Position54
Long Exit AlertalertconditionExit Long Position55
Short Exit AlertalertconditionExit Short Position56

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

10/10trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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 1D−3.9%+102.5%3954%0.737.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−1.2%+5.5%2227%0.763.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.2%+9.8%4058%1.025.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−1.3%+8.4%2227%0.784.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−4.1%+16.7%5262%0.787.8%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+1.8%+21.5%2050%1.382.5%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−1.7%+148.3%3462%0.854.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%2536%1.011.5%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 barsTradesWonP&L
Rising market850%−$3,610.46
Sideways market2352%$467.23
Falling market863%−$727.57

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

8.8%

The 95th percentile of the worst drawdown when the same 39 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 4.6% to 8.8%; the tick is what actually happened, 6.4%. Order luck alone moves it this much.

0%10%
All 39 trades
SideEntryExitBarsP&L
short18 Apr 2024 61,277.4019 Apr 2024 60,296.601$146.07
short1 May 2024 60,672.001 May 2024 57,638.400$486.72
short8 May 2024 62,312.1021 May 2024 71,446.6013−$1,489.29
long21 May 2024 71,446.6015 Jun 2024 66,044.0025−$762.58
short15 Jun 2024 66,044.0024 Jun 2024 60,049.509$879.25
long16 Jul 2024 64,724.1019 Jul 2024 67,187.303$363.35
long20 Jul 2024 66,660.0024 Jul 2024 65,936.004−$121.99
short24 Jul 2024 65,936.002 Aug 2024 62,086.309$567.06
short5 Aug 2024 58,161.005 Aug 2024 55,252.900$486.34
short12 Aug 2024 58,712.6027 Aug 2024 59,692.3015−$181.86
short7 Sep 2024 53,963.0022 Sep 2024 63,349.0015−$1,759.87
long22 Sep 2024 63,349.0011 Oct 2024 63,342.7019−$14.77
long15 Oct 2024 66,084.0029 Oct 2024 73,460.3014$1,085.23
long18 Jan 2025 104,077.0020 Jan 2025 106,398.002$208.01
long22 Jan 2025 106,144.0026 Feb 2025 88,680.4035−$1,655.15
short26 Feb 2025 88,680.4026 Feb 2025 84,246.400$477.47
short4 Mar 2025 86,221.204 Mar 2025 81,909.600$479.82
short7 Apr 2025 78,430.007 Apr 2025 74,508.500$482.09
short11 Apr 2025 79,607.3023 Apr 2025 93,443.0012−$1,746.30
long23 Apr 2025 93,443.008 May 2025 101,882.0015$869.56
short23 Jun 2025 100,964.0010 Jul 2025 111,234.0017−$1,018.82
long10 Jul 2025 111,234.0010 Jul 2025 116,796.000$474.57
long14 Aug 2025 123,306.0026 Aug 2025 110,112.0012−$1,063.66
short26 Aug 2025 110,112.0019 Sep 2025 117,074.0024−$628.10
long19 Sep 2025 117,074.0026 Sep 2025 108,994.007−$678.99
short26 Sep 2025 108,994.002 Oct 2025 118,595.006−$858.04
long2 Oct 2025 118,595.0017 Oct 2025 108,194.0015−$845.57
short17 Oct 2025 108,194.004 Nov 2025 101,254.0018$591.01
short5 Nov 2025 101,497.0014 Nov 2025 94,707.409$620.73
long6 Jan 2026 93,859.7013 Jan 2026 95,861.007$189.77
long14 Jan 2026 95,414.0026 Jan 2026 86,670.4012−$888.05
short26 Jan 2026 86,670.4029 Jan 2026 84,835.003$187.29
short30 Jan 2026 84,650.2031 Jan 2026 80,047.501$502.63
long5 Mar 2026 72,666.809 Mar 2026 69,269.804−$458.62
long16 Mar 2026 72,815.3023 Mar 2026 71,251.907−$216.79
long16 Apr 2026 74,810.0028 May 2026 74,449.3042−$58.85
short28 May 2026 74,449.302 Jun 2026 67,838.405$827.27
long22 Jul 2026 66,556.1019 Aug 2026 67,961.7028$187.99
long20 Aug 2026 69,334.8020 Aug 2026 72,801.500$464.27

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 Breaker this page—v5 strategy−3.9%397.1%
Alex Days HiLo Rajib by 14rajibhighest lowestv4 strategyNo trades on this market
Donchian Strat EXMO by pskoroplashighest lowestv4 strategy+12.1%2268.0%
Average Highest High and Lowest Low Swinger Strategy by exlux99lowest highestv4 strategy+6.4%2049.6%
Highest High and Lowest Low Channel Strategy by ceyhunhighest lowestv5 strategy−3.7%267.9%
Donchian Channels System [racer8] by racer8highest lowestv4 strategy−3.2%3643.6%

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.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

Yes

Same 39 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.

Download the v6 script

⋯// © deperp-//@version=5+//@version=6strategy("Range Breaker", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.07, pyramiding=0)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 21 msYes 1,000 bars in 40 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/// © deperp//@version=5strategy("Range Breaker", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.07, pyramiding=0)// Backtest Time PerioduseDateFilter = input.bool(true, title="Begin Backtest at Start Date",     group="Backtest Time Period")backtestStartDate = input.time(timestamp("1 Jan 2020"),      title="Start Date", group="Backtest Time Period",     tooltip="This start date is in the time zone of the exchange " +      "where the chart's instrument trades. It doesn't use the time " +      "zone of the chart or of your computer.")inTradeWindow = not useDateFilter or time >= backtestStartDateswingLookback = input.int(20, title="Swing Lookback", minval=3)stopTargetPercent = input.float(5, title="Stop Target Percentage", step=0.1)// Calculate lockback swingsswings(len) =>    var highIndex = bar_index    var lowIndex = bar_index    var swingHigh = float(na)    var swingLow = float(na)        upper = ta.highest(len)    lower = ta.lowest(len)        if high[len] > upper        highIndex := bar_index[len]        swingHigh := high[len]    if low[len] < lower        lowIndex := bar_index[len]        swingLow := low[len]    [swingHigh, swingLow, highIndex, lowIndex]// Strategy logic[swingHigh, swingLow, highIndex, lowIndex] = swings(swingLookback)longCondition = inTradeWindow and (ta.crossover(close, swingHigh))shortCondition = inTradeWindow and (ta.crossunder(close, swingLow))if longCondition    strategy.entry("Long", strategy.long)if shortCondition    strategy.entry("Short", strategy.short)longStopTarget = close * (1 + stopTargetPercent / 100)shortStopTarget = close * (1 - stopTargetPercent / 100)strategy.exit("Long Stop Target", "Long", limit=longStopTarget)strategy.exit("Short Stop Target", "Short", limit=shortStopTarget)// Plot break linesline.new(x1=highIndex, y1=swingHigh, x2=bar_index, y2=swingHigh, color=color.rgb(255, 82, 82, 48), width=3, xloc=xloc.bar_index, extend=extend.right)line.new(x1=lowIndex, y1=swingLow, x2=bar_index, y2=swingLow, color=color.rgb(76, 175, 79, 47), width=3, xloc=xloc.bar_index, extend=extend.right)// Alert conditions for entry and exitlongEntryCondition = inTradeWindow and (ta.crossover(close, swingHigh))shortEntryCondition = inTradeWindow and (ta.crossunder(close, swingLow))longExitCondition = close >= longStopTargetshortExitCondition = close <= shortStopTargetalertcondition(longEntryCondition, title="Long Entry Alert", message="Enter Long Position")alertcondition(shortEntryCondition, title="Short Entry Alert", message="Enter Short Position")alertcondition(longExitCondition, title="Long Exit Alert", message="Exit Long Position")alertcondition(shortExitCondition, title="Short Exit Alert", message="Exit Short Position")