Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Swing Points Breakouts

A Pine Script v4 strategy built on Lowest (10), Highest (10) and Valuewhen or ATR (bought, SwingLow). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 100% of equity and pays 0.04 commission. 6 settings; defaults include Strategy Direction 0, Swing Low Lookback 10 and Swing High Lookback 10.

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 Swing Points Breakouts repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 23 of 23 trades.
How did Swing Points Breakouts do on BTCUSDT 1D with default settings?
+29.88%
From 26 Jan 2024 to 21 Oct 2026, over 92 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Swing Points Breakouts be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does Swing Points Breakouts use a stop loss?
Yes
strategy.exit sets a stop on line 30, 31.
Does Swing Points Breakouts run in Zeal Terminal?
Yes
It compiles in 15 ms and runs 1,000 bars in 44 ms, in the browser.

BTCUSDT · 1D · default settings

  • SL
  • Plot
  • Plot
  • 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 (6)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$13,044$20,253Equity from $10,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. Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 27, 28) so the engine trades the way the script says.
Net profit
+29.88%
$2,987.73
Buy and hold
+102.5%
same period
Closed trades
92
23 won · 69 lost
Profitable
25.0%
of closed trades
Profit factor
1.13
gross profit ÷ gross loss
Max drawdown
51.96%
−$8,217.56

One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames lowest → ta.lowest, highest → ta.highest, valuewhen → ta.valuewhen, atr → ta.atr.

v4 → v5

Verified

Same 92 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 6: //@version=4 → //@version=5
  • Line 8: input(type = input.integer) → input.int()
  • Line 17: lowest → ta.lowest
  • Line 18: highest → ta.highest
  • Line 21: valuewhen → ta.valuewhen
  • Line 21: valuewhen → ta.valuewhen
6 more edits
  • Line 21: atr → ta.atr
  • Line 22: valuewhen → ta.valuewhen
  • Line 22: valuewhen → ta.valuewhen
  • Line 22: atr → ta.atr
  • Line 27: strategy.entry(…, true) → strategy.entry(…, strategy.long)
  • Line 28: strategy.entry(…, false) → strategy.entry(…, strategy.short)
⋯// The direction of the strategy can be adjusted in the Inputs panel.-//@version=4+//@version=5strategy("Swing Points Breakouts", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, commission_value=0.04)-direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)+direction = input.int(0, title = "Strategy Direction", minval=-1, maxval=1)strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))⋯//Strategy Calculations-SwingLow=lowest(i_SwingLow)+SwingLow=ta.lowest(i_SwingLow)-SwingHigh=highest(i_SwingHigh)+SwingHigh=ta.highest(i_SwingHigh)//SL & TP Calculationsbought=strategy.position_size != strategy.position_size[1]-LSL=valuewhen(bought, SwingLow, 0)-((valuewhen(bought, atr(14), 0)/5)*i_SLExpander)+LSL=ta.valuewhen(bought, SwingLow, 0)-((ta.valuewhen(bought, ta.atr(14), 0)/5)*i_SLExpander)-SSL=valuewhen(bought, SwingHigh, 0)+((valuewhen(bought, atr(14), 0)/5)*i_SLExpander)+SSL=ta.valuewhen(bought, SwingHigh, 0)+((ta.valuewhen(bought, ta.atr(14), 0)/5)*i_SLExpander)islong=strategy.position_size > 0⋯//Entries and Exits-strategy.entry("long", true, stop=i_reverse?na:SwingHigh, limit=i_reverse?SwingLow:na)+strategy.entry("long", strategy.long, stop=i_reverse?na:SwingHigh, limit=i_reverse?SwingLow:na)-strategy.entry("short", false, stop=i_reverse?na:SwingLow, limit=i_reverse?SwingHigh:na)+strategy.entry("short", strategy.short, stop=i_reverse?na:SwingLow, limit=i_reverse?SwingHigh:na)if i_SL⋯

Clean v5

VerifiedDownload the v5 script

Same 92 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 11: input() → input.bool()
  • Line 12: input() → input.int()
  • Line 13: input() → input.int()
  • Line 14: input() → input.bool()
  • Line 15: input() → input.int()
⋯//Inputss-i_SL=input(true, title="Use Swing Lo/Hi Stop Loss & Take Profit")+i_SL=input.bool(true, title="Use Swing Lo/Hi Stop Loss & Take Profit")-i_SwingLow=input(10, title="Swing Low Lookback")+i_SwingLow=input.int(10, title="Swing Low Lookback")-i_SwingHigh=input(10, title="Swing High Lookback")+i_SwingHigh=input.int(10, title="Swing High Lookback")-i_reverse=input(false, "Reverse Trades")+i_reverse=input.bool(false, "Reverse Trades")-i_SLExpander=input(defval=0, step=1, title="SL Expander")+i_SLExpander=input.int(defval=0, step=1, title="SL Expander")//Strategy Calculations⋯

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: 92 before, 236 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.

⋯// The direction of the strategy can be adjusted in the Inputs panel.-//@version=5+//@version=6strategy("Swing Points Breakouts", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, commission_value=0.04)⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Strategy Direction0int (written input.integer) · min -1 · max 1line 9
Use Swing Lo/Hi Stop Loss & Take Profittrueboolexit longexit exit shortexit line 29 SL
Swing Low Lookback10intSwingLow
Swing High Lookback10intSwingHigh
Reverse Tradesfalseboolentry long entry short
SL Expander0int · step 1LSL SSL

What it calculates

  • Lowest (lowest, ta.lowest in v5)Swing Low Lookback (10)SwingLow · line 17
  • Highest (highest, ta.highest in v5)Swing High Lookback (10)SwingHigh · line 18
  • Valuewhen / ATR (valuewhen, ta.valuewhen in v5)bought, SwingLow, 0LSL · line 21
  • Valuewhen / ATR (valuewhen, ta.valuewhen in v5)bought, SwingHigh, 0SSL · line 22

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.

i_SwingLowSwing Low Lookbacksetting · 10i_SwingHighSwing High Lookbacksetting · 10i_SLExpanderSL Expandersetting · 0SwingLowLowest→ SwingLowSwingHighHighest→ SwingHighLSLValuewhen / ATR→ LSLSSLValuewhen / ATR→ SSLSLSLvaluebought, islong, isshortbought · islong +13 conditionsentry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entryexit:longexitexit longexitstrategy.exitexit:shortexitexit shortexitstrategy.exitplot:33SLplotplot:34plotplotplot:35plotplot

Order rules

OrderFires whenBy defaultLine
Open long longevery barOn27
Open short shortevery barOn28
Exit longexit stopi_SLOn “Use Swing Lo/Hi Stop Loss & Take Profit”30
Exit shortexit stopi_SLOn “Use Swing Lo/Hi Stop Loss & Take Profit”31

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.

23/23trades 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+29.9%+102.5%9225%1.1352.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+12.0%+5.5%10021%1.1519.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+165.4%+9.8%8928%1.4538.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+27.3%+8.4%10423%1.2225.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−7.5%+16.7%9732%0.9759.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+43.4%+21.5%9031%1.3822.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−71.8%+148.3%9827%0.5784.7%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−5.2%+17.1%10122%0.9317.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 market2516%−$11,326.30
Sideways market5431%$13,905.80
Falling market1315%$413.47

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

How bad could the drawdown be?

61.6%

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

0%71%
All 92 trades
SideEntryExitBarsP&L
long27 Jan 2024 41,823.5027 Jan 2024 41,823.500−$8.00
short27 Jan 2024 41,823.5028 Jan 2024 42,120.601−$79.04
long28 Jan 2024 42,120.6028 Jan 2024 42,120.600−$7.93
short28 Jan 2024 42,120.6029 Jan 2024 42,031.101$13.16
long29 Jan 2024 42,031.1029 Jan 2024 42,031.100−$7.93
short29 Jan 2024 42,031.1030 Jan 2024 43,302.701−$308.13
long30 Jan 2024 43,302.7030 Jan 2024 43,302.700−$7.68
short30 Jan 2024 43,302.7031 Jan 2024 42,941.101$72.54
long31 Jan 2024 42,941.1031 Jan 2024 42,941.100−$7.73
short31 Jan 2024 42,941.101 Feb 2024 42,580.001$73.59
long1 Feb 2024 42,580.001 Feb 2024 42,580.000−$7.79
short1 Feb 2024 42,580.002 Feb 2024 43,082.901−$122.80
long2 Feb 2024 43,082.902 Feb 2024 43,082.900−$7.68
short2 Feb 2024 43,082.903 Feb 2024 43,200.001−$33.78
long3 Feb 2024 43,200.003 Feb 2024 43,200.000−$7.65
short3 Feb 2024 43,200.004 Feb 2024 43,011.101$34.17
long4 Feb 2024 43,011.104 Feb 2024 43,011.100−$7.67
short4 Feb 2024 43,011.107 Feb 2024 43,882.403−$201.95
long7 Feb 2024 43,882.4017 Mar 2024 64,780.0039$4,539.59
short17 Mar 2024 64,780.0026 Mar 2024 71,150.009−$1,391.45
long26 Mar 2024 71,150.0013 Apr 2024 64,493.1018−$1,207.54
short13 Apr 2024 64,493.106 May 2024 64,820.0023−$69.23
long6 May 2024 64,820.0011 Jun 2024 67,257.5036$419.28
short11 Jun 2024 67,257.5011 Jun 2024 67,257.500−$9.66
short14 Jun 2024 66,051.0014 Jul 2024 60,498.2030$970.81
long14 Jul 2024 60,498.2014 Jul 2024 60,498.200−$10.29
long15 Jul 2024 61,420.701 Aug 2024 63,456.7017$407.88
short1 Aug 2024 63,456.701 Aug 2024 64,900.000−$312.50
short2 Aug 2024 62,302.0023 Aug 2024 61,820.9021$88.01
long23 Aug 2024 61,820.9030 Aug 2024 57,860.007−$849.29
short30 Aug 2024 57,860.0013 Sep 2024 59,809.7014−$423.46
long13 Sep 2024 59,809.701 Oct 2024 62,357.9018$496.70
short1 Oct 2024 62,357.901 Oct 2024 62,357.900−$9.78
short2 Oct 2024 60,164.0014 Oct 2024 64,478.2012−$871.30
long14 Oct 2024 64,478.205 Dec 2024 90,791.1052$4,668.57
short5 Dec 2024 90,791.105 Dec 2024 90,791.100−$13.76
long15 Dec 2024 104,088.0020 Dec 2024 94,256.505−$1,503.83
short20 Dec 2024 94,256.506 Jan 2025 98,976.9017−$752.44
long6 Jan 2025 98,976.909 Jan 2025 91,530.403−$1,036.77
short9 Jan 2025 91,530.4017 Jan 2025 102,724.008−$1,600.12
short9 Jan 2025 91,530.4017 Jan 2025 102,724.008−$1,553.45
long17 Jan 2025 102,724.0027 Jan 2025 99,550.0010−$320.92
long17 Jan 2025 102,724.0027 Jan 2025 99,550.0010−$462.12
short27 Jan 2025 99,550.0021 Feb 2025 98,826.0025$60.32
long21 Feb 2025 98,826.0021 Feb 2025 97,777.800−$98.97
short24 Feb 2025 93,388.1019 Mar 2025 86,500.0023$622.48
long19 Mar 2025 86,500.0019 Mar 2025 86,500.000−$7.60
long20 Mar 2025 87,000.0029 Mar 2025 82,547.209−$475.10
short29 Mar 2025 82,547.2013 Apr 2025 85,905.0015−$368.01
long13 Apr 2025 85,905.0030 May 2025 104,185.0047$1,773.98
short30 May 2025 104,185.0030 May 2025 104,185.000−$8.17
short31 May 2025 103,621.009 Jun 2025 106,795.009−$316.46
long9 Jun 2025 106,795.0020 Jun 2025 102,664.0011−$388.93
short20 Jun 2025 102,664.0029 Jun 2025 108,272.009−$529.43
long29 Jun 2025 108,272.0025 Jul 2025 115,737.0026$607.98
short25 Jul 2025 115,737.0025 Jul 2025 115,737.000−$7.73
short1 Aug 2025 114,723.0010 Aug 2025 118,922.009−$352.90
long10 Aug 2025 118,922.0018 Aug 2025 115,879.008−$244.97
short18 Aug 2025 115,879.0010 Sep 2025 113,385.0023$185.68
long10 Sep 2025 113,385.0010 Sep 2025 113,385.000−$7.33
long11 Sep 2025 114,313.0022 Sep 2025 114,384.0011−$1.62
short22 Sep 2025 114,384.001 Oct 2025 115,819.009−$121.24
long1 Oct 2025 115,819.0010 Oct 2025 112,656.009−$253.81
short10 Oct 2025 112,656.0026 Oct 2025 114,000.0016−$118.93
long26 Oct 2025 114,000.0030 Oct 2025 106,667.004−$567.38
short30 Oct 2025 106,667.003 Dec 2025 93,092.0034$1,038.54
long3 Dec 2025 93,092.003 Dec 2025 93,092.000−$7.30
long9 Dec 2025 94,150.0014 Dec 2025 87,719.305−$620.31
short14 Dec 2025 87,719.302 Jan 2026 90,406.1019−$270.52
long2 Jan 2026 90,406.1020 Jan 2026 90,128.4018−$31.91
short20 Jan 2026 90,128.402 Mar 2026 69,988.8041$1,846.38
long2 Mar 2026 69,988.802 Mar 2026 69,988.800−$8.23
long4 Mar 2026 70,096.0021 Mar 2026 68,793.4017−$191.73
short21 Mar 2026 68,793.406 Apr 2026 69,310.0016−$82.71
long6 Apr 2026 69,310.0015 May 2026 78,754.6039$1,308.73
short15 May 2026 78,754.6015 May 2026 78,754.600−$9.01
short16 May 2026 78,659.0014 Jun 2026 64,764.3029$1,921.00
long14 Jun 2026 64,764.3014 Jun 2026 64,764.300−$10.31
long15 Jun 2026 65,800.0023 Jun 2026 62,272.108−$697.88
short23 Jun 2026 62,272.104 Jul 2026 63,239.1011−$203.82
long4 Jul 2026 63,239.1028 Jul 2026 63,100.0024−$36.17
short28 Jul 2026 63,100.0028 Jul 2026 63,462.000−$78.62
short31 Jul 2026 62,742.509 Aug 2026 65,409.609−$511.84
long9 Aug 2026 65,409.6014 Aug 2026 62,802.305−$463.00
short14 Aug 2026 62,802.3019 Aug 2026 65,474.505−$475.45
long19 Aug 2026 65,474.5011 Sep 2026 76,264.0023$1,721.12
long19 Aug 2026 65,474.5011 Sep 2026 76,264.0023$1,873.68
short11 Sep 2026 76,264.0011 Sep 2026 76,264.000−$11.26
short15 Sep 2026 76,046.6018 Sep 2026 79,890.003−$716.29
long18 Sep 2026 79,890.008 Oct 2026 82,563.0020$452.88
short8 Oct 2026 82,563.008 Oct 2026 82,563.000−$11.06
short15 Oct 2026 80,393.6021 Oct 2026 84,352.006−$684.39

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
Swing Points Breakouts this page—v4 strategy+29.9%9252.0%
Positive Bars - Strategy by tweakerIDlowest highest valuewhen atrv4 strategy−40.3%754.7%
Big Bar Strategy by tweakerIDlowest highest valuewhen atrv4 strategy−56.6%1357.1%
SuperTrend Multi Time Frame Long and Short Trading Strategy by ranga_technologiesatr highest lowest valuewhenv5 strategyNo trades on this market
Inside Bar Strategy w- SL by tweakerIDlowest highest valuewhen atrv4 strategy−61.3%2565.0%
Modulo Logic + EMA Strat by tweakerIDlowest highest valuewhen atrv4 strategy−50.8%1654.7%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 15 msWith a workaround 1,000 bars in 44 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 27, 28) so the engine trades the way the script says.

“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. PineTS runs Pine Script v5 and v6 only.

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/// © tweakerID// Long term strategy for managing a Crypto investment with Swing Trades of more than 1 day. The strategy buys with a // stop order at the Swing High price (green line) and sells with a stop order at the Swing Low price (red line). // The direction of the strategy can be adjusted in the Inputs panel.//@version=4strategy("Swing Points Breakouts", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, commission_value=0.04)direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))//Inputssi_SL=input(true, title="Use Swing Lo/Hi Stop Loss & Take Profit")i_SwingLow=input(10, title="Swing Low Lookback")i_SwingHigh=input(10, title="Swing High Lookback")i_reverse=input(false, "Reverse Trades")i_SLExpander=input(defval=0, step=1, title="SL Expander")//Strategy CalculationsSwingLow=lowest(i_SwingLow)SwingHigh=highest(i_SwingHigh)//SL & TP Calculationsbought=strategy.position_size != strategy.position_size[1]LSL=valuewhen(bought, SwingLow, 0)-((valuewhen(bought, atr(14), 0)/5)*i_SLExpander)SSL=valuewhen(bought, SwingHigh, 0)+((valuewhen(bought, atr(14), 0)/5)*i_SLExpander)islong=strategy.position_size > 0isshort=strategy.position_size < 0SL= islong ? LSL : isshort ? SSL : na//Entries and Exitsstrategy.entry("long", true, stop=i_reverse?na:SwingHigh, limit=i_reverse?SwingLow:na)strategy.entry("short", false, stop=i_reverse?na:SwingLow, limit=i_reverse?SwingHigh:na)if i_SL    strategy.exit("longexit", "long", stop=LSL)    strategy.exit("shortexit", "short", stop=SSL)//Plotsplot(i_SL ? SL : na, color=color.red, style=plot.style_cross, title="SL")plot(SwingLow, color=color.red)plot(SwingHigh, color=color.green)