Pine Script v4 · Strategy
GRB Long
A Pine Script v4 strategy built on Highest (high, 21) and Lowest (low, 21). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 5 settings; defaults include High Days 21, Low Days 21 and Start Date 1.
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 GRB Long repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 9 of 9 trades.
- How did GRB Long do on BTCUSDT 1D with default settings?
- +13.91%
- From 26 Jan 2024 to 21 Oct 2026, over 33 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can GRB Long 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 GRB Long use a stop loss?
- Yes
- strategy.exit sets a stop on line 22.
- Does GRB Long run in Zeal Terminal?
- Yes
- It compiles in 8 ms and runs 1,000 bars in 25 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +13.91%
- $13,909.90
- Buy and hold
- +102.5%
- same period
- Closed trades
- 33
- 10 won · 23 lost
- Profitable
- 30.3%
- of closed trades
- Profit factor
- 1.17
- gross profit ÷ gross loss
- Max drawdown
- 31.15%
- −$42,614.60
One run with the author's default settings, $100,000 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 commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
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 21. 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 highest → ta.highest, lowest → ta.lowest.
- 1 strategy call uses the when = argument (line 21). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 33 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 8: input(type = input.integer) → input.int()
- Line 10: input(type = input.integer) → input.int()
- Line 12: input(type = input.integer) → input.int()
- Line 17: highest → ta.highest
- Line 18: lowest → ta.lowest
⋯// © omkarkondhekar-//@version=4+//@version=5strategy("GRBLong", overlay=true)-highInput = input(title = "High Days", type = input.integer, defval = 21, minval = 11)+highInput = input.int(title = "High Days", defval = 21, minval = 11)-lowInput = input(title = "Low Days", type = input.integer, defval = 21, minval = 5)+lowInput = input.int(title = "Low Days", defval = 21, minval = 5)// Configure backtest start date with inputs-startDate = input(title="Start Date", type=input.integer,+startDate = input.int(title="Start Date", defval=1, minval=1, maxval=31)-startMonth = input(title="Start Month", type=input.integer,+startMonth = input.int(title="Start Month", defval=1, minval=1, maxval=12)-startYear = input(title="Start Year", type=input.integer,+startYear = input.int(title="Start Year", defval=2019, minval=1800, maxval=2100)⋯ startYear, startMonth, startDate, 0, 0))-high21 = highest(high, highInput)+high21 = ta.highest(high, highInput)-low21 = lowest(low, lowInput)+low21 = ta.lowest(low, lowInput)diff = high21 - low21⋯Same 33 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 21: when = longEntrySignal and afterStartDate → if block
⋯longEntrySignal = low > low21 + (diff * 0.382) and close[1] > open[1] -strategy.entry("Long", strategy.long, when = longEntrySignal and afterStartDate)+if longEntrySignal and afterStartDate+ strategy.entry("Long", strategy.long)strategy.exit("Long Exit", "Long", stop = low21 + (diff * 0.236))⋯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: 33 before, 30 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.
⋯// © omkarkondhekar-//@version=5+//@version=6strategy("GRBLong", overlay=true)⋯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 Days | 21 | int (written input.integer) · min 11 | high21 |
| Low Days | 21 | int (written input.integer) · min 5 | low21 |
| Start Date | 1 | int (written input.integer) · min 1 · max 31 | afterStartDate |
| Start Month | 1 | int (written input.integer) · min 1 · max 12 | afterStartDate |
| Start Year | 2019 | int (written input.integer) · min 1800 · max 2100 | afterStartDate |
What it calculates
- Highest (
highest,ta.highestin v5)high, High Days (21)high21 · line 17 - Lowest (
lowest,ta.lowestin v5)low, Low Days (21)low21 · line 18
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 | longEntrySignal and afterStartDate | On | 21 |
| Exit Long Exit stop | every bar | On | 22 |
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 | +13.9% | +102.5% | 33 | 30% | 1.17 | 31.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −4.5% | +5.5% | 37 | 22% | 0.85 | 14.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1.0% | +9.8% | 37 | 22% | 0.84 | 2.7% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.2% | +8.4% | 37 | 19% | 0.86 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 32 | 31% | 0.92 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 32 | 19% | 1.25 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.3% | +148.3% | 30 | 37% | 1.41 | 0.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.1% | +17.1% | 31 | 32% | 1.40 | 0.1% | 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 | 10 | 40% | −$187.20 |
| Sideways market | 16 | 31% | $23,684.70 |
| Falling market | 7 | 14% | −$9,587.66 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
36.2%
The 95th percentile of the worst drawdown when the same 33 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 17.1% to 36.2%; the tick is what actually happened, 29.7%. Order luck alone moves it this much.
All 33 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 16 Feb 2024 51,880.00 | 22 Mar 2024 62,491.20 | 35 | $10,611.20 |
| long | 26 Mar 2024 69,880.00 | 13 Apr 2024 65,312.30 | 18 | −$4,567.68 |
| long | 24 Apr 2024 66,414.00 | 27 Apr 2024 62,714.70 | 3 | −$3,699.27 |
| long | 5 May 2024 63,892.00 | 11 Jun 2024 67,653.80 | 37 | $3,761.75 |
| long | 14 Jul 2024 59,204.00 | 3 Aug 2024 60,664.90 | 20 | $1,460.93 |
| long | 10 Aug 2024 60,838.00 | 30 Aug 2024 58,184.00 | 20 | −$2,653.99 |
| long | 14 Sep 2024 60,498.00 | 9 Oct 2024 60,903.10 | 25 | $405.08 |
| long | 13 Oct 2024 63,206.20 | 20 Dec 2024 94,713.30 | 68 | $31,507.10 |
| long | 26 Dec 2024 99,429.60 | 27 Dec 2024 95,791.60 | 1 | −$3,638.01 |
| long | 16 Jan 2025 100,497.00 | 3 Feb 2025 94,054.90 | 18 | −$6,442.48 |
| long | 16 Feb 2025 97,569.70 | 18 Feb 2025 94,824.40 | 2 | −$2,745.24 |
| long | 7 Mar 2025 89,931.90 | 9 Mar 2025 83,265.60 | 2 | −$6,666.28 |
| long | 21 Mar 2025 84,223.40 | 3 Apr 2025 82,022.70 | 13 | −$2,200.66 |
| long | 13 Apr 2025 85,276.90 | 31 May 2025 103,376.00 | 48 | $18,099.20 |
| long | 9 Jun 2025 105,734.00 | 13 Jun 2025 103,069.00 | 4 | −$2,664.81 |
| long | 17 Jun 2025 106,795.00 | 20 Jun 2025 102,770.00 | 3 | −$4,025.01 |
| long | 25 Jun 2025 106,083.00 | 1 Aug 2025 115,764.00 | 37 | $9,681.07 |
| long | 9 Aug 2025 116,675.00 | 18 Aug 2025 114,883.00 | 9 | −$1,792.00 |
| long | 12 Sep 2025 115,483.00 | 24 Sep 2025 111,352.00 | 12 | −$4,130.85 |
| long | 1 Oct 2025 114,049.00 | 10 Oct 2025 112,769.00 | 9 | −$1,280.10 |
| long | 14 Oct 2025 115,166.00 | 16 Oct 2025 107,711.00 | 2 | −$7,454.89 |
| long | 27 Oct 2025 114,559.00 | 30 Oct 2025 107,136.00 | 3 | −$7,423.36 |
| long | 2 Nov 2025 110,098.00 | 3 Nov 2025 106,566.00 | 1 | −$3,532.14 |
| long | 4 Dec 2025 93,429.90 | 15 Dec 2025 86,363.60 | 11 | −$7,066.36 |
| long | 3 Jan 2026 89,995.10 | 20 Jan 2026 89,460.30 | 17 | −$534.88 |
| long | 22 Feb 2026 67,975.90 | 23 Feb 2026 64,569.00 | 1 | −$3,406.97 |
| long | 27 Feb 2026 67,485.20 | 28 Feb 2026 64,813.90 | 1 | −$2,671.29 |
| long | 4 Mar 2026 68,338.00 | 22 Mar 2026 67,638.80 | 18 | −$699.23 |
| long | 9 Apr 2026 71,069.90 | 17 May 2026 76,804.90 | 38 | $5,734.93 |
| long | 5 Jul 2026 63,144.00 | 28 Jul 2026 62,821.70 | 23 | −$322.32 |
| long | 7 Aug 2026 64,323.60 | 11 Aug 2026 63,379.80 | 4 | −$943.86 |
| long | 19 Aug 2026 64,725.40 | 12 Sep 2026 77,139.70 | 24 | $12,414.30 |
| long | 20 Sep 2026 81,250.00 | 12 Oct 2026 82,046.10 | 22 | $796.06 |
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 |
|---|---|---|---|---|---|
| GRB Long this page | — | v4 strategy | +13.9% | 33 | 31.1% |
| 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% |
| 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% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 8 ms | Yes 1,000 bars in 25 ms | Not measured |
| PineTS | No v5 and v6 only | — | 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. 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/// © omkarkondhekar//@version=4strategy("GRBLong", overlay=true)highInput = input(title = "High Days", type = input.integer, defval = 21, minval = 11)lowInput = input(title = "Low Days", type = input.integer, defval = 21, minval = 5)// Configure backtest start date with inputsstartDate = input(title="Start Date", type=input.integer, defval=1, minval=1, maxval=31)startMonth = input(title="Start Month", type=input.integer, defval=1, minval=1, maxval=12)startYear = input(title="Start Year", type=input.integer, defval=2019, minval=1800, maxval=2100)// See if this bar's time happened on/after start dateafterStartDate = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0))high21 = highest(high, highInput)low21 = lowest(low, lowInput)diff = high21 - low21longEntrySignal = low > low21 + (diff * 0.382) and close[1] > open[1] strategy.entry("Long", strategy.long, when = longEntrySignal and afterStartDate)strategy.exit("Long Exit", "Long", stop = low21 + (diff * 0.236))plot(low21 + (diff * 0.382), color= color.green)plot(low21 + (diff * 0.236), color = color.red)