Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Grid Spot Trading Algorithm V2 - The Quant Science

A Pine Script v5 strategy with no technical-analysis calculation. It has 13 order rules and no entry of its own. Exits wait for a signal; there is no stop loss. Each trade commits 1% of equity and pays 0.10% commission. 5 settings; defaults include High price: 0.00, Low price: 0.00 and Stop level 0.00.

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 Spot Trading Algorithm V2 - The Quant Science repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
How did Grid Spot Trading Algorithm V2 - The Quant Science 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 Spot Trading Algorithm V2 - The Quant Science 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 Spot Trading Algorithm V2 - The Quant Science use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Grid Spot Trading Algorithm V2 - The Quant Science run in Zeal Terminal?
Yes
It compiles in 54 ms and runs 1,000 bars in 86 ms, in the browser.

BTCUSDT · 1D · default settings

  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (5)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$10,000$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. 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 65, 66, 67, 68, 69) so the engine trades the way the script says.
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, $10,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

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    1 setting has no label

    In the settings dialog stop_level (line 31) 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.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
TOP PRICE GRID
High price: Top grid price.0.00pricegrid_range grid_1 grid_2 grid_3 grid_4 grid_5 grid_6 grid_7 grid_8 grid_9 close_all Close-Position cancel O #1 cancel O #2 cancel O #3 cancel O #4 cancel O #5 line 44 line 60 line 80 line 90 line 104
BOTTOM PRICE GRID
Low price: Bottom grid price.0.00pricegrid_range grid_10 close_all Close-Position cancel O #1 cancel O #2 cancel O #3 cancel O #4 cancel O #5 line 44 line 60 line 80 line 90 line 104
STOP LOSS CONFIGURATION
Active grid destroyer:Destroy the grid when price crossunder the stop loss level.falseboolline 90 line 115 line 128
Stop level (no label in the script)Stop loss price level. Set price level to destroy the grid and close all the positions.0.00pricegrid_destroyed_ten close_all Grid Destroyed !!! line 91
Exit Configuration
Select exitStarting from the middle to the top.Grid level 1string · options ["Grid level 1", "Grid level 2", "Grid level 3", "Grid level 4", "Grid level 5"]exit_price

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 66 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
order O #1 longlongOn65
order O #2 longlongOn66
order O #3 longlongOn67
order O #4 longlongOn68
order O #5 longlongOn69
Close Close-Positionta.crossover(close, exit_price) and (high_price > 0 or close_price > 0)On81
cancel O #1ta.crossover(close, exit_price) and (high_price > 0 or close_price > 0)On82
cancel O #2ta.crossover(close, exit_price) and (high_price > 0 or close_price > 0)On83
cancel O #3ta.crossover(close, exit_price) and (high_price > 0 or close_price > 0)On84
cancel O #4ta.crossover(close, exit_price) and (high_price > 0 or close_price > 0)On85
cancel O #5ta.crossover(close, exit_price) and (high_price > 0 or close_price > 0)On86
cancel_all (close < grid_10 or ta.crossover(close, grid_10))On88
Close Grid Destroyed !!!ta.crossunder(close, stop_level)On92

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—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.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

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.

⋯                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     -//@version=5+//@version=6strategy(⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 54 msWith a workaround 1,000 bars in 86 msNot measured
PineTSNot testedNot testedNot 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 65, 66, 67, 68, 69) 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 = 'Grid Spot Trading Algorithm V2 - The Quant Science™',      overlay = true,     calc_on_every_tick = true,     initial_capital = 10000,      commission_type = strategy.commission.percent,      commission_value = 0.10,      pyramiding = 5,     default_qty_type = strategy.percent_of_equity,     close_entries_rule = 'ANY'     )/////////////////////////////// Coded by The Quant Science™ ////////////////////////////////////// Upgrade 2.00 (2022.30.07) // Upgrade 3.00 (2022.11.11)// Upgrade 4.00 (2022.20.01)// New release version 2.0 (2023.10.05)////////////////////////////////////////////////////////////////////////////////////////////////////high_price  = input.price(defval = 0.00, title = 'High price: ', group = "TOP PRICE GRID", confirm = true, tooltip = "Top grid price.")close_price = input.price(defval = 0.00, title = 'Low price: ',  group = "BOTTOM PRICE GRID", confirm = true, tooltip = "Bottom grid price.")grid_destroyer = input.bool(defval = false,title = 'Active grid destroyer:',group = "STOP LOSS CONFIGURATION", inline = "SL", tooltip = "Destroy the grid when price crossunder the stop loss level.", confirm = false)stop_level     = input.price(defval = 0.00, title = '',group = "STOP LOSS CONFIGURATION", inline = "SL", confirm = false, tooltip = "Stop loss price level. Set price level to destroy the grid and close all the positions.")grid_range = high_price - close_pricevar 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 grid_factor = 0 if (high_price > 0 or close_price > 0)    grid_factor := grid_range / 9    grid_1 := (high_price)    grid_2 := (high_price - (grid_factor * 1))     grid_3 := (high_price - (grid_factor * 2))     grid_4 := (high_price - (grid_factor * 3))     grid_5 := (high_price - (grid_factor * 4))    grid_6  := (high_price - (grid_factor * 5))     grid_7  := (high_price - (grid_factor * 6))     grid_8  := (high_price - (grid_factor * 7))     grid_9  := (high_price - (grid_factor * 8))    grid_10 := (close_price)    var float lots = 0var float account_balance = 0 long = (ta.crossunder(close, grid_5) or ta.crossover(close, grid_5))if (high_price > 0 or close_price > 0)    if strategy.opentrades==0        account_balance := strategy.equity        lots := (account_balance / close)/5        if long            strategy.order(id = "O #1", direction = strategy.long, qty = lots, limit = grid_6)            strategy.order(id = "O #2", direction = strategy.long, qty = lots, limit = grid_7)            strategy.order(id = "O #3", direction = strategy.long, qty = lots, limit = grid_8)            strategy.order(id = "O #4", direction = strategy.long, qty = lots, limit = grid_9)            strategy.order(id = "O #5", direction = strategy.long, qty = lots, limit = grid_10)Exit(type) =>         switch type        "Grid level 5" => grid_1        "Grid level 4" => grid_2        "Grid level 3" => grid_3        "Grid level 2" => grid_4        "Grid level 1" => grid_5exit_input = input.string("Grid level 1", title = "Select exit", options = ["Grid level 1", "Grid level 2", "Grid level 3", "Grid level 4", "Grid level 5"], tooltip = "Starting from the middle to the top.", group = "Exit Configuration")exit_price = Exit(exit_input)if ta.crossover(close, exit_price) and (high_price > 0 or close_price > 0)    strategy.close_all("Close-Position")    strategy.cancel("O #1")    strategy.cancel("O #2")    strategy.cancel("O #3")    strategy.cancel("O #4")    strategy.cancel("O #5")if (close < grid_10 or ta.crossover(close, grid_10))    strategy.cancel_all()    if (high_price > 0 or close_price > 0) and grid_destroyer==true     if ta.crossunder(close, stop_level)        strategy.close_all("Grid Destroyed !!!") 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 var float grid_destroyed_ten = 0 if (high_price > 0 or close_price > 0)    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_10    if grid_destroyer == true         grid_destroyed_ten := stop_levelelse     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 := na    if grid_destroyer == false         grid_destroyed_ten := nafill(plot(new_ten_grid_1, color = color.new(#35f83b, 90)),      plot(new_ten_grid_2, color = color.new(#36fa3d, 90)),          color = color.new(#37ff3e, 90))fill(plot(new_ten_grid_2, color = color.new(#35f53c, 85)),      plot(new_ten_grid_3, color = color.new(#36f53c, 85)),          color = color.new(#34fc3b, 85))fill(plot(new_ten_grid_3, color = color.new(#35fa3c, 80)),      plot(new_ten_grid_4, color = color.new(#33f83a, 80)),          color = color.new(#32ff39, 80))fill(plot(new_ten_grid_4, color = color.new(#35fc3c, 70)),      plot(new_ten_grid_5, color = color.new(#35f83c, 70)),          color = color.new(#34ff3b, 70))fill(plot(new_ten_grid_5, color = color.new(#35f13b, 60)),      plot(new_ten_grid_6, color = color.new(#34fc3b, 60)),          color = color.new(#37ff3d, 60))fill(plot(new_ten_grid_6, color = color.new(#f83333, 60)),      plot(new_ten_grid_7, color = color.new(#fd3838, 60)),          color = color.new(#ff3434, 60))fill(plot(new_ten_grid_7, color = color.new(#fa3636, 70)),      plot(new_ten_grid_8, color = color.new(#fa3737, 70)),          color = color.new(#ff3636, 70))fill(plot(new_ten_grid_8, color = color.new(#f83535, 80)),      plot(new_ten_grid_9, color = color.new(#fa3636, 80)),          color = color.new(#fd3434, 80))fill(plot(new_ten_grid_9, color = color.new(#fc3434, 85)),      plot(new_ten_grid_10, color = color.new(#fc3737, 85)),          color = color.new(#ff3636, 85))plot(grid_destroyed_ten, color = color.new(#fc3636, 80), linewidth = 10)