Pine Script v5 · Strategy
Grid HW
A Pine Script v5 strategy with no technical-analysis calculation. It has 20 order rules, 10 entries among them, and trades long only with the default settings. Exits use a profit target and no stop loss. Each trade is one contract and pays no commission. 2 settings; defaults include Sprice 40500 and Percent 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 Grid HW repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Grid HW do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its entry conditions never all held on this data. It closed no trades on the other markets either. A backtest, not investment advice.
- Does Grid HW run in Pine Script v6?
- Not tested
- Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download.
- Does Grid HW use a stop loss?
- No
- Its exits set a profit target but no stop.
- Does Grid HW run in Zeal Terminal?
- Yes
- It compiles in 55 ms and runs 1,000 bars in 42 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $1,000,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 stop loss
strategy.exit is used without a stop, loss or trailing stop.
-
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 sprice (line 6) 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.
-
Note
Uses an argument v6 removed
when = on line 65, 68, 71, 73, 75, 77, 79, 81, 83, 85, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107. The upgraded version below moves each call inside an if block.
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 |
|---|---|---|---|
| Sprice (no label in the script) | 40500 | price | b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 |
| Percent | 1 | int | p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 |
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.
The script has 67 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open b1 long | (lc1) | On | 65 |
| Open b2 long | (lc2) | On | 68 |
| Open b3 long | (lc3) | On | 71 |
| Open b4 long | (lc4) | On | 73 |
| Open b5 long | (lc5) | On | 75 |
| Open b6 long | (lc6) | On | 77 |
| Open b7 long | (lc7) | On | 79 |
| Open b8 long | (lc8) | On | 81 |
| Open b9 long | (lc9) | On | 83 |
| Open b10 long | (lc10) | On | 85 |
| Exit b1 limit | (ec1) | On | 89 |
| Exit b2 limit | (ec2) | On | 91 |
| Exit b3 limit | (ec3) | On | 93 |
| Exit b4 limit | (ec4) | On | 95 |
| Exit b5 limit | (ec5) | On | 97 |
| Exit b6 limit | (ec6) | On | 99 |
| Exit b7 limit | (ec7) | On | 101 |
| Exit b8 limit | (ec8) | On | 103 |
| Exit b9 limit | (ec9) | On | 105 |
| Exit b10 limit | (ec10) | On | 107 |
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.
- 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 | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Similar scripts
No other indicator or strategy here shares enough of its calculations.
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.
- 20 strategy calls use the when = argument (line 65, 68, 71, 73, 75, 77, 79, 81, 83, 85, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 1 setting uses the untyped input() (line 7). 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.
Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 7: input() → input.int()
- Line 65: when = (lc1) → if block
- Line 68: when = (lc2) → if block
- Line 71: when = (lc3) → if block
- Line 73: when = (lc4) → if block
- Line 75: when = (lc5) → if block
15 more edits
- Line 77: when = (lc6) → if block
- Line 79: when = (lc7) → if block
- Line 81: when = (lc8) → if block
- Line 83: when = (lc9) → if block
- Line 85: when = (lc10) → if block
- Line 89: when = (ec1) → if block
- Line 91: when = (ec2) → if block
- Line 93: when = (ec3) → if block
- Line 95: when = (ec4) → if block
- Line 97: when = (ec5) → if block
- Line 99: when = (ec6) → if block
- Line 101: when = (ec7) → if block
- Line 103: when = (ec8) → if block
- Line 105: when = (ec9) → if block
- Line 107: when = (ec10) → if block
⋯sprice=input.price(40500,"Starting price")-gridpercent=input(1,"Percent")+gridpercent=input.int(1,"Percent")// calculate the % of the 10 layers ⋯if (lc1)- strategy.entry("b1", strategy.long, when=(lc1))+ if (lc1)+ strategy.entry("b1", strategy.long) if (lc2)- strategy.entry("b2", strategy.long, when=(lc2))+ if (lc2)+ strategy.entry("b2", strategy.long) if (lc3)- strategy.entry("b3", strategy.long, when=(lc3)) + if (lc3)+ strategy.entry("b3", strategy.long) if (lc4)- strategy.entry("b4", strategy.long, when=(lc4)) + if (lc4)+ strategy.entry("b4", strategy.long) if (lc5)- strategy.entry("b5", strategy.long, when=(lc5))+ if (lc5)+ strategy.entry("b5", strategy.long)if (lc6)- strategy.entry("b6", strategy.long, when=(lc6))+ if (lc6)+ strategy.entry("b6", strategy.long)if (lc7)- strategy.entry("b7", strategy.long, when=(lc7)) + if (lc7)+ strategy.entry("b7", strategy.long) if (lc8)- strategy.entry("b8", strategy.long, when=(lc8)) + if (lc8)+ strategy.entry("b8", strategy.long) if (lc9)- strategy.entry("b9", strategy.long, when=(lc9)) + if (lc9)+ strategy.entry("b9", strategy.long) if (lc10)- strategy.entry("b10", strategy.long, when=(lc10))+ if (lc10)+ strategy.entry("b10", strategy.long) ⋯if (ec1)- strategy.exit("b1", when=(ec1), limit=1)+ if (ec1)+ strategy.exit("b1", limit=1)if (ec2)- strategy.exit("b2", when=(ec2), limit=1)+ if (ec2)+ strategy.exit("b2", limit=1)if (ec3)- strategy.exit("b3", when=(ec3), limit=1)+ if (ec3)+ strategy.exit("b3", limit=1)if (ec4)- strategy.exit("b4", when=(ec4), limit=1)+ if (ec4)+ strategy.exit("b4", limit=1)if (ec5)- strategy.exit("b5", when=(ec5), limit=1)+ if (ec5)+ strategy.exit("b5", limit=1)if (ec6)- strategy.exit("b6", when=(ec6), limit=1)+ if (ec6)+ strategy.exit("b6", limit=1)if (ec7)- strategy.exit("b7", when=(ec7), limit=1)+ if (ec7)+ strategy.exit("b7", limit=1)if (ec8)- strategy.exit("b8", when=(ec8), limit=1)+ if (ec8)+ strategy.exit("b8", limit=1)if (ec9)- strategy.exit("b9", when=(ec9), limit=1)+ if (ec9)+ strategy.exit("b9", limit=1)if (ec10)- strategy.exit("b10", when=(ec10), limit=1)+ if (ec10)+ strategy.exit("b10", limit=1) ⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © Lionkind-//@version=5+//@version=6strategy("Grid HW", overlay = true, margin_long = 1, margin_short = 1)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 55 ms | Yes 1,000 bars in 42 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/// © Lionkind//@version=5strategy("Grid HW", overlay = true, margin_long = 1, margin_short = 1)// Fix 35k price as starting point and 1% as a distancesprice=input.price(40500,"Starting price")gridpercent=input(1,"Percent")// calculate the % of the 10 layers p1=((gridpercent*1)/100)p2=((gridpercent*2)/100)p3=((gridpercent*3)/100)p4=((gridpercent*4)/100)p5=((gridpercent*5)/100)p6=((gridpercent*6)/100)p7=((gridpercent*7)/100)p8=((gridpercent*8)/100)p9=((gridpercent*9)/100)p10=((gridpercent*10)/100)//set buy prices b1=sprice-(sprice*p1)b2=sprice-(sprice*p2)b3=sprice-(sprice*p3)b4=sprice-(sprice*p4)b5=sprice-(sprice*p5)b6=sprice-(sprice*p6)b7=sprice-(sprice*p7)b8=sprice-(sprice*p8)b9=sprice-(sprice*p9)b10=sprice-(sprice*p10)//set sell pricess1=b1+(sprice*p1)s2=b2+(sprice*p1)s3=b3+(sprice*p1)s4=b4+(sprice*p1)s5=b5+(sprice*p1)s6=b6+(sprice*p1)s7=b7+(sprice*p1)s8=b8+(sprice*p1)s9=b9+(sprice*p1)s10=b10+(sprice*p1)//Long conditionslc1=close<b1lc2=close<b2lc3=close<b3lc4=close<b4lc5=close<b5lc6=close<b6lc7=close<b7lc8=close<b8lc9=close<b9lc10=close<b10//exit conditionsec1=close>s1ec2=close>s2ec3=close>s3ec4=close>s4ec5=close>s5ec6=close>s6ec7=close>s7ec8=close>s8ec9=close>s9ec10=close>s10//long ordersif (lc1) strategy.entry("b1", strategy.long, when=(lc1)) if (lc2) strategy.entry("b2", strategy.long, when=(lc2)) if (lc3) strategy.entry("b3", strategy.long, when=(lc3)) if (lc4) strategy.entry("b4", strategy.long, when=(lc4)) if (lc5) strategy.entry("b5", strategy.long, when=(lc5))if (lc6) strategy.entry("b6", strategy.long, when=(lc6))if (lc7) strategy.entry("b7", strategy.long, when=(lc7)) if (lc8) strategy.entry("b8", strategy.long, when=(lc8)) if (lc9) strategy.entry("b9", strategy.long, when=(lc9)) if (lc10) strategy.entry("b10", strategy.long, when=(lc10)) //exit orders if (ec1) strategy.exit("b1", when=(ec1), limit=1)if (ec2) strategy.exit("b2", when=(ec2), limit=1)if (ec3) strategy.exit("b3", when=(ec3), limit=1)if (ec4) strategy.exit("b4", when=(ec4), limit=1)if (ec5) strategy.exit("b5", when=(ec5), limit=1)if (ec6) strategy.exit("b6", when=(ec6), limit=1)if (ec7) strategy.exit("b7", when=(ec7), limit=1)if (ec8) strategy.exit("b8", when=(ec8), limit=1)if (ec9) strategy.exit("b9", when=(ec9), limit=1)if (ec10) strategy.exit("b10", when=(ec10), limit=1) plot(b1,color=color.green)plot(s1, color=color.red)plot(b2, color=color.purple)