Pine Script v5 · Strategy
GRID SPOT TRADING ALGORITHM - GRID BOT TRADING STRATEGY
A Pine Script v5 strategy built on RSI (close, 14). It has 47 order rules and no entry of its own. Exits use a profit target and no stop loss. Each trade commits 1% of equity and pays 0.10% commission. 12 settings; defaults include Start date: 1, Start month: 1 and Start year: 2022.
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 - GRID BOT TRADING STRATEGY repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did GRID SPOT TRADING ALGORITHM - GRID BOT TRADING STRATEGY 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 code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Does GRID SPOT TRADING ALGORITHM - GRID BOT TRADING STRATEGY run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L224:C3: cannot use 'float' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download.
- Does GRID SPOT TRADING ALGORITHM - GRID BOT TRADING STRATEGY use a stop loss?
- No
- Its exits set a profit target but no stop.
- Does GRID SPOT TRADING ALGORITHM - GRID BOT TRADING STRATEGY run in Zeal Terminal?
- Yes
- It compiles in 198 ms and runs 1,000 bars in 297 ms, in the browser.
BTCUSDT · 1D · default settings
- Winning trade
- Losing trade
- Equity
- Buy and hold
| Developed by The Quant Science™ |
- 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
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 |
|---|---|---|---|
| BACKTESTING PERIOD | |||
| Start date: | 1 | int · min 1 · max 31 | inDateRange |
| Start month: | 1 | int · min 1 · max 12 | inDateRange |
| Start year: | 2022 | int · min 1800 · max 2100 | inDateRange |
| End date: | 31 | int · min 1 · max 31 | inDateRange |
| End month: | 12 | int · min 1 · max 12 | inDateRange |
| End year: | 2022 | int · min 1800 · max 2100 | inDateRange |
| HIGH PRICE GRID | |||
| High price: Top grid price. | 0.00 | price | grid_range grid_1 grid_2 grid_3 grid_4 grid_5 grid_6 grid_7 grid_8 grid_9 grid_10 grid_11 grid_12 grid_13 grid_14 grid_15 grid_16 grid_17 grid_18 grid_19 |
| LOW PRICE GRID | |||
| Low price: Bottom grid price. | 0.00 | price | grid_range grid_10 grid_20 last_long |
| GRID CONFIGURATION | |||
| Grid: 10Create a 10 levels grid. | false | bool | cancel O #1 cancel O #2 cancel O #3 cancel O #4 cancel O #5 exit C #1 exit C #2 exit C #3 exit C #4 line 123 line 206 line 214 line 216 line 218 line 220 line 222 line 224 line 231 line 238 line 245 line 259 line 380 line 393 |
| Grid: 20Create a 20 levels grid. | false | bool | cancel O #1 cancel O #2 cancel O #3 cancel O #4 cancel O #5 cancel O #6 cancel O #7 cancel O #8 cancel O #9 cancel O #10 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 136 line 262 line 275 line 277 line 279 line 281 line 283 line 285 line 287 line 289 line 291 line 293 line 295 line 302 line 309 line 316 line 323 line 330 line 337 line 344 line 351 line 358 line 365 line 456 line 479 |
| STOP LOSS CONFIGURATION | |||
| Active grid destroyerDestroy the grid when price crossunder the stop loss level. | false | bool | line 259 line 365 line 391 line 404 line 477 line 500 |
| Destroy level: Stop loss price level. Always set this value below the low price grid. | 0.00 | price | grid_destroyed_ten grid_destroyed_twenty close_all Grid Destroyed !!! close_all Grid Destroyed !!! line 260 line 366 |
What it calculates
- RSIclose, 14
rsi · line 191
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 165 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 |
|---|---|---|---|
| order O #1 long | trigger_entry and strategy.opentrades == 0 | On | 209 |
| order O #2 long | trigger_entry and strategy.opentrades == 0 | On | 210 |
| order O #3 long | trigger_entry and strategy.opentrades == 0 | On | 211 |
| order O #4 long | trigger_entry and strategy.opentrades == 0 | On | 212 |
| order O #5 long | trigger_entry and strategy.opentrades == 0 | On | 213 |
| cancel O #1 | close < grid_6 and ten_grid == true | On | 215 |
| cancel O #2 | close < grid_7 and ten_grid == true | On | 217 |
| cancel O #3 | close < grid_8 and ten_grid == true | On | 219 |
| cancel O #4 | close < grid_9 and ten_grid == true | On | 221 |
| cancel O #5 | close < grid_10 and ten_grid == true | On | 223 |
| Exit C #1 limit | grid_5 and ten_grid == true | On | 225 |
| Exit C #2 limit | grid_4 and ten_grid == true | On | 232 |
| Exit C #3 limit | grid_3 and ten_grid == true | On | 239 |
| Exit C #4 limit | grid_2 and ten_grid == true | On | 246 |
| Exit C #5 limit | grid_1 | On | 253 |
| Close Grid Destroyed !!! | ta.crossunder(low, stop_level) | On | 261 |
| order O #1 long | trigger_entry and strategy.opentrades == 0 | On | 265 |
| order O #2 long | trigger_entry and strategy.opentrades == 0 | On | 266 |
| order O #3 long | trigger_entry and strategy.opentrades == 0 | On | 267 |
| order O #4 long | trigger_entry and strategy.opentrades == 0 | On | 268 |
| order O #5 long | trigger_entry and strategy.opentrades == 0 | On | 269 |
| order O #6 long | trigger_entry and strategy.opentrades == 0 | On | 270 |
| order O #7 long | trigger_entry and strategy.opentrades == 0 | On | 271 |
| order O #8 long | trigger_entry and strategy.opentrades == 0 | On | 272 |
| order O #9 long | trigger_entry and strategy.opentrades == 0 | On | 273 |
| order O #10 long | trigger_entry and strategy.opentrades == 0 | On | 274 |
| cancel O #1 | close < grid_11 and tewnty_grid == true | On | 276 |
| cancel O #2 | close < grid_12 and tewnty_grid == true | On | 278 |
| cancel O #3 | close < grid_13 and tewnty_grid == true | On | 280 |
| cancel O #4 | close < grid_14 and tewnty_grid == true | On | 282 |
| cancel O #5 | close < grid_15 and tewnty_grid == true | On | 284 |
| cancel O #6 | close < grid_16 and tewnty_grid == true | On | 286 |
| cancel O #7 | close < grid_17 and tewnty_grid == true | On | 288 |
| cancel O #8 | close < grid_18 and tewnty_grid == true | On | 290 |
| cancel O #9 | close < grid_19 and tewnty_grid == true | On | 292 |
| cancel O #10 | close < grid_20 and tewnty_grid == true | On | 294 |
| Exit C #1 limit | grid_10 and tewnty_grid == true | On | 296 |
| Exit C #2 limit | grid_9 and tewnty_grid == true | On | 303 |
| Exit C #3 limit | grid_8 and tewnty_grid == true | On | 310 |
| Exit C #4 limit | grid_7 and tewnty_grid == true | On | 317 |
| Exit C #5 limit | grid_6 and tewnty_grid == true | On | 324 |
| Exit C #6 limit | grid_5 and tewnty_grid == true | On | 331 |
| Exit C #7 limit | grid_4 and tewnty_grid == true | On | 338 |
| Exit C #8 limit | grid_3 and tewnty_grid == true | On | 345 |
| Exit C #9 limit | grid_2 and tewnty_grid == true | On | 352 |
| Exit C #10 limit | grid_1 and tewnty_grid == true | On | 359 |
| Close Grid Destroyed !!! | ta.crossunder(low, stop_level) | On | 367 |
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.
- 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.
| 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.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 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
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 |
|---|---|---|---|---|---|
| GRID SPOT TRADING ALGORITHM - GRID BOT TRADING STRATEGY this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Triple RSI strategy by Trade_by_DB | rsi | v5 strategy | +3.2% | 2 | 3.3% |
| Hobbiecode - RSI + Close previous day by hobbiecode | rsi | v5 strategy | +1.2% | 63 | 4.2% |
| dirt cheap yet elegant RSI Strategy by SparkyFlary | rsi | v4 strategy | −11.4% | 8 | 20.5% |
| RSI Classic Strategy (by Coinrule) by Coinrule | rsi | v4 strategy | +7.5% | 6 | 7.2% |
| RSITrendStrategy by email_analysts | rsi | v4 strategy | +69.2% | 22 | 38.6% |
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?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L224:C3: cannot use 'float' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯initial_grid_amount = 10000-//@version=5+//@version=6strategy(⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 198 ms | With a workaround 1,000 bars in 297 ms | 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 209, 210, 211, 212, 213, 265 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// ██████╗ ██████╗ ██╗██████╗ ███████╗██████╗ ██████╗ ████████╗ █████╗ ██╗ ██████╗ ██████╗ ██████╗ ██╗████████╗██╗ ██╗███╗ ███╗// ██╔════╝ ██╔══██╗██║██╔══██╗ ██╔════╝██╔══██╗██╔═══██╗╚══██╔══╝ ██╔══██╗██║ ██╔════╝ ██╔═══██╗██╔══██╗██║╚══██╔══╝██║ ██║████╗ ████║// ██║ ███╗██████╔╝██║██║ ██║ ███████╗██████╔╝██║ ██║ ██║ ███████║██║ ██║ ███╗██║ ██║██████╔╝██║ ██║ ███████║██╔████╔██║// ██║ ██║██╔══██╗██║██║ ██║ ╚════██║██╔═══╝ ██║ ██║ ██║ ██╔══██║██║ ██║ ██║██║ ██║██╔══██╗██║ ██║ ██╔══██║██║╚██╔╝██║// ╚██████╔╝██║ ██║██║██████╔╝ ███████║██║ ╚██████╔╝ ██║ ██║ ██║███████╗╚██████╔╝╚██████╔╝██║ ██║██║ ██║ ██║ ██║██║ ╚═╝ ██║// ╚═════╝ ╚═╝ ╚═╝╚═╝╚═════╝ ╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ initial_grid_amount = 10000//@version=5strategy( title = 'Grid Spot Trading Algorithm - The Quant Science™', overlay = true, calc_on_every_tick = true, initial_capital = initial_grid_amount, commission_type = strategy.commission.percent, commission_value = 0.10, pyramiding = 20, default_qty_type = strategy.percent_of_equity, close_entries_rule = 'ANY' )/////////////////////////////// Design by The Quant Science ™ //////////////////////////////////////----------------------------------------------------------------------------------------------------------//------------------------------------- Grid Spot Trading Algorithm ----------------------------------------//----------------------------------------------------------------------------------------------------------// HOW IT WORKS: 3Commas Grid Bot Strategy for spot asset, based on multiple dinamic trigger start condition.//----------------------------------------------------------------------------------------------------------// SET UP: Select the high price, select the low price, select the trigger entry condition. // Extra feature: adjust date range.//----------------------------------------------------------------------------------------------------------// Upgrade 2.00 (2022.30.07) // Upgrade 3.00 (2022.11.11)// Upgrade 4.00 (2022.20.01)/////////////////////////////// ALGORITHM BACKTEST SOURCE CODE ////////////////////////////////////startDate = input.int(title="Start date: ", defval=1, minval=1, maxval=31, group = '############# BACKTESTING PERIOD #############')startMonth = input.int(title="Start month: ", defval=1, minval=1, maxval=12, group = '############# BACKTESTING PERIOD #############')startYear = input.int(title="Start year: ", defval=2022, minval=1800, maxval=2100, group = '############# BACKTESTING PERIOD #############')endDate = input.int(title="End date: ", defval=31, minval=1, maxval=31, group = '############# BACKTESTING PERIOD #############')endMonth = input.int(title="End month: ", defval=12, minval=1, maxval=12, group = '############# BACKTESTING PERIOD #############')endYear = input.int(title="End year: ", defval=2022, minval=1800, maxval=2100, group = '############# BACKTESTING PERIOD #############')inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))// #########################################################################################################high_price = input.price( defval = 0.00, title = 'High price: ', group = " ################# HIGH PRICE GRID ################ ", confirm = true, tooltip = "Top grid price." )low_price = input.price( defval = 0.00, title = 'Low price: ', group = " ################# LOW PRICE GRID ################# ", confirm = true, tooltip = "Bottom grid price." )ten_grid = input.bool( defval = false, title = "Grid: 10", group = " ############## GRID CONFIGURATION ############## ", tooltip = "Create a 10 levels grid.", confirm = true )tewnty_grid = input.bool( defval = false, title = "Grid: 20", group = " ############## GRID CONFIGURATION ############## ", tooltip = "Create a 20 levels grid.", confirm = true )grid_destroyer = input.bool( defval = false, title = "Active grid destroyer", group = " ############ STOP LOSS CONFIGURATION ############ ", tooltip = "Destroy the grid when price crossunder the stop loss level.", confirm = false )stop_level = input.price( defval = 0.00, title = 'Destroy level: ', group = " ############ STOP LOSS CONFIGURATION ############ ", confirm = false, tooltip = "Stop loss price level. Always set this value below the low price grid." )// #########################################################################################################grid_range = high_price - low_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_11 = 0var float grid_12 = 0var float grid_13 = 0var float grid_14 = 0var float grid_15 = 0var float grid_16 = 0var float grid_17 = 0var float grid_18 = 0var float grid_19 = 0var float grid_20 = 0var float factor = 0 if ten_grid == true factor := grid_range / 9 grid_1 := (high_price) grid_2 := (high_price - (factor * 1)) grid_3 := (high_price - (factor * 2)) grid_4 := (high_price - (factor * 3)) grid_5 := (high_price - (factor * 4)) grid_6 := (high_price - (factor * 5)) grid_7 := (high_price - (factor * 6)) grid_8 := (high_price - (factor * 7)) grid_9 := (high_price - (factor * 8)) grid_10 := (low_price) if tewnty_grid == true factor := grid_range / 19 grid_1 := (high_price) grid_2 := (high_price - (factor * 1)) grid_3 := (high_price - (factor * 2)) grid_4 := (high_price - (factor * 3)) grid_5 := (high_price - (factor * 4)) grid_6 := (high_price - (factor * 5)) grid_7 := (high_price - (factor * 6)) grid_8 := (high_price - (factor * 7)) grid_9 := (high_price - (factor * 8)) grid_10 := (high_price - (factor * 9)) grid_11 := (high_price - (factor * 10)) grid_12 := (high_price - (factor * 11)) grid_13 := (high_price - (factor * 12)) grid_14 := (high_price - (factor * 13)) grid_15 := (high_price - (factor * 14)) grid_16 := (high_price - (factor * 15)) grid_17 := (high_price - (factor * 16)) grid_18 := (high_price - (factor * 17)) grid_19 := (high_price - (factor * 18)) grid_20 := (low_price)// #########################################################################################################var tb = table.new(position.bottom_left, 1, 1, bgcolor = color.new(color.blue, 90))if barstate.isfirst table.cell(tb, 0, 0, 'Developed by The Quant Science™' ,text_size = size.normal ,text_color = color.new(color.blue, 20))// #########################################################################################################long_1 = ta.crossunder(low, grid_1) and inDateRangelong_2 = ta.crossunder(low, grid_2) and inDateRangelong_3 = ta.crossunder(low, grid_3) and inDateRangelong_4 = ta.crossunder(low, grid_4) and inDateRangelong_5 = ta.crossunder(low, grid_5) and inDateRangelong_6 = ta.crossunder(low, grid_6) and inDateRangelong_7 = ta.crossunder(low, grid_7) and inDateRangelong_8 = ta.crossunder(low, grid_8) and inDateRangelong_9 = ta.crossunder(low, grid_9) and inDateRangelong_10 = ta.crossunder(low, grid_10) and inDateRangelong_11 = ta.crossunder(low, grid_11) and inDateRangelong_12 = ta.crossunder(low, grid_12) and inDateRangelong_13 = ta.crossunder(low, grid_13) and inDateRangelong_14 = ta.crossunder(low, grid_14) and inDateRangelong_15 = ta.crossunder(low, grid_15) and inDateRangelong_16 = ta.crossunder(low, grid_16) and inDateRangelong_17 = ta.crossunder(low, grid_17) and inDateRangelong_18 = ta.crossunder(low, grid_18) and inDateRangelong_19 = ta.crossunder(low, grid_19) and inDateRangelast_long = ta.crossunder(low, low_price) and inDateRange// #########################################################################################################// Change the default trigger start condition with your personal and custom start condition// Code the condition inside the local function below. // Define a indicator condition or another specific condition .....// Example with RSI calculating on close bar, and last 14 previous bar data rsi = ta.rsi(close, 14)// Create a local function for the trigger start condition TriggerGrid() => trigger_rsi = ta.crossover(rsi, 75) and inDateRange // Define the specific condition trigger_rsi trigger_entry = TriggerGrid() // Assign the condition to the "trigger_entry" variable// ANOTHER EASY EXAMPLE WITH OVERSOLD RSI CONDITION ....//TriggerGrid() => //trigger_rsi = ta.crossunder(rsi, 35) // Crossunder the RSI 35 value... //trigger_rsi //trigger_entry = TriggerGrid() // Assign the condition to the "trigger_entry" variable// #########################################################################################################var float lots = 0 if ten_grid == true and inDateRange lots := (initial_grid_amount / close) / 10 if trigger_entry and strategy.opentrades == 0 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)if close < grid_6 and ten_grid == true strategy.cancel("O #1")if close < grid_7 and ten_grid == true strategy.cancel("O #2")if close < grid_8 and ten_grid == true strategy.cancel("O #3")if close < grid_9 and ten_grid == true strategy.cancel("O #4")if close < grid_10 and ten_grid == true strategy.cancel("O #5")if grid_5 and ten_grid == true strategy.exit( id = "C #1", from_entry = "O #1", qty = 100, limit = grid_5 )if grid_4 and ten_grid == true strategy.exit( id = "C #2", from_entry = "O #2", qty = 100, limit = grid_4 )if grid_3 and ten_grid == true strategy.exit( id = "C #3", from_entry = "O #3", qty = 100, limit = grid_3 )if grid_2 and ten_grid == true strategy.exit( id = "C #4", from_entry = "O #4", qty = 100, limit = grid_2 )if grid_1 strategy.exit( id = "C #5", from_entry = "O #5", qty = 100, limit = grid_1 )if ten_grid == true and grid_destroyer == true if ta.crossunder(low, stop_level) strategy.close_all(" Grid Destroyed !!! ") if tewnty_grid == true and inDateRange lots := (initial_grid_amount / close) / 20 if trigger_entry and strategy.opentrades == 0 strategy.order(id = "O #1", direction = strategy.long, qty = lots, limit = grid_11) strategy.order(id = "O #2", direction = strategy.long, qty = lots, limit = grid_12) strategy.order(id = "O #3", direction = strategy.long, qty = lots, limit = grid_13) strategy.order(id = "O #4", direction = strategy.long, qty = lots, limit = grid_14) strategy.order(id = "O #5", direction = strategy.long, qty = lots, limit = grid_15) strategy.order(id = "O #6", direction = strategy.long, qty = lots, limit = grid_16) strategy.order(id = "O #7", direction = strategy.long, qty = lots, limit = grid_17) strategy.order(id = "O #8", direction = strategy.long, qty = lots, limit = grid_18) strategy.order(id = "O #9", direction = strategy.long, qty = lots, limit = grid_19) strategy.order(id = "O #10", direction = strategy.long, qty = lots, limit = grid_20)if close < grid_11 and tewnty_grid == true strategy.cancel("O #1")if close < grid_12 and tewnty_grid == true strategy.cancel("O #2")if close < grid_13 and tewnty_grid == true strategy.cancel("O #3")if close < grid_14 and tewnty_grid == true strategy.cancel("O #4")if close < grid_15 and tewnty_grid == true strategy.cancel("O #5")if close < grid_16 and tewnty_grid == true strategy.cancel("O #6")if close < grid_17 and tewnty_grid == true strategy.cancel("O #7")if close < grid_18 and tewnty_grid == true strategy.cancel("O #8")if close < grid_19 and tewnty_grid == true strategy.cancel("O #9")if close < grid_20 and tewnty_grid == true strategy.cancel("O #10")if grid_10 and tewnty_grid == true strategy.exit( id = "C #1", from_entry = "O #1", qty = 100, limit = grid_10 )if grid_9 and tewnty_grid == true strategy.exit( id = "C #2", from_entry = "O #2", qty = 100, limit = grid_9 )if grid_8 and tewnty_grid == true strategy.exit( id = "C #3", from_entry = "O #3", qty = 100, limit = grid_8 )if grid_7 and tewnty_grid == true strategy.exit( id = "C #4", from_entry = "O #4", qty = 100, limit = grid_7 )if grid_6 and tewnty_grid == true strategy.exit( id = "C #5", from_entry = "O #5", qty = 100, limit = grid_6 )if grid_5 and tewnty_grid == true strategy.exit( id = "C #6", from_entry = "O #6", qty = 100, limit = grid_5 )if grid_4 and tewnty_grid == true strategy.exit( id = "C #7", from_entry = "O #7", qty = 100, limit = grid_4 )if grid_3 and tewnty_grid == true strategy.exit( id = "C #8", from_entry = "O #8", qty = 100, limit = grid_3 )if grid_2 and tewnty_grid == true strategy.exit( id = "C #9", from_entry = "O #9", qty = 100, limit = grid_2 )if grid_1 and tewnty_grid == true strategy.exit( id = "C #10", from_entry = "O #10", qty = 100, limit = grid_1 )if tewnty_grid == true and grid_destroyer == true if ta.crossunder(low, 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 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_10 if grid_destroyer == true grid_destroyed_ten := stop_levelelse 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 := na if grid_destroyer == false grid_destroyed_ten := nafill(plot(new_ten_grid_1, color = color.new(color.green, 90)), plot(new_ten_grid_2, color = color.new(color.green, 90)), color = color.new(color.green, 90))fill(plot(new_ten_grid_2, color = color.new(color.green, 85)), plot(new_ten_grid_3, color = color.new(color.green, 85)), color = color.new(color.green, 85))fill(plot(new_ten_grid_3, color = color.new(color.green, 80)), plot(new_ten_grid_4, color = color.new(color.green, 80)), color = color.new(color.green, 80))fill(plot(new_ten_grid_4, color = color.new(color.green, 70)), plot(new_ten_grid_5, color = color.new(color.green, 70)), color = color.new(color.green, 70))fill(plot(new_ten_grid_5, color = color.new(color.green, 60)), plot(new_ten_grid_6, color = color.new(color.green, 60)), color = color.new(color.green, 60))fill(plot(new_ten_grid_6, color = color.new(color.red, 60)), plot(new_ten_grid_7, color = color.new(color.red, 60)), color = color.new(color.red, 60))fill(plot(new_ten_grid_7, color = color.new(color.red, 70)), plot(new_ten_grid_8, color = color.new(color.red, 70)), color = color.new(color.red, 70))fill(plot(new_ten_grid_8, color = color.new(color.red, 80)), plot(new_ten_grid_9, color = color.new(color.red, 80)), color = color.new(color.red, 80))fill(plot(new_ten_grid_9, color = color.new(color.red, 85)), plot(new_ten_grid_10, color = color.new(color.red, 85)), color = color.new(color.red, 85))plot(grid_destroyed_ten, color = color.new(color.red, 80), linewidth = 10)// #########################################################################################################var float new_twenty_grid_1 = 0 var float new_twenty_grid_2 = 0 var float new_twenty_grid_3 = 0 var float new_twenty_grid_4 = 0 var float new_twenty_grid_5 = 0 var float new_twenty_grid_6 = 0 var float new_twenty_grid_7 = 0 var float new_twenty_grid_8 = 0 var float new_twenty_grid_9 = 0 var float new_twenty_grid_10 = 0 var float new_twenty_grid_11 = 0 var float new_twenty_grid_12 = 0 var float new_twenty_grid_13 = 0 var float new_twenty_grid_14 = 0 var float new_twenty_grid_15 = 0 var float new_twenty_grid_16 = 0 var float new_twenty_grid_17 = 0 var float new_twenty_grid_18 = 0 var float new_twenty_grid_19 = 0 var float new_twenty_grid_20 = 0 var float grid_destroyed_twenty = 0if tewnty_grid == true new_twenty_grid_1 := grid_1 new_twenty_grid_2 := grid_2 new_twenty_grid_3 := grid_3 new_twenty_grid_4 := grid_4 new_twenty_grid_5 := grid_5 new_twenty_grid_6 := grid_6 new_twenty_grid_7 := grid_7 new_twenty_grid_8 := grid_8 new_twenty_grid_9 := grid_9 new_twenty_grid_10 := grid_10 new_twenty_grid_11 := grid_11 new_twenty_grid_12 := grid_12 new_twenty_grid_13 := grid_13 new_twenty_grid_14 := grid_14 new_twenty_grid_15 := grid_15 new_twenty_grid_16 := grid_16 new_twenty_grid_17 := grid_17 new_twenty_grid_18 := grid_18 new_twenty_grid_19 := grid_19 new_twenty_grid_20 := grid_20 if grid_destroyer == true grid_destroyed_twenty := stop_levelelse if tewnty_grid == false new_twenty_grid_1 := na new_twenty_grid_2 := na new_twenty_grid_3 := na new_twenty_grid_4 := na new_twenty_grid_5 := na new_twenty_grid_6 := na new_twenty_grid_7 := na new_twenty_grid_8 := na new_twenty_grid_9 := na new_twenty_grid_10 := na new_twenty_grid_11 := na new_twenty_grid_12 := na new_twenty_grid_13 := na new_twenty_grid_14 := na new_twenty_grid_15 := na new_twenty_grid_16 := na new_twenty_grid_17 := na new_twenty_grid_18 := na new_twenty_grid_19 := na new_twenty_grid_20 := na if grid_destroyer == false grid_destroyed_twenty := nafill(plot(new_twenty_grid_1, color = color.new(color.green, 90)), plot(new_twenty_grid_2, color = color.new(color.green, 90)), color = color.new(color.green, 90))fill(plot(new_twenty_grid_2, color = color.new(color.green, 85)), plot(new_twenty_grid_3, color = color.new(color.green, 85)), color = color.new(color.green, 85))fill(plot(new_twenty_grid_3, color = color.new(color.green, 80)), plot(new_twenty_grid_4, color = color.new(color.green, 80)), color = color.new(color.green, 80))fill(plot(new_twenty_grid_4, color = color.new(color.green, 70)), plot(new_twenty_grid_5, color = color.new(color.green, 70)), color = color.new(color.green, 70))fill(plot(new_twenty_grid_5, color = color.new(color.green, 60)), plot(new_twenty_grid_6, color = color.new(color.green, 60)), color = color.new(color.green, 60))fill(plot(new_twenty_grid_6, color = color.new(color.green, 60)), plot(new_twenty_grid_7, color = color.new(color.green, 60)), color = color.new(color.green, 60))fill(plot(new_twenty_grid_7, color = color.new(color.green, 70)), plot(new_twenty_grid_8, color = color.new(color.green, 70)), color = color.new(color.green, 70))fill(plot(new_twenty_grid_8, color = color.new(color.green, 80)), plot(new_twenty_grid_9, color = color.new(color.green, 80)), color = color.new(color.green, 80))fill(plot(new_twenty_grid_9, color = color.new(color.green, 85)), plot(new_twenty_grid_10, color = color.new(color.green, 85)), color = color.new(color.green, 85))fill(plot(new_twenty_grid_10, color = color.new(color.red, 90)), plot(new_twenty_grid_11, color = color.new(color.red, 90)), color = color.new(color.red, 90))fill(plot(new_twenty_grid_11, color = color.new(color.red, 85)), plot(new_twenty_grid_12, color = color.new(color.red, 85)), color = color.new(color.red, 85))fill(plot(new_twenty_grid_12, color = color.new(color.red, 80)), plot(new_twenty_grid_13, color = color.new(color.red, 80)), color = color.new(color.red, 80))fill(plot(new_twenty_grid_13, color = color.new(color.red, 70)), plot(new_twenty_grid_14, color = color.new(color.red, 70)), color = color.new(color.red, 70))fill(plot(new_twenty_grid_14, color = color.new(color.red, 60)), plot(new_twenty_grid_15, color = color.new(color.red, 60)), color = color.new(color.red, 60))fill(plot(new_twenty_grid_15, color = color.new(color.red, 60)), plot(new_twenty_grid_16, color = color.new(color.red, 60)), color = color.new(color.red, 60))fill(plot(new_twenty_grid_16, color = color.new(color.red, 70)), plot(new_twenty_grid_17, color = color.new(color.red, 70)), color = color.new(color.red, 70))fill(plot(new_twenty_grid_17, color = color.new(color.red, 80)), plot(new_twenty_grid_18, color = color.new(color.red, 80)), color = color.new(color.red, 80))fill(plot(new_twenty_grid_18, color = color.new(color.red, 85)), plot(new_twenty_grid_19, color = color.new(color.red, 85)), color = color.new(color.red, 85))fill(plot(new_twenty_grid_19, color = color.new(color.red, 85)), plot(new_twenty_grid_20, color = color.new(color.red, 85)), color = color.new(color.red, 85))plot(grid_destroyed_twenty, color = color.new(color.red, 80), linewidth = 10)// #########################################################################################################