Pine Script v5 · Strategy
Hulk Grid Algorithm - The Quant Science
A Pine Script v5 strategy built on Crossunder (close, destroyall). It has 26 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 commits 1% of equity and pays 0.07% commission. 11 settings; defaults include Start Date 1, Start Month 1 and Start Year 2018.
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 Hulk Grid Algorithm - The Quant Science repaint?
- No
- No repainting patterns were found in the source.
- Does Hulk Grid Algorithm - The Quant Science run in Pine Script v6?
- Not tested
- The v5 script does not run in Zeal Terminal's engine (WRONG TIMEFRAME: Please select an intraday timeframe when use this strategy backtesting.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download.
- Does Hulk Grid Algorithm - The Quant Science use a stop loss?
- No
- Its exits set a profit target but no stop.
- Does Hulk Grid Algorithm - The Quant Science run in Zeal Terminal?
- No
- Not yet: WRONG TIMEFRAME: Please select an intraday timeframe when use this strategy backtesting.
Review
What a careful reader of this script would point out, found by checking the source.
-
Check
No stop loss
strategy.exit is used without a stop, loss or trailing stop.
-
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.
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 |
|---|---|---|---|
| DATE PERIOD CONFIGURATION | |||
| Start Date | 1 | int · min 1 · max 31 | inDateRange |
| Start Month | 1 | int · min 1 · max 12 | inDateRange |
| Start Year | 2018 | int · min 1800 · max 2100 | inDateRange |
| End Date | 12 | int · min 1 · max 31 | inDateRange |
| End Month | 3 | int · min 1 · max 12 | inDateRange |
| End Year | 2022 | int · min 1800 · max 2100 | inDateRange |
| STRATEGY CONFIGURATION | |||
| Enable StrategyCreate grid backtesting. | false | bool | exit C #1 exit C #2 exit C #3 exit C #4 exit C #5 exit C #6 exit C #7 exit C #8 exit C #9 exit C #10 line 65 line 97 line 108 line 123 line 141 line 143 line 145 line 147 line 149 line 151 line 153 line 155 line 157 line 159 |
| Stop Loss: | 2.00 | float · step 0.10 | destroyall |
| Take Profit: | 2.00 | float · step 0.10 | takeprofitlevel |
| Minimum Bars: | 3 | int · step 1 | period |
| Size Grid Range: | 200.00 | float · step 1.00 | trigger |
What it calculates
- Crossunderclose, destroyall
des_function · line 120
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 89 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 O #1 long | close > new_ten_grid_1 | On | 126 |
| Open O #2 long | close > new_ten_grid_1 | On | 127 |
| Open O #3 long | close > new_ten_grid_1 | On | 128 |
| Open O #4 long | close > new_ten_grid_1 | On | 129 |
| Open O #5 long | close > new_ten_grid_1 | On | 130 |
| Open O #6 long | close < new_ten_grid_1 | On | 132 |
| Open O #7 long | close < new_ten_grid_1 | On | 133 |
| Open O #8 long | close < new_ten_grid_1 | On | 134 |
| Open O #9 long | close < new_ten_grid_1 | On | 135 |
| Open O #10 long | close < new_ten_grid_1 | On | 136 |
| cancel_all | close > takeprofitlevel | On | 138 |
| cancel_all | close < destroyall | On | 140 |
| Exit C #1 limit | new_ten_grid_2 and ten_grid == true | On | 142 |
| Exit C #2 limit | new_ten_grid_3 and ten_grid == true | On | 144 |
| Exit C #3 limit | new_ten_grid_4 and ten_grid == true | On | 146 |
| Exit C #4 limit | new_ten_grid_5 and ten_grid == true | On | 148 |
| Exit C #5 limit | takeprofitlevel and ten_grid == true | On | 150 |
| Exit C #6 limit | new_ten_grid_5 and ten_grid == true | On | 152 |
| Exit C #7 limit | new_ten_grid_6 and ten_grid == true | On | 154 |
| Exit C #8 limit | new_ten_grid_7 and ten_grid == true | On | 156 |
| Exit C #9 limit | new_ten_grid_8 and ten_grid == true | On | 158 |
| Exit C #10 limit | new_ten_grid_9 and ten_grid == true | On | 160 |
| Close Destroyed Grid | des_function | On | 162 |
| cancel_all | des_function | On | 163 |
| Close Dayli Session End | session.islastbar_regular | On | 165 |
| cancel_all | session.islastbar_regular | On | 167 |
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.
The live replay needs a run, and this script does not run in Zeal Terminal yet; the answer comes from the checks on the source alone.
- ClearHigher-timeframe data3 request.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.
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.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing to change.
Does it run in Pine Script v6?
Not tested
The v5 script does not run in Zeal Terminal's engine (WRONG TIMEFRAME: Please select an intraday timeframe when use this strategy backtesting.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯ -//@version=5+//@version=6strategy(⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | No WRONG TIMEFRAME: Please select an intraday timeframe when use this strategy backtesting. | Not measured | |
| PineTS | Not tested | Not tested | Not measured |
Zeal Terminal's engine currently reads an order side written as direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 126, 127, 128, 129, 130, 132 and more) 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.
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/// © thequantscience// ██╗ ██╗██╗ ██╗██╗ ██╗ ██╗ ██████╗ ██████╗ ██╗██████╗ █████╗ ██╗ ██████╗ ██████╗ ██████╗ ██╗████████╗██╗ ██╗███╗ ███╗// ██║ ██║██║ ██║██║ ██║ ██╔╝ ██╔════╝ ██╔══██╗██║██╔══██╗ ██╔══██╗██║ ██╔════╝ ██╔═══██╗██╔══██╗██║╚══██╔══╝██║ ██║████╗ ████║// ███████║██║ ██║██║ █████╔╝ ██║ ███╗██████╔╝██║██║ ██║ ███████║██║ ██║ ███╗██║ ██║██████╔╝██║ ██║ ███████║██╔████╔██║// ██╔══██║██║ ██║██║ ██╔═██╗ ██║ ██║██╔══██╗██║██║ ██║ ██╔══██║██║ ██║ ██║██║ ██║██╔══██╗██║ ██║ ██╔══██║██║╚██╔╝██║// ██║ ██║╚██████╔╝███████╗██║ ██╗ ╚██████╔╝██║ ██║██║██████╔╝ ██║ ██║███████╗╚██████╔╝╚██████╔╝██║ ██║██║ ██║ ██║ ██║██║ ╚═╝ ██║// ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ //@version=5strategy( title = 'Hulk Grid Algorithm - The Quant Science', overlay = true, initial_capital = 1000, commission_type = strategy.commission.percent, commission_value = 0.07, pyramiding = 10, default_qty_type = strategy.percent_of_equity )// #########################################################################################################if not timeframe.isintraday runtime.error("WRONG TIMEFRAME: Please select an intraday timeframe when use this strategy backtesting.")// #########################################################################################################startDate = input.int(title="Start Date", defval=1, minval=1, maxval=31, group = "DATE PERIOD CONFIGURATION")startMonth = input.int(title="Start Month", defval=1, minval=1, maxval=12, group = "DATE PERIOD CONFIGURATION")startYear = input.int(title="Start Year", defval=2018, minval=1800, maxval=2100, group = "DATE PERIOD CONFIGURATION")endDate = input.int(title="End Date", defval=12, minval=1, maxval=31, group = "DATE PERIOD CONFIGURATION")endMonth = input.int(title="End Month", defval=3, minval=1, maxval=12, group = "DATE PERIOD CONFIGURATION")endYear = input.int(title="End Year", defval=2022, minval=1800, maxval=2100, group = "DATE PERIOD CONFIGURATION")inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))// #########################################################################################################requestpastweekclose = request.security(syminfo.tickerid, "D", close[1], gaps = barmerge.gaps_off) requestpastweekopen = request.security(syminfo.tickerid, "D", open[1], gaps = barmerge.gaps_off)newday = request.security(syminfo.tickerid, "D", close, gaps = barmerge.gaps_off)// #########################################################################################################ten_grid = input.bool(defval = false, title = "Enable Strategy", tooltip = "Create grid backtesting.", group = "STRATEGY CONFIGURATION")stop_loss = input.float(defval = 2.00, step = 0.10, title = "Stop Loss: ", group = "STRATEGY CONFIGURATION")take_profit = input.float(defval = 2.00, step = 0.10, title = "Take Profit: ", group = "STRATEGY CONFIGURATION")period_num = input.int(defval = 3, step = 1, title = "Minimum Bars: ", group = "STRATEGY CONFIGURATION")size_grid = input.float(defval = 200.00, step = 1.00, title = "Size Grid Range: ", group = "STRATEGY CONFIGURATION")// #########################################################################################################var float high_start = 0 var float high_end = 0 checking = requestpastweekclose > requestpastweekopen if checking==true high_start := requestpastweekclose high_end := requestpastweekopengrid_range = high_start - high_endperiod = ta.barssince(ta.change(checking==true))==period_numTriggerGrid() => trigger = checking==true and period and grid_range > size_grid and close triggertrigger_entry = TriggerGrid() var float grid_1 = 0var float grid_2 = 0var float grid_3 = 0var float grid_4 = 0var float grid_5 = 0var float grid_6 = 0var float grid_7 = 0var float grid_8 = 0var float grid_9 = 0var float grid_10 = 0var float factor = 0 if ten_grid == true and trigger_entry==true and strategy.opentrades==0 factor := grid_range / 10 // UP GRID grid_1 := (high_start) grid_2 := (high_start + (factor * 1)) grid_3 := (high_start + (factor * 2)) grid_4 := (high_start + (factor * 3)) grid_5 := (high_start + (factor * 4)) // DOWN GRID grid_6 := (high_start - (factor * 1)) grid_7 := (high_start - (factor * 2)) grid_8 := (high_start - (factor * 3)) grid_9 := (high_start - (factor * 4)) grid_10 := (high_start - (factor * 5))// #########################################################################################################var tb = table.new(position.bottom_left, 1, 1, bgcolor = color.new(#00ff08, 74))if barstate.isfirst table.cell(tb, 0, 0, 'Developed by The Quant Science™' ,text_size = size.normal ,text_color = color.new(#00ff08, 21))// #########################################################################################################var float new_ten_grid_1 = 0 var float new_ten_grid_2 = 0 var float new_ten_grid_3 = 0 var float new_ten_grid_4 = 0 var float new_ten_grid_5 = 0 var float new_ten_grid_6 = 0 var float new_ten_grid_7 = 0 var float new_ten_grid_8 = 0 var float new_ten_grid_9 = 0 var float new_ten_grid_10 = 0 if ten_grid == true new_ten_grid_1 := grid_1 new_ten_grid_2 := grid_2 new_ten_grid_3 := grid_3 new_ten_grid_4 := grid_4 new_ten_grid_5 := grid_5 new_ten_grid_6 := grid_6 new_ten_grid_7 := grid_7 new_ten_grid_8 := grid_8 new_ten_grid_9 := grid_9 new_ten_grid_10 := grid_10else if ten_grid == false new_ten_grid_1 := na new_ten_grid_2 := na new_ten_grid_3 := na new_ten_grid_4 := na new_ten_grid_5 := na new_ten_grid_6 := na new_ten_grid_7 := na new_ten_grid_8 := na new_ten_grid_9 := na new_ten_grid_10 := nadestroyall = new_ten_grid_10 - (new_ten_grid_10 * stop_loss / 100)des_function = ta.crossunder(close, destroyall)takeprofitlevel = new_ten_grid_5 + (new_ten_grid_5 * take_profit / 100)var float lots = 0 if trigger_entry==true and ten_grid==true and period and inDateRange lots := (strategy.equity / close) / 5 if close > new_ten_grid_1 strategy.entry(id = "O #1", direction = strategy.long, qty = lots, limit = new_ten_grid_1) strategy.entry(id = "O #2", direction = strategy.long, qty = lots, limit = new_ten_grid_2) strategy.entry(id = "O #3", direction = strategy.long, qty = lots, limit = new_ten_grid_3) strategy.entry(id = "O #4", direction = strategy.long, qty = lots, limit = new_ten_grid_4) strategy.entry(id = "O #5", direction = strategy.long, qty = lots, limit = new_ten_grid_5) if close < new_ten_grid_1 strategy.entry(id = "O #6", direction = strategy.long, qty = lots, limit = new_ten_grid_6) strategy.entry(id = "O #7", direction = strategy.long, qty = lots, limit = new_ten_grid_7) strategy.entry(id = "O #8", direction = strategy.long, qty = lots, limit = new_ten_grid_8) strategy.entry(id = "O #9", direction = strategy.long, qty = lots, limit = new_ten_grid_9) strategy.entry(id = "O #10", direction = strategy.long, qty = lots, limit = new_ten_grid_10) if close > takeprofitlevel strategy.cancel_all() if close < destroyall strategy.cancel_all()if new_ten_grid_2 and ten_grid == true strategy.exit(id = "C #1", from_entry = "O #1", qty = 100, limit = new_ten_grid_2)if new_ten_grid_3 and ten_grid == true strategy.exit(id = "C #2", from_entry = "O #2", qty = 100, limit = new_ten_grid_3)if new_ten_grid_4 and ten_grid == true strategy.exit(id = "C #3", from_entry = "O #3", qty = 100, limit = new_ten_grid_4)if new_ten_grid_5 and ten_grid == true strategy.exit(id = "C #4", from_entry = "O #4", qty = 100, limit = new_ten_grid_5)if takeprofitlevel and ten_grid == true strategy.exit(id = "C #5", from_entry = "O #5", qty = 100, limit = takeprofitlevel)if new_ten_grid_5 and ten_grid == true strategy.exit(id = "C #6", from_entry = "O #6", qty = 100, limit = new_ten_grid_1)if new_ten_grid_6 and ten_grid == true strategy.exit(id = "C #7", from_entry = "O #7", qty = 100, limit = new_ten_grid_6)if new_ten_grid_7 and ten_grid == true strategy.exit(id = "C #8", from_entry = "O #8", qty = 100, limit = new_ten_grid_7)if new_ten_grid_8 and ten_grid == true strategy.exit(id = "C #9", from_entry = "O #9", qty = 100, limit = new_ten_grid_8)if new_ten_grid_9 and ten_grid == true strategy.exit(id = "C #10", from_entry = "O #10", qty = 100, limit = new_ten_grid_9)if des_function strategy.close_all("Destroyed Grid") strategy.cancel_all()if session.islastbar_regular strategy.close_all("Dayli Session End")if session.islastbar_regular strategy.cancel_all()// #########################################################################################################fill(plot(grid_1, color = color.new(color.rgb(0, 255, 132), 95)), plot(grid_2, color = color.new(color.rgb(0, 255, 132), 95)), color = color.new(#00ff08, 80))fill(plot(grid_2, color = color.new(color.rgb(0, 255, 132), 95)), plot(grid_3, color = color.new(color.rgb(0, 255, 132), 95)), color = color.new(#00ff08, 85))fill(plot(grid_3, color = color.new(color.rgb(0, 255, 132), 95)), plot(grid_4, color = color.new(color.rgb(0, 255, 132), 95)), color = color.new(#00ff08, 85))fill(plot(grid_4, color = color.new(color.rgb(0, 255, 132), 95)), plot(grid_5, color = color.new(color.rgb(0, 255, 132), 95)), color = color.new(#00ff08, 90))fill(plot(grid_1, color = color.new(color.rgb(0, 255, 132), 95)), plot(grid_6, color = color.new(color.rgb(0, 255, 132), 95)), color = color.new(#00ff08, 80))fill(plot(grid_6, color = color.new(color.rgb(0, 255, 132), 95)), plot(grid_7, color = color.new(color.rgb(0, 255, 132), 95)), color = color.new(#00ff08, 80))fill(plot(grid_7, color = color.new(color.rgb(0, 255, 132), 95)), plot(grid_8, color = color.new(color.rgb(0, 255, 132), 95)), color = color.new(#00ff08, 85))fill(plot(grid_8, color = color.new(color.rgb(0, 255, 132), 95)), plot(grid_9, color = color.new(color.rgb(0, 255, 132), 95)), color = color.new(#00ff08, 85))fill(plot(grid_9, color = color.new(color.rgb(0, 255, 132), 95)), plot(grid_10, color = color.new(color.rgb(0, 255, 132), 95)), color = color.new(#00ff08, 90))// #########################################################################################################