Pine Script v4 · Strategy
Average Highest High and Lowest Low Swinger Strategy
A Pine Script v4 strategy built on Lowest (9), Highest (9) and Highest or Lowest (varHi * 2). It has 2 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.1% commission. 2 settings; defaults include Fast Line 9 and Slow Line 26.
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 Average Highest High and Lowest Low Swinger Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
- How did Average Highest High and Lowest Low Swinger Strategy do on BTCUSDT 1D with default settings?
- +6.41%
- From 26 Jan 2024 to 21 Oct 2026, over 20 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Average Highest High and Lowest Low Swinger Strategy 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 Average Highest High and Lowest Low Swinger Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Average Highest High and Lowest Low Swinger Strategy run in Zeal Terminal?
- Yes
- It compiles in 8 ms and runs 1,000 bars in 31 ms, in the browser.
BTCUSDT · 1D · default settings
- Lowest
- Highest
- Lowest
- Highest
- Highest
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +6.41%
- $6.41
- Buy and hold
- +102.5%
- same period
- Closed trades
- 20
- 5 won · 15 lost
- Profitable
- 25.0%
- of closed trades
- Profit factor
- 1.08
- gross profit ÷ gross loss
- Max drawdown
- 49.56%
- −$49.56
One run with the author's default settings, $100 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
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
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 17, 18. The upgraded version below moves each call inside an if block.
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.
- 2 strategy calls use the when = argument (line 17, 18). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 20 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 5: input(type = input.integer) → input.int()
- Line 6: input(type = input.integer) → input.int()
- Line 7: lowest → ta.lowest
- Line 8: highest → ta.highest
- Line 10: lowest → ta.lowest
5 more edits
- Line 11: highest → ta.highest
- Line 14: highest → ta.highest
- Line 14: lowest → ta.lowest
- Line 17: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
- Line 18: strategy.entry(…, 0) → strategy.entry(…, strategy.short)
⋯// © exlux99-//@version=4+//@version=5strategy(title = "Avg HH/LL Crypto Swinger", overlay = true, initial_capital = 100, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent,commission_value=0.1)-varLo = input(title="Fast Line", type=input.integer, defval=9, minval=1)+varLo = input.int(title="Fast Line", defval=9, minval=1)-varHi = input(title="Slow Line", type=input.integer, defval=26, minval=1)+varHi = input.int(title="Slow Line", defval=26, minval=1)-a = lowest(varLo)+a = ta.lowest(varLo)-b = highest(varLo)+b = ta.highest(varLo)c = (a + b ) / 2-d = lowest(varHi)+d = ta.lowest(varHi)-e = highest(varHi)+e = ta.highest(varHi)f = (d + e) / 2g = ((c + f) / 2)[varHi]-h = ((highest(varHi * 2) + lowest(varHi * 2)) / 2)[varHi]+h = ((ta.highest(varHi * 2) + ta.lowest(varHi * 2)) / 2)[varHi]long=close > c and close > f and close >g and close > hshort=close < c and close < f and close<g and close < h-strategy.entry("long",1,when=long)+strategy.entry("long",strategy.long,when=long)-strategy.entry('short',0,when=short)+strategy.entry('short',strategy.short,when=short)Same 20 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 17: when = long → if block
- Line 18: when = short → if block
⋯short=close < c and close < f and close<g and close < h-strategy.entry("long",strategy.long,when=long)+if long+ strategy.entry("long",strategy.long)-strategy.entry('short',strategy.short,when=short)+if short+ strategy.entry('short',strategy.short)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: 20 before, 214 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.
⋯// © exlux99-//@version=5+//@version=6strategy(title = "Avg HH/LL Crypto Swinger", overlay = true, initial_capital = 100, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent,commission_value=0.1)⋯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 |
|---|---|---|---|
| Fast Line | 9 | int (written input.integer) · min 1 | a b |
| Slow Line | 26 | int (written input.integer) · min 1 | d e g h |
What it calculates
- Lowest (
lowest,ta.lowestin v5)Fast Line (9)a · line 7 - Highest (
highest,ta.highestin v5)Fast Line (9)b · line 8 - Lowest (
lowest,ta.lowestin v5)Slow Line (26)d · line 10 - Highest (
highest,ta.highestin v5)Slow Line (26)e · line 11 - Highest / Lowest (
highest,ta.highestin v5)varHi * 2h · line 14
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 | longclose > c and close > f and close >g and close > h | On | 17 |
| Open short short | shortclose < c and close < f and close<g and close < h | On | 18 |
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 | +6.4% | +102.5% | 20 | 25% | 1.08 | 49.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +19.5% | +5.5% | 19 | 37% | 1.78 | 11.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +45.4% | +9.8% | 17 | 41% | 1.46 | 51.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.1% | +8.4% | 25 | 24% | 1.00 | 28.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −45.2% | +16.7% | 19 | 26% | 0.52 | 68.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +35.7% | +21.5% | 17 | 35% | 1.90 | 15.9% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +55.6% | +148.3% | 16 | 31% | 1.70 | 34.6% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −18.7% | +17.1% | 23 | 22% | 0.53 | 23.9% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (Fast Line 6, Slow Line 31) made +57.3% before 26 Dec 2025 and −10.0% after it, worse than the defaults' +3.6% after. Tuning on the past did not carry forward. 29% of the 56 combinations made money in-sample and 63% out-of-sample.
| Slow Line ↓ · Fast Line → | 5 | 6 | 8 | 9 | 11 | 13 | 15 |
|---|---|---|---|---|---|---|---|
| 13 | −25% | −18% | −18% | −18% | −18% | −18% | −17% |
| 16 | −21% | −25% | −30% | −30% | −31% | −34% | −25% |
| 18 | −19% | −20% | −26% | −26% | −26% | −13% | −31% |
| 22 | −26% | −29% | −13% | −13% | +2% | +2% | +2% |
| 26 | −0% | −3% | +3% | +3% | +8% | +8% | +19% |
| 31 | +46% | +57% | +54% | +54% | +54% | +54% | +54% |
| 36 | +1% | −9% | −9% | −9% | −9% | −9% | −9% |
| 44 | −19% | −19% | −19% | −25% | −25% | −27% | −26% |
| Slow Line ↓ · Fast Line → | 5 | 6 | 8 | 9 | 11 | 13 | 15 |
|---|---|---|---|---|---|---|---|
| 13 | +20% | +22% | +22% | +22% | +22% | +22% | +22% |
| 16 | +17% | +30% | +28% | +28% | +28% | +27% | +30% |
| 18 | +23% | +23% | +22% | +22% | +22% | +25% | +20% |
| 22 | +19% | +18% | +22% | +22% | +26% | +26% | +26% |
| 26 | +4% | +3% | +4% | +4% | +4% | +4% | +4% |
| 31 | −9% | −10% | −10% | −10% | −10% | −10% | −10% |
| 36 | −24% | −21% | −21% | −21% | −21% | −21% | −21% |
| 44 | −11% | −11% | −11% | −10% | −10% | −9% | −10% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. 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 | 6 | 17% | −$23.63 |
| Sideways market | 12 | 33% | $36.99 |
| Falling market | 2 | 0% | −$6.85 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
54.0%
The 95th percentile of the worst drawdown when the same 20 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 29.1% to 54.0%; the tick is what actually happened, 46.8%. Order luck alone moves it this much.
All 20 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 23 Apr 2024 66,819.30 | 1 May 2024 60,672.00 | 8 | −$9.38 |
| short | 1 May 2024 60,672.00 | 16 May 2024 66,206.50 | 15 | −$8.46 |
| long | 16 May 2024 66,206.50 | 22 Jun 2024 64,143.60 | 37 | −$2.72 |
| short | 22 Jun 2024 64,143.60 | 20 Jul 2024 66,660.00 | 28 | −$3.28 |
| long | 20 Jul 2024 66,660.00 | 5 Aug 2024 58,161.00 | 16 | −$9.85 |
| short | 5 Aug 2024 58,161.00 | 24 Aug 2024 64,037.20 | 19 | −$6.84 |
| long | 24 Aug 2024 64,037.20 | 1 Sep 2024 58,974.00 | 8 | −$4.82 |
| short | 1 Sep 2024 58,974.00 | 14 Sep 2024 60,498.00 | 13 | −$1.52 |
| long | 14 Sep 2024 60,498.00 | 3 Feb 2025 97,700.60 | 142 | $32.53 |
| short | 3 Feb 2025 97,700.60 | 4 Feb 2025 101,329.00 | 1 | −$3.36 |
| long | 4 Feb 2025 101,329.00 | 5 Feb 2025 97,763.10 | 1 | −$3.06 |
| short | 5 Feb 2025 97,763.10 | 23 Apr 2025 93,443.00 | 77 | $3.35 |
| long | 23 Apr 2025 93,443.00 | 26 Aug 2025 110,112.00 | 125 | $14.55 |
| short | 26 Aug 2025 110,112.00 | 19 Sep 2025 117,074.00 | 24 | −$6.34 |
| long | 19 Sep 2025 117,074.00 | 24 Sep 2025 111,999.00 | 5 | −$4.11 |
| short | 24 Sep 2025 111,999.00 | 2 Oct 2025 118,595.00 | 8 | −$5.28 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$4.15 |
| short | 11 Oct 2025 112,774.00 | 17 Apr 2026 75,154.30 | 188 | $25.64 |
| long | 17 Apr 2026 75,154.30 | 2 Jun 2026 71,408.90 | 46 | −$5.33 |
| short | 2 Jun 2026 71,408.90 | 19 Aug 2026 64,725.40 | 78 | $8.95 |
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 |
|---|---|---|---|---|---|
| Average Highest High and Lowest Low Swinger Strategy this page | — | v4 strategy | +6.4% | 20 | 49.6% |
| 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% |
| 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% |
| eswaran ab by ESWARMONK2515 | lowest highest | v4 strategy | +8.4% | 13 | 39.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 8 ms | With a workaround 1,000 bars in 31 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as 1, 0 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 17, 18) 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/// © exlux99//@version=4strategy(title = "Avg HH/LL Crypto Swinger", overlay = true, initial_capital = 100, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent,commission_value=0.1)varLo = input(title="Fast Line", type=input.integer, defval=9, minval=1)varHi = input(title="Slow Line", type=input.integer, defval=26, minval=1)a = lowest(varLo)b = highest(varLo)c = (a + b ) / 2d = lowest(varHi)e = highest(varHi)f = (d + e) / 2g = ((c + f) / 2)[varHi]h = ((highest(varHi * 2) + lowest(varHi * 2)) / 2)[varHi]long=close > c and close > f and close >g and close > hshort=close < c and close < f and close<g and close < hstrategy.entry("long",1,when=long)strategy.entry('short',0,when=short)