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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Backtest Time Period | |||
| Begin Backtest at Start Date | true | bool | inTradeWindow |
| 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") | time | inTradeWindow |
| Swing Lookback | 20 | int · min 3 | highIndex lowIndex swingHigh swingLow |
| Stop Target Percentage | 5 | float · step 0.1 | longStopTarget shortStopTarget |
What it calculates
- Highestlen
upper · line 23 - Lowestlen
lower · 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | longCondition | On | 38 |
| Open Short short | shortCondition | On | 40 |
| Exit Long Stop Target limit | every bar | On | 43 |
| Exit Short Stop Target limit | every bar | On | 44 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Long Entry Alert | alertcondition | Enter Long Position | 53 |
| Short Entry Alert | alertcondition | Enter Short Position | 54 |
| Long Exit Alert | alertcondition | Exit Long Position | 55 |
| Short Exit Alert | alertcondition | Exit Short Position | 56 |
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 | −3.9% | +102.5% | 39 | 54% | 0.73 | 7.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −1.2% | +5.5% | 22 | 27% | 0.76 | 3.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.2% | +9.8% | 40 | 58% | 1.02 | 5.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −1.3% | +8.4% | 22 | 27% | 0.78 | 4.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −4.1% | +16.7% | 52 | 62% | 0.78 | 7.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +1.8% | +21.5% | 20 | 50% | 1.38 | 2.5% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −1.7% | +148.3% | 34 | 62% | 0.85 | 4.6% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 25 | 36% | 1.01 | 1.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 8 | 50% | −$3,610.46 |
| Sideways market | 23 | 52% | $467.23 |
| Falling market | 8 | 63% | −$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.
All 39 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 18 Apr 2024 61,277.40 | 19 Apr 2024 60,296.60 | 1 | $146.07 |
| short | 1 May 2024 60,672.00 | 1 May 2024 57,638.40 | 0 | $486.72 |
| short | 8 May 2024 62,312.10 | 21 May 2024 71,446.60 | 13 | −$1,489.29 |
| long | 21 May 2024 71,446.60 | 15 Jun 2024 66,044.00 | 25 | −$762.58 |
| short | 15 Jun 2024 66,044.00 | 24 Jun 2024 60,049.50 | 9 | $879.25 |
| long | 16 Jul 2024 64,724.10 | 19 Jul 2024 67,187.30 | 3 | $363.35 |
| long | 20 Jul 2024 66,660.00 | 24 Jul 2024 65,936.00 | 4 | −$121.99 |
| short | 24 Jul 2024 65,936.00 | 2 Aug 2024 62,086.30 | 9 | $567.06 |
| short | 5 Aug 2024 58,161.00 | 5 Aug 2024 55,252.90 | 0 | $486.34 |
| short | 12 Aug 2024 58,712.60 | 27 Aug 2024 59,692.30 | 15 | −$181.86 |
| short | 7 Sep 2024 53,963.00 | 22 Sep 2024 63,349.00 | 15 | −$1,759.87 |
| long | 22 Sep 2024 63,349.00 | 11 Oct 2024 63,342.70 | 19 | −$14.77 |
| long | 15 Oct 2024 66,084.00 | 29 Oct 2024 73,460.30 | 14 | $1,085.23 |
| long | 18 Jan 2025 104,077.00 | 20 Jan 2025 106,398.00 | 2 | $208.01 |
| long | 22 Jan 2025 106,144.00 | 26 Feb 2025 88,680.40 | 35 | −$1,655.15 |
| short | 26 Feb 2025 88,680.40 | 26 Feb 2025 84,246.40 | 0 | $477.47 |
| short | 4 Mar 2025 86,221.20 | 4 Mar 2025 81,909.60 | 0 | $479.82 |
| short | 7 Apr 2025 78,430.00 | 7 Apr 2025 74,508.50 | 0 | $482.09 |
| short | 11 Apr 2025 79,607.30 | 23 Apr 2025 93,443.00 | 12 | −$1,746.30 |
| long | 23 Apr 2025 93,443.00 | 8 May 2025 101,882.00 | 15 | $869.56 |
| short | 23 Jun 2025 100,964.00 | 10 Jul 2025 111,234.00 | 17 | −$1,018.82 |
| long | 10 Jul 2025 111,234.00 | 10 Jul 2025 116,796.00 | 0 | $474.57 |
| long | 14 Aug 2025 123,306.00 | 26 Aug 2025 110,112.00 | 12 | −$1,063.66 |
| short | 26 Aug 2025 110,112.00 | 19 Sep 2025 117,074.00 | 24 | −$628.10 |
| long | 19 Sep 2025 117,074.00 | 26 Sep 2025 108,994.00 | 7 | −$678.99 |
| short | 26 Sep 2025 108,994.00 | 2 Oct 2025 118,595.00 | 6 | −$858.04 |
| long | 2 Oct 2025 118,595.00 | 17 Oct 2025 108,194.00 | 15 | −$845.57 |
| short | 17 Oct 2025 108,194.00 | 4 Nov 2025 101,254.00 | 18 | $591.01 |
| short | 5 Nov 2025 101,497.00 | 14 Nov 2025 94,707.40 | 9 | $620.73 |
| long | 6 Jan 2026 93,859.70 | 13 Jan 2026 95,861.00 | 7 | $189.77 |
| long | 14 Jan 2026 95,414.00 | 26 Jan 2026 86,670.40 | 12 | −$888.05 |
| short | 26 Jan 2026 86,670.40 | 29 Jan 2026 84,835.00 | 3 | $187.29 |
| short | 30 Jan 2026 84,650.20 | 31 Jan 2026 80,047.50 | 1 | $502.63 |
| long | 5 Mar 2026 72,666.80 | 9 Mar 2026 69,269.80 | 4 | −$458.62 |
| long | 16 Mar 2026 72,815.30 | 23 Mar 2026 71,251.90 | 7 | −$216.79 |
| long | 16 Apr 2026 74,810.00 | 28 May 2026 74,449.30 | 42 | −$58.85 |
| short | 28 May 2026 74,449.30 | 2 Jun 2026 67,838.40 | 5 | $827.27 |
| long | 22 Jul 2026 66,556.10 | 19 Aug 2026 67,961.70 | 28 | $187.99 |
| long | 20 Aug 2026 69,334.80 | 20 Aug 2026 72,801.50 | 0 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Range Breaker this page | — | v5 strategy | −3.9% | 39 | 7.1% |
| Alex Days HiLo Rajib by 14rajib | highest lowest | v4 strategy | No trades on this market | ||
| Donchian Strat EXMO by pskoroplas | highest lowest | v4 strategy | +12.1% | 22 | 68.0% |
| Average Highest High and Lowest Low Swinger Strategy by exlux99 | lowest highest | v4 strategy | +6.4% | 20 | 49.6% |
| Highest High and Lowest Low Channel Strategy by ceyhun | highest lowest | v5 strategy | −3.7% | 26 | 7.9% |
| Donchian Channels System [racer8] by racer8 | highest lowest | v4 strategy | −3.2% | 36 | 43.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
VerifiedNothing 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.
⋯// © 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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 21 ms | Yes 1,000 bars in 40 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/// © 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")