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
- 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
VerifiedSame 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⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Strategy Direction | 0 | int (written input.integer) · min -1 · max 1 | line 9 |
| Use Swing Lo/Hi Stop Loss & Take Profit | true | bool | exit longexit exit shortexit line 29 SL |
| Swing Low Lookback | 10 | int | SwingLow |
| Swing High Lookback | 10 | int | SwingHigh |
| Reverse Trades | false | bool | entry long entry short |
| SL Expander | 0 | int · step 1 | LSL SSL |
What it calculates
- Lowest (
lowest,ta.lowestin v5)Swing Low Lookback (10)SwingLow · line 17 - Highest (
highest,ta.highestin v5)Swing High Lookback (10)SwingHigh · line 18 - Valuewhen / ATR (
valuewhen,ta.valuewhenin v5)bought, SwingLow, 0LSL · line 21 - Valuewhen / ATR (
valuewhen,ta.valuewhenin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | every bar | On | 27 |
| Open short short | every bar | On | 28 |
| Exit longexit stop | i_SL | On “Use Swing Lo/Hi Stop Loss & Take Profit” | 30 |
| Exit shortexit stop | i_SL | On “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.
- 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 | +29.9% | +102.5% | 92 | 25% | 1.13 | 52.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +12.0% | +5.5% | 100 | 21% | 1.15 | 19.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +165.4% | +9.8% | 89 | 28% | 1.45 | 38.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +27.3% | +8.4% | 104 | 23% | 1.22 | 25.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −7.5% | +16.7% | 97 | 32% | 0.97 | 59.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +43.4% | +21.5% | 90 | 31% | 1.38 | 22.6% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −71.8% | +148.3% | 98 | 27% | 0.57 | 84.7% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −5.2% | +17.1% | 101 | 22% | 0.93 | 17.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 | 25 | 16% | −$11,326.30 |
| Sideways market | 54 | 31% | $13,905.80 |
| Falling market | 13 | 15% | $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.
All 92 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 27 Jan 2024 41,823.50 | 27 Jan 2024 41,823.50 | 0 | −$8.00 |
| short | 27 Jan 2024 41,823.50 | 28 Jan 2024 42,120.60 | 1 | −$79.04 |
| long | 28 Jan 2024 42,120.60 | 28 Jan 2024 42,120.60 | 0 | −$7.93 |
| short | 28 Jan 2024 42,120.60 | 29 Jan 2024 42,031.10 | 1 | $13.16 |
| long | 29 Jan 2024 42,031.10 | 29 Jan 2024 42,031.10 | 0 | −$7.93 |
| short | 29 Jan 2024 42,031.10 | 30 Jan 2024 43,302.70 | 1 | −$308.13 |
| long | 30 Jan 2024 43,302.70 | 30 Jan 2024 43,302.70 | 0 | −$7.68 |
| short | 30 Jan 2024 43,302.70 | 31 Jan 2024 42,941.10 | 1 | $72.54 |
| long | 31 Jan 2024 42,941.10 | 31 Jan 2024 42,941.10 | 0 | −$7.73 |
| short | 31 Jan 2024 42,941.10 | 1 Feb 2024 42,580.00 | 1 | $73.59 |
| long | 1 Feb 2024 42,580.00 | 1 Feb 2024 42,580.00 | 0 | −$7.79 |
| short | 1 Feb 2024 42,580.00 | 2 Feb 2024 43,082.90 | 1 | −$122.80 |
| long | 2 Feb 2024 43,082.90 | 2 Feb 2024 43,082.90 | 0 | −$7.68 |
| short | 2 Feb 2024 43,082.90 | 3 Feb 2024 43,200.00 | 1 | −$33.78 |
| long | 3 Feb 2024 43,200.00 | 3 Feb 2024 43,200.00 | 0 | −$7.65 |
| short | 3 Feb 2024 43,200.00 | 4 Feb 2024 43,011.10 | 1 | $34.17 |
| long | 4 Feb 2024 43,011.10 | 4 Feb 2024 43,011.10 | 0 | −$7.67 |
| short | 4 Feb 2024 43,011.10 | 7 Feb 2024 43,882.40 | 3 | −$201.95 |
| long | 7 Feb 2024 43,882.40 | 17 Mar 2024 64,780.00 | 39 | $4,539.59 |
| short | 17 Mar 2024 64,780.00 | 26 Mar 2024 71,150.00 | 9 | −$1,391.45 |
| long | 26 Mar 2024 71,150.00 | 13 Apr 2024 64,493.10 | 18 | −$1,207.54 |
| short | 13 Apr 2024 64,493.10 | 6 May 2024 64,820.00 | 23 | −$69.23 |
| long | 6 May 2024 64,820.00 | 11 Jun 2024 67,257.50 | 36 | $419.28 |
| short | 11 Jun 2024 67,257.50 | 11 Jun 2024 67,257.50 | 0 | −$9.66 |
| short | 14 Jun 2024 66,051.00 | 14 Jul 2024 60,498.20 | 30 | $970.81 |
| long | 14 Jul 2024 60,498.20 | 14 Jul 2024 60,498.20 | 0 | −$10.29 |
| long | 15 Jul 2024 61,420.70 | 1 Aug 2024 63,456.70 | 17 | $407.88 |
| short | 1 Aug 2024 63,456.70 | 1 Aug 2024 64,900.00 | 0 | −$312.50 |
| short | 2 Aug 2024 62,302.00 | 23 Aug 2024 61,820.90 | 21 | $88.01 |
| long | 23 Aug 2024 61,820.90 | 30 Aug 2024 57,860.00 | 7 | −$849.29 |
| short | 30 Aug 2024 57,860.00 | 13 Sep 2024 59,809.70 | 14 | −$423.46 |
| long | 13 Sep 2024 59,809.70 | 1 Oct 2024 62,357.90 | 18 | $496.70 |
| short | 1 Oct 2024 62,357.90 | 1 Oct 2024 62,357.90 | 0 | −$9.78 |
| short | 2 Oct 2024 60,164.00 | 14 Oct 2024 64,478.20 | 12 | −$871.30 |
| long | 14 Oct 2024 64,478.20 | 5 Dec 2024 90,791.10 | 52 | $4,668.57 |
| short | 5 Dec 2024 90,791.10 | 5 Dec 2024 90,791.10 | 0 | −$13.76 |
| long | 15 Dec 2024 104,088.00 | 20 Dec 2024 94,256.50 | 5 | −$1,503.83 |
| short | 20 Dec 2024 94,256.50 | 6 Jan 2025 98,976.90 | 17 | −$752.44 |
| long | 6 Jan 2025 98,976.90 | 9 Jan 2025 91,530.40 | 3 | −$1,036.77 |
| short | 9 Jan 2025 91,530.40 | 17 Jan 2025 102,724.00 | 8 | −$1,600.12 |
| short | 9 Jan 2025 91,530.40 | 17 Jan 2025 102,724.00 | 8 | −$1,553.45 |
| long | 17 Jan 2025 102,724.00 | 27 Jan 2025 99,550.00 | 10 | −$320.92 |
| long | 17 Jan 2025 102,724.00 | 27 Jan 2025 99,550.00 | 10 | −$462.12 |
| short | 27 Jan 2025 99,550.00 | 21 Feb 2025 98,826.00 | 25 | $60.32 |
| long | 21 Feb 2025 98,826.00 | 21 Feb 2025 97,777.80 | 0 | −$98.97 |
| short | 24 Feb 2025 93,388.10 | 19 Mar 2025 86,500.00 | 23 | $622.48 |
| long | 19 Mar 2025 86,500.00 | 19 Mar 2025 86,500.00 | 0 | −$7.60 |
| long | 20 Mar 2025 87,000.00 | 29 Mar 2025 82,547.20 | 9 | −$475.10 |
| short | 29 Mar 2025 82,547.20 | 13 Apr 2025 85,905.00 | 15 | −$368.01 |
| long | 13 Apr 2025 85,905.00 | 30 May 2025 104,185.00 | 47 | $1,773.98 |
| short | 30 May 2025 104,185.00 | 30 May 2025 104,185.00 | 0 | −$8.17 |
| short | 31 May 2025 103,621.00 | 9 Jun 2025 106,795.00 | 9 | −$316.46 |
| long | 9 Jun 2025 106,795.00 | 20 Jun 2025 102,664.00 | 11 | −$388.93 |
| short | 20 Jun 2025 102,664.00 | 29 Jun 2025 108,272.00 | 9 | −$529.43 |
| long | 29 Jun 2025 108,272.00 | 25 Jul 2025 115,737.00 | 26 | $607.98 |
| short | 25 Jul 2025 115,737.00 | 25 Jul 2025 115,737.00 | 0 | −$7.73 |
| short | 1 Aug 2025 114,723.00 | 10 Aug 2025 118,922.00 | 9 | −$352.90 |
| long | 10 Aug 2025 118,922.00 | 18 Aug 2025 115,879.00 | 8 | −$244.97 |
| short | 18 Aug 2025 115,879.00 | 10 Sep 2025 113,385.00 | 23 | $185.68 |
| long | 10 Sep 2025 113,385.00 | 10 Sep 2025 113,385.00 | 0 | −$7.33 |
| long | 11 Sep 2025 114,313.00 | 22 Sep 2025 114,384.00 | 11 | −$1.62 |
| short | 22 Sep 2025 114,384.00 | 1 Oct 2025 115,819.00 | 9 | −$121.24 |
| long | 1 Oct 2025 115,819.00 | 10 Oct 2025 112,656.00 | 9 | −$253.81 |
| short | 10 Oct 2025 112,656.00 | 26 Oct 2025 114,000.00 | 16 | −$118.93 |
| long | 26 Oct 2025 114,000.00 | 30 Oct 2025 106,667.00 | 4 | −$567.38 |
| short | 30 Oct 2025 106,667.00 | 3 Dec 2025 93,092.00 | 34 | $1,038.54 |
| long | 3 Dec 2025 93,092.00 | 3 Dec 2025 93,092.00 | 0 | −$7.30 |
| long | 9 Dec 2025 94,150.00 | 14 Dec 2025 87,719.30 | 5 | −$620.31 |
| short | 14 Dec 2025 87,719.30 | 2 Jan 2026 90,406.10 | 19 | −$270.52 |
| long | 2 Jan 2026 90,406.10 | 20 Jan 2026 90,128.40 | 18 | −$31.91 |
| short | 20 Jan 2026 90,128.40 | 2 Mar 2026 69,988.80 | 41 | $1,846.38 |
| long | 2 Mar 2026 69,988.80 | 2 Mar 2026 69,988.80 | 0 | −$8.23 |
| long | 4 Mar 2026 70,096.00 | 21 Mar 2026 68,793.40 | 17 | −$191.73 |
| short | 21 Mar 2026 68,793.40 | 6 Apr 2026 69,310.00 | 16 | −$82.71 |
| long | 6 Apr 2026 69,310.00 | 15 May 2026 78,754.60 | 39 | $1,308.73 |
| short | 15 May 2026 78,754.60 | 15 May 2026 78,754.60 | 0 | −$9.01 |
| short | 16 May 2026 78,659.00 | 14 Jun 2026 64,764.30 | 29 | $1,921.00 |
| long | 14 Jun 2026 64,764.30 | 14 Jun 2026 64,764.30 | 0 | −$10.31 |
| long | 15 Jun 2026 65,800.00 | 23 Jun 2026 62,272.10 | 8 | −$697.88 |
| short | 23 Jun 2026 62,272.10 | 4 Jul 2026 63,239.10 | 11 | −$203.82 |
| long | 4 Jul 2026 63,239.10 | 28 Jul 2026 63,100.00 | 24 | −$36.17 |
| short | 28 Jul 2026 63,100.00 | 28 Jul 2026 63,462.00 | 0 | −$78.62 |
| short | 31 Jul 2026 62,742.50 | 9 Aug 2026 65,409.60 | 9 | −$511.84 |
| long | 9 Aug 2026 65,409.60 | 14 Aug 2026 62,802.30 | 5 | −$463.00 |
| short | 14 Aug 2026 62,802.30 | 19 Aug 2026 65,474.50 | 5 | −$475.45 |
| long | 19 Aug 2026 65,474.50 | 11 Sep 2026 76,264.00 | 23 | $1,721.12 |
| long | 19 Aug 2026 65,474.50 | 11 Sep 2026 76,264.00 | 23 | $1,873.68 |
| short | 11 Sep 2026 76,264.00 | 11 Sep 2026 76,264.00 | 0 | −$11.26 |
| short | 15 Sep 2026 76,046.60 | 18 Sep 2026 79,890.00 | 3 | −$716.29 |
| long | 18 Sep 2026 79,890.00 | 8 Oct 2026 82,563.00 | 20 | $452.88 |
| short | 8 Oct 2026 82,563.00 | 8 Oct 2026 82,563.00 | 0 | −$11.06 |
| short | 15 Oct 2026 80,393.60 | 21 Oct 2026 84,352.00 | 6 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Swing Points Breakouts this page | — | v4 strategy | +29.9% | 92 | 52.0% |
| Positive Bars - Strategy by tweakerID | lowest highest valuewhen atr | v4 strategy | −40.3% | 7 | 54.7% |
| Big Bar Strategy by tweakerID | lowest highest valuewhen atr | v4 strategy | −56.6% | 13 | 57.1% |
| SuperTrend Multi Time Frame Long and Short Trading Strategy by ranga_technologies | atr highest lowest valuewhen | v5 strategy | No trades on this market | ||
| Inside Bar Strategy w- SL by tweakerID | lowest highest valuewhen atr | v4 strategy | −61.3% | 25 | 65.0% |
| Modulo Logic + EMA Strat by tweakerID | lowest highest valuewhen atr | v4 strategy | −50.8% | 16 | 54.7% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 15 ms | With a workaround 1,000 bars in 44 ms | Not measured |
| PineTS | No 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)