Pine Script v5 · Strategy
Highest High and Lowest Low Channel Strategy
A Pine Script v5 strategy built on Highest (high, 20) and Lowest (low, 20). 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 is one contract and pays no commission. 2 settings; defaults include Length 20.
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 Highest High and Lowest Low Channel Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
- How did Highest High and Lowest Low Channel Strategy do on BTCUSDT 1D with default settings?
- −3.71%
- From 26 Jan 2024 to 21 Oct 2026, over 26 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Highest High and Lowest Low Channel Strategy 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: 26 before, 149 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Highest High and Lowest Low Channel Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Highest High and Lowest Low Channel Strategy run in Zeal Terminal?
- Yes
- It compiles in 29 ms and runs 1,000 bars in 21 ms, in the browser.
BTCUSDT · 1D · default settings
- HH
- LL
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −3.71%
- −$37,066.90
- Buy and hold
- +102.5%
- same period
- Closed trades
- 26
- 10 won · 16 lost
- Profitable
- 38.5%
- of closed trades
- Profit factor
- 0.72
- gross profit ÷ gross loss
- Max drawdown
- 7.88%
- −$79,063.10
One run with the author's default settings, $1,000,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
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
1 setting has no label
In the settings dialog length (line 5) shows an empty name. The labels on this page come from the variable names.
-
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 |
|---|---|---|---|
| Length (no label in the script) | 20 | int | hh ll |
| Trade reverse | false | bool | iff_2 possig |
What it calculates
- Highesthigh, Length (20)
hh · line 7 - Lowestlow, Length (20)
ll · line 8
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 | possig == 1 | On | 15 |
| Open Short short | possig == -1 | On | 17 |
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 | −3.7% | +102.5% | 26 | 38% | 0.72 | 7.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.9% | +5.5% | 19 | 32% | 1.33 | 1.5% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.1% | +9.8% | 18 | 50% | 1.28 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 21 | 33% | 1.09 | 0.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 22 | 32% | 0.79 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 20 | 40% | 1.71 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 20 | 30% | 1.16 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 26 | 35% | 0.61 | 0.0% | 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 | 7 | 29% | −$32,761.00 |
| Sideways market | 15 | 40% | −$8,525.83 |
| Falling market | 4 | 50% | $4,219.93 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
9.2%
The 95th percentile of the worst drawdown when the same 26 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 4.6% to 9.2%; the tick is what actually happened, 7.3%. Order luck alone moves it this much.
All 26 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 27 Feb 2024 54,476.50 | 2 May 2024 58,365.00 | 65 | $3,888.49 |
| short | 2 May 2024 58,365.00 | 16 May 2024 66,206.50 | 14 | −$7,841.54 |
| long | 16 May 2024 66,206.50 | 15 Jun 2024 66,044.00 | 30 | −$162.52 |
| short | 15 Jun 2024 66,044.00 | 16 Jul 2024 64,724.10 | 31 | $1,319.93 |
| long | 16 Jul 2024 64,724.10 | 5 Aug 2024 58,161.00 | 20 | −$6,563.06 |
| short | 5 Aug 2024 58,161.00 | 24 Aug 2024 64,037.20 | 19 | −$5,876.24 |
| long | 24 Aug 2024 64,037.20 | 7 Sep 2024 53,963.00 | 14 | −$10,074.30 |
| short | 7 Sep 2024 53,963.00 | 19 Sep 2024 61,760.00 | 12 | −$7,797.01 |
| long | 19 Sep 2024 61,760.00 | 25 Feb 2025 91,552.90 | 159 | $29,792.90 |
| short | 25 Feb 2025 91,552.90 | 23 Apr 2025 93,443.00 | 57 | −$1,890.11 |
| long | 23 Apr 2025 93,443.00 | 6 Jun 2025 101,509.00 | 44 | $8,065.70 |
| short | 6 Jun 2025 101,509.00 | 10 Jul 2025 111,234.00 | 34 | −$9,725.31 |
| long | 10 Jul 2025 111,234.00 | 2 Aug 2025 113,298.00 | 23 | $2,063.92 |
| short | 2 Aug 2025 113,298.00 | 14 Aug 2025 123,306.00 | 12 | −$10,008.50 |
| long | 14 Aug 2025 123,306.00 | 26 Aug 2025 110,112.00 | 12 | −$13,194.50 |
| short | 26 Aug 2025 110,112.00 | 17 Sep 2025 116,789.00 | 22 | −$6,676.98 |
| long | 17 Sep 2025 116,789.00 | 26 Sep 2025 108,994.00 | 9 | −$7,794.47 |
| short | 26 Sep 2025 108,994.00 | 2 Oct 2025 118,595.00 | 6 | −$9,600.50 |
| long | 2 Oct 2025 118,595.00 | 5 Nov 2025 101,497.00 | 34 | −$17,097.80 |
| short | 5 Nov 2025 101,497.00 | 5 Jan 2026 91,529.70 | 61 | $9,967.49 |
| long | 5 Jan 2026 91,529.70 | 26 Jan 2026 86,670.40 | 21 | −$4,859.38 |
| short | 26 Jan 2026 86,670.40 | 5 Mar 2026 72,666.80 | 38 | $14,003.60 |
| long | 5 Mar 2026 72,666.80 | 23 May 2026 75,539.50 | 79 | $2,872.73 |
| short | 23 May 2026 75,539.50 | 15 Jul 2026 65,044.00 | 53 | $10,495.50 |
| long | 15 Jul 2026 65,044.00 | 16 Sep 2026 75,644.50 | 63 | $10,600.50 |
| short | 16 Sep 2026 75,644.50 | 22 Sep 2026 86,620.00 | 6 | −$10,975.50 |
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 |
|---|---|---|---|---|---|
| Highest High and Lowest Low Channel Strategy this page | — | v5 strategy | −3.7% | 26 | 7.9% |
| 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% |
| 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% |
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.
- 2 settings use the untyped input() (line 5, 6). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 26 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.int()
- Line 6: input() → input.bool()
⋯strategy('Highest High and Lowest Low Channel Strategy', overlay=true)-length = input(20)+length = input.int(20)-reverse = input(false, title='Trade reverse')+reverse = input.bool(false, title='Trade reverse')hh = ta.highest(high, length)⋯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: 26 before, 149 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.
⋯// © ceyhun-//@version=5+//@version=6strategy('Highest High and Lowest Low Channel Strategy', overlay=true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 29 ms | Yes 1,000 bars in 21 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/// © ceyhun//@version=5strategy('Highest High and Lowest Low Channel Strategy', overlay=true)length = input(20)reverse = input(false, title='Trade reverse')hh = ta.highest(high, length)ll = ta.lowest(low, length)pos = 0.0iff_1 = close < ll[1] ? -1 : nz(pos[1], 0)pos := close > hh[1] ? 1 : iff_1iff_2 = reverse and pos == -1 ? 1 : pospossig = reverse and pos == 1 ? -1 : iff_2if possig == 1 strategy.entry('Long', strategy.long)if possig == -1 strategy.entry('Short', strategy.short)barcolor(possig == -1 ? color.red : possig == 1 ? color.green : color.blue)plot(hh[1], color=color.new(color.green, 0), title='HH', linewidth=2)plot(ll[1], color=color.new(color.red, 0), title='LL', linewidth=2)