Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (2)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$139$203Equity from $100
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. 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.
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

Verified

Same 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)

Clean v5

VerifiedDownload the v5 script

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.

SettingDefaultType and rangeFeeds
Fast Line9int (written input.integer) · min 1a b
Slow Line26int (written input.integer) · min 1d e g h

What it calculates

  • Lowest (lowest, ta.lowest in v5)Fast Line (9)a · line 7
  • Highest (highest, ta.highest in v5)Fast Line (9)b · line 8
  • Lowest (lowest, ta.lowest in v5)Slow Line (26)d · line 10
  • Highest (highest, ta.highest in v5)Slow Line (26)e · line 11
  • Highest / Lowest (highest, ta.highest in 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.

varLoFast Linesetting · 9varHiSlow Linesetting · 26closecloseprice dataaLowest→ abHighest→ bdLowest→ deHighest→ ehHighest / Lowest→ hccvalueffvalueggvaluelonglongconditionshortshortconditionentry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entry

Order rules

OrderFires whenBy defaultLine
Open long longlongclose > c and close > f and close >g and close > hOn17
Open short shortshortclose < c and close < f and close<g and close < hOn18

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.

2/2trades 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+6.4%+102.5%2025%1.0849.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+19.5%+5.5%1937%1.7811.3%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+45.4%+9.8%1741%1.4651.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.1%+8.4%2524%1.0028.7%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−45.2%+16.7%1926%0.5268.8%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+35.7%+21.5%1735%1.9015.9%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+55.6%+148.3%1631%1.7034.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−18.7%+17.1%2322%0.5323.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.

Before 26 Dec 2025 · in-sample
Slow Line ↓ · Fast Line →5689111315
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%
From 26 Dec 2025 · out-of-sample
Slow Line ↓ · Fast Line →5689111315
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 barsTradesWonP&L
Rising market617%−$23.63
Sideways market1233%$36.99
Falling market20%−$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.

0%62%
All 20 trades
SideEntryExitBarsP&L
long23 Apr 2024 66,819.301 May 2024 60,672.008−$9.38
short1 May 2024 60,672.0016 May 2024 66,206.5015−$8.46
long16 May 2024 66,206.5022 Jun 2024 64,143.6037−$2.72
short22 Jun 2024 64,143.6020 Jul 2024 66,660.0028−$3.28
long20 Jul 2024 66,660.005 Aug 2024 58,161.0016−$9.85
short5 Aug 2024 58,161.0024 Aug 2024 64,037.2019−$6.84
long24 Aug 2024 64,037.201 Sep 2024 58,974.008−$4.82
short1 Sep 2024 58,974.0014 Sep 2024 60,498.0013−$1.52
long14 Sep 2024 60,498.003 Feb 2025 97,700.60142$32.53
short3 Feb 2025 97,700.604 Feb 2025 101,329.001−$3.36
long4 Feb 2025 101,329.005 Feb 2025 97,763.101−$3.06
short5 Feb 2025 97,763.1023 Apr 2025 93,443.0077$3.35
long23 Apr 2025 93,443.0026 Aug 2025 110,112.00125$14.55
short26 Aug 2025 110,112.0019 Sep 2025 117,074.0024−$6.34
long19 Sep 2025 117,074.0024 Sep 2025 111,999.005−$4.11
short24 Sep 2025 111,999.002 Oct 2025 118,595.008−$5.28
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$4.15
short11 Oct 2025 112,774.0017 Apr 2026 75,154.30188$25.64
long17 Apr 2026 75,154.302 Jun 2026 71,408.9046−$5.33
short2 Jun 2026 71,408.9019 Aug 2026 64,725.4078$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.

ScriptSharesTypeNetTradesMax drawdown
Average Highest High and Lowest Low Swinger Strategy this page—v4 strategy+6.4%2049.6%
Alex Days HiLo Rajib by 14rajibhighest lowestv4 strategyNo trades on this market
Donchian Strat EXMO by pskoroplashighest lowestv4 strategy+12.1%2268.0%
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%
eswaran ab by ESWARMONK2515lowest highestv4 strategy+8.4%1339.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 8 msWith a workaround 1,000 bars in 31 msNot measured
PineTSNo 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)