Strategy · Pine Script v5 · On the chart

Hulk Grid Algorithm V2 - The Quant Science

by wynnforthework· code credited to thequantscience

Hulk Grid Algorithm V2 is a grid trading strategy designed for price charts.

View on GitHub

Repaints

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code153
Settings4inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago7 Oct 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

153 lines of Pine Script v5 from 策略/新建文件夹 (2)/绿巨人网格算法 V2 - The Quant Science.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

绿巨人网格算法 V2 - The Quant Science.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © thequantscience
                              
//@version=5
strategy(
     title = 'Hulk Grid Algorithm V2 - The Quant Science', 
     overlay = true,
     default_qty_type = strategy.cash,
     pyramiding = 100,
     calc_on_every_tick = true,
     currency = currency.USD,
     initial_capital = 10000,
     commission_type = strategy.commission.percent,
     commission_value = 0.10,
     slippage = 5,
     process_orders_on_close = true,
     close_entries_rule = "ANY"
     )

mid_start = input.price(defval = 0, title = "Mid Price", group = "GRID CONFIGURATION", confirm = true)
stop_loss = input.float(defval = 2.00, step = 0.10, title = "Stop Loss", group = "GRID CONFIGURATION", confirm = true)
take_profit = input.float(defval = 2.00, step = 0.10, title = "Take Profit", group = "GRID CONFIGURATION", confirm = true)
size_grid = input.float(defval = 200.00, step = 1.00, title = "Grid Step ($)", group = "GRID CONFIGURATION", confirm = true)

var float grid_1  = 0
var float grid_2  = 0
var float grid_3  = 0
var float grid_4  = 0
var float grid_5  = 0
var float grid_6  = 0
var float grid_7  = 0
var float grid_8  = 0
var float grid_9  = 0
var float grid_10 = 0

var float factor = 0 

if (strategy.opentrades==0)

    factor := size_grid
    grid_1  := (mid_start) 
    grid_2  := (mid_start + (factor * 1)) 
    grid_3  := (mid_start + (factor * 2)) 
    grid_4  := (mid_start + (factor * 3)) 
    grid_5  := (mid_start + (factor * 4))
    grid_6  := (mid_start - (factor * 1)) 
    grid_7  := (mid_start - (factor * 2)) 
    grid_8  := (mid_start - (factor * 3)) 
    grid_9  := (mid_start - (factor * 4))
    grid_10 := (mid_start - (factor * 5))

destroyall = grid_10 - (grid_10 * stop_loss / 100)
des_function = ta.crossunder(close, destroyall)
takeprofitlevel = grid_5 + (grid_5 * take_profit / 100)

var float lots = 0 

initial_capital = strategy.initial_capital * 0.50 / 100

lots := initial_capital

if (strategy.opentrades==0)

    strategy.entry(id = "O #1",  direction = strategy.long, qty = lots * 1 / grid_10,limit = grid_10)
    strategy.entry(id = "O #2",  direction = strategy.long, qty = lots * 2 / grid_9, limit = grid_9)
    strategy.entry(id = "O #3",  direction = strategy.long, qty = lots * 3 / grid_8, limit = grid_8)
    strategy.entry(id = "O #4",  direction = strategy.long, qty = lots * 4 / grid_7, limit = grid_7)
    strategy.entry(id = "O #5",  direction = strategy.long, qty = lots * 5 / grid_6, limit = grid_6)
    strategy.entry(id = "O #6",  direction = strategy.long, qty = lots * 6 / grid_1, limit = grid_1)
    strategy.entry(id = "O #7",  direction = strategy.long, qty = lots * 7 / grid_2, limit = grid_2)
    strategy.entry(id = "O #8",  direction = strategy.long, qty = lots * 8 / grid_3, limit = grid_3)
    strategy.entry(id = "O #9",  direction = strategy.long, qty = lots * 9 / grid_4, limit = grid_4)
    strategy.entry(id = "O #10", direction = strategy.long, qty = lots * 10 / grid_5,limit = grid_5)

    if (close < grid_10)
        strategy.cancel("O #1")
        strategy.cancel("O #2")
        strategy.cancel("O #3")
        strategy.cancel("O #4")
        strategy.cancel("O #5")
        strategy.cancel("O #6")
        strategy.cancel("O #7")
        strategy.cancel("O #8")
        strategy.cancel("O #9")
        strategy.cancel("O #10")

    if (close < mid_start)
        strategy.cancel("O #1")
        strategy.cancel("O #2")
        strategy.cancel("O #3")
        strategy.cancel("O #4")
        strategy.cancel("O #5")
        strategy.cancel("O #6")
        strategy.cancel("O #7")
        strategy.cancel("O #8")
        strategy.cancel("O #9")
        strategy.cancel("O #10")

if (ta.crossunder(close, destroyall))
    strategy.close_all("Stop Loss")

    strategy.cancel("O #1")
    strategy.cancel("O #2")
    strategy.cancel("O #3")
    strategy.cancel("O #4")
    strategy.cancel("O #5")
    strategy.cancel("O #6")
    strategy.cancel("O #7")
    strategy.cancel("O #8")
    strategy.cancel("O #9")
    strategy.cancel("O #10")

if (ta.crossover(close, takeprofitlevel))
    strategy.close_all("Take Profit")

    strategy.cancel("O #1")
    strategy.cancel("O #2")
    strategy.cancel("O #3")
    strategy.cancel("O #4")
    strategy.cancel("O #5")
    strategy.cancel("O #6")
    strategy.cancel("O #7")
    strategy.cancel("O #8")
    strategy.cancel("O #9")
    strategy.cancel("O #10")

fill(plot(grid_1, color = color.new(#00ff84, 55)), 
     plot(grid_2, color = color.new(#00ff84, 55)),  
         color = color.new(#00ff84, 55))
fill(plot(grid_2, color = color.new(#00ff84, 70)),  
     plot(grid_3, color = color.new(#00ff84, 70)),  
         color = color.new(#00ff84, 70))
fill(plot(grid_3, color = color.new(#00ff84, 80)),  
     plot(grid_4, color = color.new(#00ff84, 80)),  
         color = color.new(#00ff84, 80))
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(color.rgb(0, 255, 132), 95))
fill(plot(grid_1, color = color.new(#00ff84, 45)),  
     plot(grid_6, color = color.new(#00ff84, 45)), 
         color = color.new(#00ff84, 45))
fill(plot(grid_6, color = color.new(#00ff84, 55)),  
     plot(grid_7, color = color.new(#00ff84, 55)),  
         color = color.new(#00ff84, 55))
fill(plot(grid_7, color = color.new(#00ff84, 70)), 
     plot(grid_8, color = color.new(#00ff84, 70)),  
         color = color.new(#00ff84, 70))
fill(plot(grid_8, color = color.new(#00ff84, 80)),  
     plot(grid_9, color = color.new(#00ff84, 80)),  
         color = color.new(#00ff84, 80))
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(color.rgb(0, 255, 132), 95))

Overview

Hulk Grid Algorithm V2 - The Quant Science establishes ten distinct grid levels around a user-defined mid price, spaced apart by a fixed dollar grid step. The strategy places long limit orders across these levels with scaled position sizing. A collective take-profit target is placed above the top grid level, while a global stop-loss exits positions if price crosses below a percentage threshold from the lowest grid line. Inputs allow traders to customize the mid price, step distance, stop loss, and take profit percentages.

Details

Published by

wynnforthework on GitHub

Code credit

thequantscience, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy can add several entries in the same direction
  • The strategy enters trades without a stop loss

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Mid Priceprice0mid_start
Stop Lossfloat2.00stop_loss
Take Profitfloat2.00take_profit
Grid Step ($)float200.00size_grid
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

330 stars

This strategy divides a fixed price range between an upper and a lower limit into equally spaced grid levels and plots them on the price chart. It marks a buy when price crosses down through a grid and a sell when price crosses up through a grid, using either

Strategy v5 Support & resistanceMean reversion Repaints
Updated 2 months ago · None stated GitHub repository of Grid Bot Simulator [Alorse]

3C QFL Mean Reversal

by hasnocool
106 stars

3C QFL Mean Reversal is a strategy based on the Quickfinger Luc (QFL) trading methodology. It identifies breakdown buying opportunities below established price base levels and enters mean-reversion trades. The strategy includes multi-safety order DCA scaling,

Strategy v5 Mean reversionSupport & resistance Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 3C QFL Mean Reversal

This strategy builds a spot grid between user-set high and low prices and draws it on the price chart. It splits that range into ten levels and places up to five long limit orders at the lower levels, sizing each from current equity. Orders already below price

Strategy v6 Support & resistanceMean reversion Repaints
Updated 6 weeks ago · None stated GitHub repository of Grid Spot Trading Algorithm [The Quant Science]

FairValueGap E003

by ruckard
13 stars

Calculates the distance between the current price and the opposite end of the latest fair value gap, entering trades on the expectation that price will partially fill the gap. It incorporates risk management with customizable stop loss, take profit based on ri

Strategy v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · None stated GitHub repository of FairValueGap E003

Wyckoff Phase

by muammeryldrm42
7 stars

This strategy identifies Wyckoff consolidation ranges directly on the price chart to trade potential spring and upthrust events. It calculates highest highs and lowest lows over a customizable lookback period, filtering setups by average volume spikes and ATR

Strategy v5 SMC / ICT / price actionSupport & resistance
Updated 3 months ago · MIT GitHub repository of Wyckoff Phase

More Support & resistance scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers