Pine Script v4 · Strategy
Hi-Lo Channel Strategy
A Pine Script v4 strategy built on SMA (ha_h, 5). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays no commission. 3 settings; defaults include High-Based MA 5 and Low-Based MA 5.
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 Hi-Lo Channel Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 10 of 10 trades.
- How did Hi-Lo Channel Strategy do on BTCUSDT 1D with default settings?
- +19.99%
- From 26 Jan 2024 to 21 Oct 2026, over 41 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Hi-Lo Channel 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 Hi-Lo Channel Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Hi-Lo Channel Strategy run in Zeal Terminal?
- Yes
- It compiles in 15 ms and runs 1,000 bars in 50 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +19.99%
- $99.96
- Buy and hold
- +102.5%
- same period
- Closed trades
- 41
- 16 won · 25 lost
- Profitable
- 39.0%
- of closed trades
- Profit factor
- 1.13
- gross profit ÷ gross loss
- Max drawdown
- 42.87%
- −$325.98
One run with the author's default settings, $500 starting capital, commission as the script sets it. 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.
-
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 security → request.security, heikinashi → ticker.heikinashi, sma → ta.sma.
v4 → v5
VerifiedSame 41 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 4: //@version=4 → //@version=5
- Line 9: security → request.security
- Line 9: heikinashi → ticker.heikinashi
- Line 10: security → request.security
- Line 10: heikinashi → ticker.heikinashi
- Line 11: security → request.security
6 more edits
- Line 11: heikinashi → ticker.heikinashi
- Line 22: sma → ta.sma
- Line 23: sma → ta.sma
- Line 27: sma → ta.sma
- Line 28: sma → ta.sma
- Line 34: strategy.entry(…, 100) → strategy.entry(…, strategy.long)
⋯// shiner.crypto@gmail.com-//@version=4+//@version=5strategy("Hi-Lo Channel Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, initial_capital=500, default_qty_value=100, currency="USD")⋯ha = input(true, "Use Heikin Ashi OHCL values (on real chart)?")-ha_h = security(heikinashi(syminfo.tickerid), timeframe.period, high)+ha_h = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)-ha_l = security(heikinashi(syminfo.tickerid), timeframe.period, low)+ha_l = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low)-ha_c = security(heikinashi(syminfo.tickerid), timeframe.period, close)+ha_c = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)float mah = na⋯if ha == true- mah := sma(ha_h, lenh)+ mah := ta.sma(ha_h, lenh)- mal := sma(ha_l, lenl)+ mal := ta.sma(ha_l, lenl) longCondition := ha_c > mah⋯if ha == false- mah := sma(high, lenh)+ mah := ta.sma(high, lenh)- mal := sma(low, lenl)+ mal := ta.sma(low, lenl) longCondition := close > mah⋯if (longCondition)- strategy.entry("Buy", 100)+ strategy.entry("Buy", strategy.long)if (shortCondition)⋯Same 41 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 8: input() → input.bool()
⋯strategy("Hi-Lo Channel Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, initial_capital=500, default_qty_value=100, currency="USD")-lenh = input(5, "High-Based MA")+lenh = input.int(5, "High-Based MA")-lenl = input (5, "Low-Based MA")+lenl = input.int (5, "Low-Based MA")-ha = input(true, "Use Heikin Ashi OHCL values (on real chart)?")+ha = input.bool(true, "Use Heikin Ashi OHCL values (on real chart)?")ha_h = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)⋯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: 41 before, 38 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.
⋯// shiner.crypto@gmail.com-//@version=5+//@version=6strategy("Hi-Lo Channel Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, initial_capital=500, default_qty_value=100, currency="USD")⋯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 |
|---|---|---|---|
| High-Based MA | 5 | int | mah |
| Low-Based MA | 5 | int | mal |
| Use Heikin Ashi OHCL values (on real chart)? | true | bool | line 21 line 26 |
What it calculates
- SMA (
sma,ta.smain v5)ha_h, High-Based MA (5)mah · line 22 - SMA (
sma,ta.smain v5)ha_l, Low-Based MA (5)mal · line 23
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 Buy long | (longCondition) | On | 34 |
| Close Buy | (shortCondition) | On | 36 |
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 data3 security call(s), none with lookahead on.
- 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 | +20.0% | +102.5% | 41 | 39% | 1.13 | 42.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +5.8% | +5.5% | 38 | 32% | 1.16 | 13.9% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +6.1% | +9.8% | 38 | 24% | 1.03 | 56.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −2.8% | +8.4% | 36 | 31% | 0.95 | 18.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −11.3% | +16.7% | 40 | 43% | 0.96 | 66.9% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +28.1% | +21.5% | 34 | 44% | 1.70 | 10.6% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +53.8% | +148.3% | 35 | 46% | 1.27 | 48.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +20.7% | +17.1% | 35 | 40% | 1.80 | 6.4% | 8 May 2026 – 21 Oct 2026 |
Higher-timeframe data for request.security(): heikinashi:SYMBOL D (Binance BTCUSDT 1d, as Heikin-Ashi by the engine), heikinashi:BINANCE:BTCUSDT D (Binance BTCUSDT 1d, as Heikin-Ashi by the engine), fetched from Binance's public market data for each market.
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 | 11 | 45% | −$17.20 |
| Sideways market | 23 | 39% | $212.11 |
| Falling market | 7 | 29% | −$94.95 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
53.1%
The 95th percentile of the worst drawdown when the same 41 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 27.4% to 53.1%; the tick is what actually happened, 41.9%. Order luck alone moves it this much.
All 41 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 31 Jan 2024 42,941.10 | 17 Mar 2024 65,300.60 | 46 | $260.35 |
| long | 26 Mar 2024 69,880.00 | 3 Apr 2024 65,464.00 | 8 | −$48.05 |
| long | 9 Apr 2024 71,620.00 | 14 Apr 2024 63,924.50 | 5 | −$76.54 |
| long | 23 Apr 2024 66,819.30 | 28 Apr 2024 63,462.00 | 5 | −$31.94 |
| long | 5 May 2024 63,892.00 | 12 Jun 2024 67,314.20 | 38 | $32.34 |
| long | 2 Jul 2024 62,900.00 | 5 Jul 2024 57,050.00 | 3 | −$59.17 |
| long | 15 Jul 2024 60,797.90 | 26 Jul 2024 65,799.90 | 11 | $47.47 |
| long | 28 Jul 2024 67,896.50 | 1 Aug 2024 64,628.00 | 4 | −$30.06 |
| long | 10 Aug 2024 60,838.00 | 28 Aug 2024 59,415.00 | 18 | −$13.90 |
| long | 11 Sep 2024 57,636.00 | 2 Oct 2024 60,804.90 | 21 | $31.92 |
| long | 8 Oct 2024 62,224.00 | 10 Oct 2024 60,636.00 | 2 | −$15.63 |
| long | 13 Oct 2024 63,206.20 | 24 Oct 2024 66,668.60 | 11 | $32.69 |
| long | 29 Oct 2024 69,962.20 | 4 Nov 2024 68,776.00 | 6 | −$10.67 |
| long | 7 Nov 2024 75,572.00 | 27 Nov 2024 91,965.20 | 20 | $134.23 |
| long | 16 Dec 2024 104,464.00 | 20 Dec 2024 97,461.90 | 4 | −$50.48 |
| long | 4 Jan 2025 98,174.20 | 9 Jan 2025 95,060.60 | 5 | −$22.28 |
| long | 16 Jan 2025 100,497.00 | 28 Jan 2025 102,083.00 | 12 | $10.73 |
| long | 21 Feb 2025 98,305.00 | 25 Feb 2025 91,552.90 | 4 | −$47.46 |
| long | 3 Mar 2025 94,270.00 | 10 Mar 2025 80,734.50 | 7 | −$92.40 |
| long | 25 Mar 2025 87,498.20 | 30 Mar 2025 82,648.50 | 5 | −$30.55 |
| long | 13 Apr 2025 85,276.90 | 6 May 2025 94,733.70 | 23 | $57.73 |
| long | 8 May 2025 97,030.50 | 30 May 2025 105,590.00 | 22 | $51.02 |
| long | 10 Jun 2025 110,263.00 | 14 Jun 2025 106,067.00 | 4 | −$23.95 |
| long | 25 Jun 2025 106,083.00 | 2 Aug 2025 113,298.00 | 38 | $41.17 |
| long | 8 Aug 2025 117,472.00 | 17 Aug 2025 117,381.00 | 9 | −$0.50 |
| long | 4 Sep 2025 111,706.00 | 23 Sep 2025 112,651.00 | 19 | $5.47 |
| long | 30 Sep 2025 114,312.00 | 11 Oct 2025 112,774.00 | 11 | −$8.76 |
| long | 27 Oct 2025 114,559.00 | 31 Oct 2025 108,323.00 | 4 | −$34.99 |
| long | 11 Nov 2025 106,011.00 | 14 Nov 2025 99,692.00 | 3 | −$36.23 |
| long | 28 Nov 2025 91,333.90 | 2 Dec 2025 86,286.00 | 4 | −$31.59 |
| long | 4 Dec 2025 93,429.90 | 15 Dec 2025 88,172.20 | 11 | −$30.39 |
| long | 4 Jan 2026 90,628.00 | 20 Jan 2026 92,631.00 | 16 | $11.26 |
| long | 5 Mar 2026 72,666.80 | 9 Mar 2026 65,971.20 | 4 | −$47.99 |
| long | 17 Mar 2026 74,884.70 | 20 Mar 2026 69,930.00 | 3 | −$31.29 |
| long | 7 Apr 2026 68,853.70 | 29 Apr 2026 76,342.80 | 22 | $48.03 |
| long | 3 May 2026 78,686.80 | 17 May 2026 78,148.10 | 14 | −$3.35 |
| long | 14 Jun 2026 64,458.00 | 19 Jun 2026 62,958.00 | 5 | −$11.32 |
| long | 4 Jul 2026 62,583.30 | 26 Jul 2026 64,375.00 | 22 | $13.60 |
| long | 6 Aug 2026 64,665.20 | 12 Aug 2026 63,600.00 | 6 | −$8.05 |
| long | 19 Aug 2026 64,725.40 | 9 Sep 2026 78,455.80 | 21 | $101.92 |
| long | 19 Sep 2026 80,883.90 | 8 Oct 2026 83,321.80 | 19 | $17.55 |
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 |
|---|---|---|---|---|---|
| Hi-Lo Channel Strategy this page | — | v4 strategy | +20.0% | 41 | 42.9% |
| Follow the Crypto Shorts by xtradernet | sma | v4 strategy | No trades on this market | ||
| buy down and sell high trend 200 sma and ma cross by willi130503 | sma | v4 strategy | No trades on this market | ||
| Mayer Multiple Strategy by xtradernet | sma | v4 strategy | No trades on this market | ||
| Moving Average Cross Strategy early Closing by Geduldtrader | sma | v4 strategy | +73.8% | 20 | 151.5% |
| MFI Simple Strategy by OztheWoz | sma | v5 strategy | −0.2% | 28 | 3.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 15 ms | With a workaround 1,000 bars in 50 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as 100 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 34) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market. Data the page supplies at the chart's own timeframe (another symbol, or Heikin-Ashi) reaches the script one bar later in Zeal Terminal's engine than on TradingView.
“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/// © shiner_trading// shiner.crypto@gmail.com//@version=4strategy("Hi-Lo Channel Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, initial_capital=500, default_qty_value=100, currency="USD")lenh = input(5, "High-Based MA")lenl = input (5, "Low-Based MA")ha = input(true, "Use Heikin Ashi OHCL values (on real chart)?")ha_h = security(heikinashi(syminfo.tickerid), timeframe.period, high)ha_l = security(heikinashi(syminfo.tickerid), timeframe.period, low)ha_c = security(heikinashi(syminfo.tickerid), timeframe.period, close)float mah = nafloat mal = nalongCondition = falseshortCondition = false/// HA is the check mark box in the configuration./// IF "Use Heikin Ashi OHCL values?" is true, then the strategy will use the Heikin Ashi close values// and therefore give the same buy/sell signals regardless of what chart you are viewing./// That being said, if "Use Heikin Ashi OHCL values?" is FALSE, yet you are viewing Heikin Ashi candles on your chart,// then logically you will also get the same buy/sell signalsif ha == true mah := sma(ha_h, lenh) mal := sma(ha_l, lenl) longCondition := ha_c > mah shortCondition := ha_c < malif ha == false mah := sma(high, lenh) mal := sma(low, lenl) longCondition := close > mah shortCondition := close < malplot(mah, color=color.green)plot(mal, color=color.red)if (longCondition) strategy.entry("Buy", 100)if (shortCondition) strategy.close("Buy")