Pine Script v4 · Strategy
HTF High-Low Repaint Strategy
A Pine Script v4 strategy with no technical-analysis calculation. 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.01% commission. 6 settings; defaults include Resolution 3M, HTFMultiplier 22 and Offset 0.
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 HTF High-Low Repaint Strategy repaint?
- Yes
- At least one pattern in the source can repaint: higher-timeframe data.
- How did HTF High-Low Repaint Strategy do on BTCUSDT 1D with default settings?
- +126.90%
- From 26 Jan 2024 to 21 Oct 2026, over 3 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can HTF High-Low Repaint 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 HTF High-Low Repaint Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does HTF High-Low Repaint Strategy run in Zeal Terminal?
- Yes
- It compiles in 13 ms and runs 1,000 bars in 106 ms, in the browser.
BTCUSDT · 1D · default settings
- HTF High
- HTF Low
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +126.90%
- $25,380.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 3
- 3 won · 0 lost
- Profitable
- 100.0%
- of closed trades
- Profit factor
- 5,593.21
- gross profit ÷ gross loss
- Max drawdown
- 11.42%
- −$4,645.95
One run with the author's default settings, $20,000 starting capital, commission as the script sets it. A short 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
4 settings have no label
In the settings dialog resolution (line 8), HTFMultiplier (line 9), offset (line 10), lookahead (line 11) show 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.
-
Note
Uses an argument v6 removed
when = on line 60, 61. 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 security → request.security, tostring → str.tostring, round → math.round, min → math.min.
- 2 strategy calls use the when = argument (line 60, 61). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 3 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.time) → input.time()
- Line 6: input(type = input.time) → input.time()
- Line 8: input(type = input.resolution) → input.timeframe()
- Line 13: security → request.security
- Line 14: security → request.security
7 more edits
- Line 15: security → request.security
- Line 16: security → request.security
- Line 28: tostring → str.tostring
- Line 28: round → math.round
- Line 29: tostring → str.tostring
- Line 29: round → math.round
- Line 29: min → math.min
⋯// © HeWhoMustNotBeNamed-//@version=4+//@version=5strategy("HTF High/Low Repaint Strategy", overlay=true, initial_capital = 20000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)-i_startTime = input(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Start Time", type = input.time)+i_startTime = input.time(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Start Time")-i_endTime = input(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "End Time", type = input.time)+i_endTime = input.time(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "End Time")inDateRange = time >= i_startTime and time <= i_endTime-resolution = input("3M", type=input.resolution)+resolution = input.timeframe("3M")HTFMultiplier = input(22, minval=1, step=1)⋯gaps = false-f_secureSecurity_on_on(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)+f_secureSecurity_on_on(_symbol, _res, _src, _offset) => request.security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)-f_secureSecurity_on_off(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_off)+f_secureSecurity_on_off(_symbol, _res, _src, _offset) => request.security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_off)-f_secureSecurity_off_on(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_off, gaps=barmerge.gaps_on)+f_secureSecurity_off_on(_symbol, _res, _src, _offset) => request.security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_off, gaps=barmerge.gaps_on)-f_secureSecurity_off_off(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_off, gaps=barmerge.gaps_off)+f_secureSecurity_off_off(_symbol, _res, _src, _offset) => request.security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_off, gaps=barmerge.gaps_off)f_multiple_resolution(HTFMultiplier) => ⋯ target_Res_In_Min <= 0.751 ? "30S" :- target_Res_In_Min <= 1440 ? tostring(round(target_Res_In_Min)) :+ target_Res_In_Min <= 1440 ? str.tostring(math.round(target_Res_In_Min)) :- tostring(round(min(target_Res_In_Min / 1440, 365))) + "D"+ str.tostring(math.round(math.min(target_Res_In_Min / 1440, 365))) + "D"f_get_htfHighLow(resolution, HTFMultiplier, lookahead, gaps, offset)=>⋯Same 3 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 9: input() → input.int()
- Line 10: input() → input.int()
- Line 11: input() → input.bool()
- Line 60: when = buyCondition and inDateRange → if block
- Line 61: when = sellCondition and inDateRange → if block
⋯resolution = input.timeframe("3M")-HTFMultiplier = input(22, minval=1, step=1)+HTFMultiplier = input.int(22, minval=1, step=1)-offset = input(0, minval=0, step=1)+offset = input.int(0, minval=0, step=1)-lookahead = input(true)+lookahead = input.bool(true)gaps = false⋯sellCondition = nhigh < nhighlast and nlow < nlowlast-strategy.entry("Buy", strategy.long, when= buyCondition and inDateRange, oca_name="oca_buy", oca_type=strategy.oca.cancel)+if buyCondition and inDateRange+ strategy.entry("Buy", strategy.long, oca_name="oca_buy", oca_type=strategy.oca.cancel)-strategy.entry("Sell", strategy.short, when= sellCondition and inDateRange, oca_name="oca_sell", oca_type=strategy.oca.cancel)+if sellCondition and inDateRange+ strategy.entry("Sell", strategy.short, oca_name="oca_sell", oca_type=strategy.oca.cancel)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: 3 before, 105 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.
⋯// © HeWhoMustNotBeNamed-//@version=5+//@version=6strategy("HTF High/Low Repaint Strategy", overlay=true, initial_capital = 20000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)⋯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 |
|---|---|---|---|
| Start Time | timestamp("01 Jan 2010 00:00 +0000") | time | inDateRange |
| End Time | timestamp("01 Jan 2099 00:00 +0000") | time | inDateRange |
| Resolution (no label in the script) | 3M | timeframe (written input.resolution) | derivedResolution nhigh nlow nhighlast nlowlast |
| HTFMultiplier (no label in the script) | 22 | int · min 1 · step 1 | target_Res_In_Min derivedResolution nhigh nlow nhighlast nlowlast |
| Offset (no label in the script) | 0 | int · min 0 · step 1 | nhigh_on_on nlow_on_on nhigh_on_off nlow_on_off nhigh_off_on nlow_off_on nhigh_off_off nlow_off_off nhigh nlow nhighlast nlowlast |
| Lookahead (no label in the script) | true | bool | nhigh nlow nhighlast nlowlast |
What it calculates
No technical-analysis calculation: the script works on prices and settings directly.
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 | buyCondition and inDateRange | On | 60 |
| Open Sell short | sellCondition and inDateRange | On | 61 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- CheckHigher-timeframe data2 security call(s) use lookahead_on (line 13, 14). Without a [1] offset this reads future bars in history.
- 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 | +126.9% | +102.5% | 3 | 100% | 5,593.21 | 11.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.0% | +5.5% | 0 | 0% | 0.00 | 8.9% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +530.3% | +9.8% | 6 | 100% | 8,413.97 | 13.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +30.5% | +8.4% | 1 | 100% | 2,337.33 | 3.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +193.9% | +16.7% | 6 | 67% | 5.53 | 54.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +14.8% | +21.5% | 1 | 100% | 1,291.25 | 11.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +317.4% | +148.3% | 6 | 100% | 7,604.34 | 11.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −20.1% | +17.1% | 1 | 0% | 0.00 | 26.7% | 8 May 2026 – 21 Oct 2026 |
Higher-timeframe data for request.security(): BINANCE:BTCUSDT 3M (aggregated from Binance BTCUSDT 1M), 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 | 0 | — | $0.00 |
| Sideways market | 3 | 100% | $25,384.50 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
0.0%
The 95th percentile of the worst drawdown when the same 3 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.0% to 0.0%; the tick is what actually happened, 0.0%. Order luck alone moves it this much.
All 3 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 27 Jan 2024 41,823.50 | 2 Jul 2024 62,900.00 | 157 | $10,072.80 |
| short | 2 Jul 2024 62,900.00 | 2 Oct 2024 60,804.90 | 92 | $995.75 |
| long | 2 Oct 2024 60,804.90 | 2 Jan 2026 88,839.10 | 457 | $14,316.00 |
Similar scripts
No other indicator or strategy here shares enough of its calculations.
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 13 ms | With a workaround 1,000 bars in 106 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
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.
“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/// © HeWhoMustNotBeNamed//@version=4strategy("HTF High/Low Repaint Strategy", overlay=true, initial_capital = 20000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)i_startTime = input(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Start Time", type = input.time)i_endTime = input(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "End Time", type = input.time)inDateRange = time >= i_startTime and time <= i_endTimeresolution = input("3M", type=input.resolution)HTFMultiplier = input(22, minval=1, step=1)offset = input(0, minval=0, step=1)lookahead = input(true)gaps = falsef_secureSecurity_on_on(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)f_secureSecurity_on_off(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_off)f_secureSecurity_off_on(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_off, gaps=barmerge.gaps_on)f_secureSecurity_off_off(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_off, gaps=barmerge.gaps_off)f_multiple_resolution(HTFMultiplier) => target_Res_In_Min = timeframe.multiplier * HTFMultiplier * ( timeframe.isseconds ? 1. / 60. : timeframe.isminutes ? 1. : timeframe.isdaily ? 1440. : timeframe.isweekly ? 7. * 24. * 60. : timeframe.ismonthly ? 30.417 * 24. * 60. : na) target_Res_In_Min <= 0.0417 ? "1S" : target_Res_In_Min <= 0.167 ? "5S" : target_Res_In_Min <= 0.376 ? "15S" : target_Res_In_Min <= 0.751 ? "30S" : target_Res_In_Min <= 1440 ? tostring(round(target_Res_In_Min)) : tostring(round(min(target_Res_In_Min / 1440, 365))) + "D"f_get_htfHighLow(resolution, HTFMultiplier, lookahead, gaps, offset)=> derivedResolution = resolution == ""?f_multiple_resolution(HTFMultiplier):resolution nhigh_on_on = f_secureSecurity_on_on(syminfo.tickerid, derivedResolution, high, offset) nlow_on_on = f_secureSecurity_on_on(syminfo.tickerid, derivedResolution, low, offset) nhigh_on_off = f_secureSecurity_on_off(syminfo.tickerid, derivedResolution, high, offset) nlow_on_off = f_secureSecurity_on_off(syminfo.tickerid, derivedResolution, low, offset) nhigh_off_on = f_secureSecurity_off_on(syminfo.tickerid, derivedResolution, high, offset) nlow_off_on = f_secureSecurity_off_on(syminfo.tickerid, derivedResolution, low, offset) nhigh_off_off = f_secureSecurity_off_off(syminfo.tickerid, derivedResolution, high, offset) nlow_off_off = f_secureSecurity_off_off(syminfo.tickerid, derivedResolution, low, offset) nhigh = lookahead and gaps ? nhigh_on_on : lookahead and not gaps ? nhigh_on_off : not lookahead and gaps ? nhigh_off_on : not lookahead and not gaps ? nhigh_off_off : na nlow = lookahead and gaps ? nlow_on_on : lookahead and not gaps ? nlow_on_off : not lookahead and gaps ? nlow_off_on : not lookahead and not gaps ? nlow_off_off : na [nhigh, nlow] [nhigh, nlow] = f_get_htfHighLow(resolution, HTFMultiplier, lookahead, gaps, offset)[nhighlast, nlowlast] = f_get_htfHighLow(resolution, HTFMultiplier, lookahead, gaps, offset+1)plot(nhigh , title="HTF High",style=plot.style_circles, color=color.green, linewidth=1) plot(nlow , title="HTF Low",style=plot.style_circles, color=color.red, linewidth=1)buyCondition = nhigh > nhighlast and nlow > nlowlastsellCondition = nhigh < nhighlast and nlow < nlowlaststrategy.entry("Buy", strategy.long, when= buyCondition and inDateRange, oca_name="oca_buy", oca_type=strategy.oca.cancel)strategy.entry("Sell", strategy.short, when= sellCondition and inDateRange, oca_name="oca_sell", oca_type=strategy.oca.cancel)