Pine Script v4 · Strategy
Grab Trading System
A Pine Script v4 strategy built on Highest (80) and Lowest (80). It has 7 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 4 settings; defaults include Longterm Period 80 and Shortterm Period 21.
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 Grab Trading System repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 5 of 5 trades.
- How did Grab Trading System do on BTCUSDT 1D with default settings?
- +21.10%
- From 26 Jan 2024 to 21 Oct 2026, over 17 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Grab Trading System 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 Grab Trading System use a stop loss?
- Yes
- strategy.exit sets a stop on line 19, 24.
- Does Grab Trading System run in Zeal Terminal?
- Yes
- It compiles in 16 ms and runs 1,000 bars in 38 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +21.10%
- $21,104.40
- Buy and hold
- +102.5%
- same period
- Closed trades
- 17
- 11 won · 6 lost
- Profitable
- 64.7%
- of closed trades
- Profit factor
- 1.47
- gross profit ÷ gross loss
- Max drawdown
- 21.58%
- −$30,523.20
One run with the author's default settings, $100,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 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 16, 17. 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, change → ta.change.
- 2 strategy calls use the when = argument (line 16, 17). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 17 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 9: highest → ta.highest
- Line 10: lowest → ta.lowest
- Line 11: highest → ta.highest
- Line 12: lowest → ta.lowest
- Line 16: strategy.entry(…, true) → strategy.entry(…, strategy.long)
- Line 17: strategy.entry(…, false) → strategy.entry(…, strategy.short)
- Line 27: change → ta.change
⋯// © LonesomeTheBlue-//@version=4+//@version=5strategy("Grab Trading System", overlay = true)⋯showtrend = input(defval = true, title = "Show Trend")-major_resistance = highest(flb)+major_resistance = ta.highest(flb)-major_support = lowest(flb)+major_support = ta.lowest(flb)-minor_resistance = highest(slb)+minor_resistance = ta.highest(slb)-minor_support = lowest(slb)+minor_support = ta.lowest(slb) ⋯trend := high > major_resistance[1] ? 1 : low < major_support[1] ? -1 : trend-strategy.entry("Buy", true, when = trend == 1 and low[1] == minor_support[1] and low > minor_support)+strategy.entry("Buy", strategy.long, when = trend == 1 and low[1] == minor_support[1] and low > minor_support)-strategy.entry("Sell", false, when = trend == -1 and high[1] == minor_resistance[1] and high < minor_resistance)+strategy.entry("Sell", strategy.short, when = trend == -1 and high[1] == minor_resistance[1] and high < minor_resistance)if strategy.position_size > 0⋯ strategy.close("Sell", comment ="Close Sell")-if strategy.position_size != 0 and change(trend)+if strategy.position_size != 0 and ta.change(trend) strategy.close_all()⋯Same 17 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.int()
- Line 7: input() → input.bool()
- Line 8: input() → input.bool()
- Line 16: when = trend == 1 and low[1] == minor_support[1] and low > minor_support → if block
- Line 17: when = trend == -1 and high[1] == minor_resistance[1] and high < minor_resistance → if block
⋯strategy("Grab Trading System", overlay = true)-flb = input(defval = 80, title = "Longterm Period", minval = 1)+flb = input.int(defval = 80, title = "Longterm Period", minval = 1)-slb = input(defval = 21, title = "Shortterm Period", minval = 1)+slb = input.int(defval = 21, title = "Shortterm Period", minval = 1)-showtarget = input(defval = true, title = "Show Target")+showtarget = input.bool(defval = true, title = "Show Target")-showtrend = input(defval = true, title = "Show Trend")+showtrend = input.bool(defval = true, title = "Show Trend")major_resistance = ta.highest(flb)⋯trend := high > major_resistance[1] ? 1 : low < major_support[1] ? -1 : trend-strategy.entry("Buy", strategy.long, when = trend == 1 and low[1] == minor_support[1] and low > minor_support)+if trend == 1 and low[1] == minor_support[1] and low > minor_support+ strategy.entry("Buy", strategy.long)-strategy.entry("Sell", strategy.short, when = trend == -1 and high[1] == minor_resistance[1] and high < minor_resistance)+if trend == -1 and high[1] == minor_resistance[1] and high < minor_resistance+ strategy.entry("Sell", strategy.short)if strategy.position_size > 0⋯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: 17 before, 28 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.
⋯// © LonesomeTheBlue-//@version=5+//@version=6strategy("Grab Trading System", 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 |
|---|---|---|---|
| Longterm Period | 80 | int · min 1 | major_resistance major_support |
| Shortterm Period | 21 | int · min 1 | minor_resistance minor_support |
| Show Target | true | bool | minr mins plot |
| Show Trend | true | bool | majr majs plot fill |
What it calculates
- Highest (
highest,ta.highestin v5)Longterm Period (80)major_resistance · line 9 - Lowest (
lowest,ta.lowestin v5)Longterm Period (80)major_support · line 10 - Highest (
highest,ta.highestin v5)Shortterm Period (21)minor_resistance · line 11 - Lowest (
lowest,ta.lowestin v5)Shortterm Period (21)minor_support · line 12
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 | trend == 1 and low[1] == minor_support[1] and low > minor_support | On | 16 |
| Open Sell short | trend == -1 and high[1] == minor_resistance[1] and high < minor_resistance | On | 17 |
| Exit Buy stop | strategy.position_size > 0 | On | 19 |
| Close Buy | high[1] == minor_resistance[1] and high < minor_resistance | On | 21 |
| Exit Sell stop | strategy.position_size < 0 | On | 24 |
| Close Sell | low[1] == minor_support[1] and low > minor_support | On | 26 |
| Close | strategy.position_size != 0 and change(trend) | On | 28 |
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 | +21.1% | +102.5% | 17 | 65% | 1.47 | 21.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.7% | +5.5% | 15 | 40% | 0.94 | 4.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.6% | +9.8% | 10 | 50% | 1.31 | 1.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.4% | +8.4% | 15 | 67% | 2.08 | 0.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.1% | +16.7% | 13 | 46% | 0.58 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 14 | 64% | 0.89 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 17 | 65% | 1.01 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.1% | +17.1% | 14 | 64% | 2.91 | 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 | 6 | 67% | $9,186.27 |
| Sideways market | 7 | 71% | $23,200.60 |
| Falling market | 4 | 50% | −$11,282.60 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
24.2%
The 95th percentile of the worst drawdown when the same 17 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 9.8% to 24.2%; the tick is what actually happened, 21.4%. Order luck alone moves it this much.
All 17 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 19 Jul 2024 63,987.90 | 7 Aug 2024 56,022.00 | 19 | $7,965.92 |
| short | 25 Aug 2024 64,157.00 | 6 Sep 2024 56,180.00 | 12 | $7,977.02 |
| short | 22 Sep 2024 63,349.00 | 12 Oct 2024 62,540.00 | 20 | $808.98 |
| short | 18 Oct 2024 67,421.80 | 19 Oct 2024 68,428.00 | 1 | −$1,006.21 |
| long | 1 Jan 2025 93,576.00 | 19 Jan 2025 104,556.00 | 18 | $10,980.20 |
| long | 5 Feb 2025 97,763.10 | 25 Feb 2025 89,256.70 | 20 | −$8,506.45 |
| short | 25 Apr 2025 93,980.50 | 8 May 2025 99,475.00 | 13 | −$5,494.53 |
| long | 7 Jun 2025 104,288.00 | 5 Jul 2025 107,984.00 | 28 | $3,695.82 |
| long | 5 Aug 2025 115,055.00 | 13 Aug 2025 120,134.00 | 8 | $5,079.06 |
| long | 24 Aug 2025 115,438.00 | 20 Sep 2025 115,632.00 | 27 | $194.33 |
| long | 28 Sep 2025 109,636.00 | 5 Oct 2025 122,391.00 | 7 | $12,755.10 |
| short | 11 Dec 2025 92,015.40 | 23 Jan 2026 89,559.70 | 43 | $2,455.70 |
| short | 6 Mar 2026 70,891.00 | 29 Mar 2026 66,377.00 | 23 | $4,513.98 |
| short | 13 Apr 2026 70,741.60 | 22 Apr 2026 79,424.00 | 9 | −$8,682.44 |
| long | 25 May 2026 77,065.00 | 3 Jun 2026 65,000.00 | 9 | −$12,065.00 |
| short | 17 Jul 2026 63,830.20 | 21 Aug 2026 73,400.00 | 35 | −$9,569.80 |
| long | 17 Sep 2026 76,206.00 | 23 Sep 2026 86,208.60 | 6 | $10,002.60 |
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 |
|---|---|---|---|---|---|
| Grab Trading System this page | — | v4 strategy | +21.1% | 17 | 21.6% |
| 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 16 ms | With a workaround 1,000 bars in 38 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 16, 17) 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/// © LonesomeTheBlue//@version=4strategy("Grab Trading System", overlay = true)flb = input(defval = 80, title = "Longterm Period", minval = 1)slb = input(defval = 21, title = "Shortterm Period", minval = 1)showtarget = input(defval = true, title = "Show Target")showtrend = input(defval = true, title = "Show Trend")major_resistance = highest(flb)major_support = lowest(flb)minor_resistance = highest(slb)minor_support = lowest(slb) var int trend = 0trend := high > major_resistance[1] ? 1 : low < major_support[1] ? -1 : trendstrategy.entry("Buy", true, when = trend == 1 and low[1] == minor_support[1] and low > minor_support)strategy.entry("Sell", false, when = trend == -1 and high[1] == minor_resistance[1] and high < minor_resistance)if strategy.position_size > 0 strategy.exit("Buy", stop = major_support, comment = "Stop Buy") if high[1] == minor_resistance[1] and high < minor_resistance strategy.close("Buy", comment ="Close Buy") if strategy.position_size < 0 strategy.exit("Sell", stop = major_resistance, comment = "Stop Sell") if low[1] == minor_support[1] and low > minor_support strategy.close("Sell", comment ="Close Sell")if strategy.position_size != 0 and change(trend) strategy.close_all() majr = plot(major_resistance, color = showtrend and trend == -1 and trend[1] == -1 ? color.red : na)majs = plot(major_support, color = showtrend and trend == 1 and trend[1] == 1 ? color.lime : na)minr = plot(minor_resistance, color = showtarget and trend == 1 and strategy.position_size > 0 ? color.yellow : na, style = plot.style_circles)mins = plot(minor_support, color = showtarget and trend == -1 and strategy.position_size < 0 ? color.yellow : na, style = plot.style_circles)fill(majs, mins, color = showtrend and trend == 1 and trend[1] == 1 ? color.new(color.lime, 85) : na)fill(majr, minr, color = showtrend and trend == -1 and trend[1] == -1 ? color.new(color.red, 85) : na)