Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Grid Strategy with MA

A Pine Script v5 strategy built on EMA or SMA or HMA or WMA or RMA or Linreg (source, 100), EMA (source, 100) and SMA (source, 100). It has 30 order rules, 15 entries among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 10000 in cash and pays 0.04% commission. 5 settings; defaults include MA Length 100, MA Type SMA and Grid Logic ATR.

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 Strategy with MA repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 11 of 11 trades.
How did Grid Strategy with MA do on BTCUSDT 1D with default settings?
−0.20%
From 26 Jan 2024 to 21 Oct 2026, over 61 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Grid Strategy with MA run in Pine Script v6?
Yes
Same 61 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
Does Grid Strategy with MA use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Grid Strategy with MA run in Zeal Terminal?
Yes
It compiles in 103 ms and runs 1,000 bars in 189 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (5)
0.0050,000100,000150,000AprJulOct2025AprJulOct2026AprJulOct$104,928$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
Net profit
−0.20%
−$200.27
Buy and hold
+102.5%
same period
Closed trades
61
31 won · 30 lost
Profitable
50.8%
of closed trades
Profit factor
0.99
gross profit ÷ gross loss
Max drawdown
26.64%
−$31,780.00

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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.

  • Likely bug

    The “ATR” option calculates EMA line 51

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 52

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 53

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 54

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 55

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 56

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 57

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 58

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 61

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 62

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 63

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 64

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 65

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 66

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 67

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    The “ATR” option calculates EMA line 68

    Choosing ATR in “Grid Logic” runs ta.ema, not ta.atr. Anyone picking ATR gets a different average from the one they asked for.

    logic == 'ATR' ? ta.ema(logic == 'ATR' ? ta.atr(
  • Likely bug

    ta.ema(main_plot + atr*(band_mult*1), 5) ignores the settings line 51

    Line 51 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot + atr*(band_mult*1), 5)ta.ema(main_plot + atr*(band_mult*1), length)
  • Likely bug

    ta.ema((main_plot*(1+band_mult*0.01*1)), 5) ignores the settings line 51

    Line 51 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1+band_mult*0.01*1)), 5)ta.ema((main_plot*(1+band_mult*0.01*1)), length)
  • Likely bug

    ta.ema(main_plot + atr*(band_mult*2), 5) ignores the settings line 52

    Line 52 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot + atr*(band_mult*2), 5)ta.ema(main_plot + atr*(band_mult*2), length)
  • Likely bug

    ta.ema((main_plot*(1+band_mult*0.01*2)), 5) ignores the settings line 52

    Line 52 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1+band_mult*0.01*2)), 5)ta.ema((main_plot*(1+band_mult*0.01*2)), length)
  • Likely bug

    ta.ema(main_plot + atr*(band_mult*3), 5) ignores the settings line 53

    Line 53 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot + atr*(band_mult*3), 5)ta.ema(main_plot + atr*(band_mult*3), length)
  • Likely bug

    ta.ema((main_plot*(1+band_mult*0.01*3)), 5) ignores the settings line 53

    Line 53 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1+band_mult*0.01*3)), 5)ta.ema((main_plot*(1+band_mult*0.01*3)), length)
  • Likely bug

    ta.ema(main_plot + atr*(band_mult*4), 5) ignores the settings line 54

    Line 54 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot + atr*(band_mult*4), 5)ta.ema(main_plot + atr*(band_mult*4), length)
  • Likely bug

    ta.ema((main_plot*(1+band_mult*0.01*4)), 5) ignores the settings line 54

    Line 54 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1+band_mult*0.01*4)), 5)ta.ema((main_plot*(1+band_mult*0.01*4)), length)
  • Likely bug

    ta.ema(main_plot + atr*(band_mult*5), 5) ignores the settings line 55

    Line 55 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot + atr*(band_mult*5), 5)ta.ema(main_plot + atr*(band_mult*5), length)
  • Likely bug

    ta.ema((main_plot*(1+band_mult*0.01*5)), 5) ignores the settings line 55

    Line 55 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1+band_mult*0.01*5)), 5)ta.ema((main_plot*(1+band_mult*0.01*5)), length)
  • Likely bug

    ta.ema(main_plot + atr*(band_mult*6), 5) ignores the settings line 56

    Line 56 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot + atr*(band_mult*6), 5)ta.ema(main_plot + atr*(band_mult*6), length)
  • Likely bug

    ta.ema((main_plot*(1+band_mult*0.01*6)), 5) ignores the settings line 56

    Line 56 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1+band_mult*0.01*6)), 5)ta.ema((main_plot*(1+band_mult*0.01*6)), length)
  • Likely bug

    ta.ema(main_plot + atr*(band_mult*7), 5) ignores the settings line 57

    Line 57 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot + atr*(band_mult*7), 5)ta.ema(main_plot + atr*(band_mult*7), length)
  • Likely bug

    ta.ema((main_plot*(1+band_mult*0.01*7)), 5) ignores the settings line 57

    Line 57 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1+band_mult*0.01*7)), 5)ta.ema((main_plot*(1+band_mult*0.01*7)), length)
  • Likely bug

    ta.ema(main_plot + atr*(band_mult*8), 5) ignores the settings line 58

    Line 58 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot + atr*(band_mult*8), 5)ta.ema(main_plot + atr*(band_mult*8), length)
  • Likely bug

    ta.ema((main_plot*(1+band_mult*0.01*8)), 5) ignores the settings line 58

    Line 58 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1+band_mult*0.01*8)), 5)ta.ema((main_plot*(1+band_mult*0.01*8)), length)
  • Likely bug

    ta.ema(main_plot - atr*(band_mult*1), 5) ignores the settings line 61

    Line 61 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot - atr*(band_mult*1), 5)ta.ema(main_plot - atr*(band_mult*1), length)
  • Likely bug

    ta.ema((main_plot*(1-band_mult*0.01*1)), 5) ignores the settings line 61

    Line 61 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1-band_mult*0.01*1)), 5)ta.ema((main_plot*(1-band_mult*0.01*1)), length)
  • Likely bug

    ta.ema(main_plot - atr*(band_mult*2), 5) ignores the settings line 62

    Line 62 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot - atr*(band_mult*2), 5)ta.ema(main_plot - atr*(band_mult*2), length)
  • Likely bug

    ta.ema((main_plot*(1-band_mult*0.01*2)), 5) ignores the settings line 62

    Line 62 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1-band_mult*0.01*2)), 5)ta.ema((main_plot*(1-band_mult*0.01*2)), length)
  • Likely bug

    ta.ema(main_plot - atr*(band_mult*3), 5) ignores the settings line 63

    Line 63 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot - atr*(band_mult*3), 5)ta.ema(main_plot - atr*(band_mult*3), length)
  • Likely bug

    ta.ema((main_plot*(1-band_mult*0.01*3)), 5) ignores the settings line 63

    Line 63 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1-band_mult*0.01*3)), 5)ta.ema((main_plot*(1-band_mult*0.01*3)), length)
  • Likely bug

    ta.ema(main_plot - atr*(band_mult*4), 5) ignores the settings line 64

    Line 64 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot - atr*(band_mult*4), 5)ta.ema(main_plot - atr*(band_mult*4), length)
  • Likely bug

    ta.ema((main_plot*(1-band_mult*0.01*4)), 5) ignores the settings line 64

    Line 64 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1-band_mult*0.01*4)), 5)ta.ema((main_plot*(1-band_mult*0.01*4)), length)
  • Likely bug

    ta.ema(main_plot - atr*(band_mult*5), 5) ignores the settings line 65

    Line 65 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot - atr*(band_mult*5), 5)ta.ema(main_plot - atr*(band_mult*5), length)
  • Likely bug

    ta.ema((main_plot*(1-band_mult*0.01*5)), 5) ignores the settings line 65

    Line 65 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1-band_mult*0.01*5)), 5)ta.ema((main_plot*(1-band_mult*0.01*5)), length)
  • Likely bug

    ta.ema(main_plot - atr*(band_mult*6), 5) ignores the settings line 66

    Line 66 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot - atr*(band_mult*6), 5)ta.ema(main_plot - atr*(band_mult*6), length)
  • Likely bug

    ta.ema((main_plot*(1-band_mult*0.01*6)), 5) ignores the settings line 66

    Line 66 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1-band_mult*0.01*6)), 5)ta.ema((main_plot*(1-band_mult*0.01*6)), length)
  • Likely bug

    ta.ema(main_plot - atr*(band_mult*7), 5) ignores the settings line 67

    Line 67 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot - atr*(band_mult*7), 5)ta.ema(main_plot - atr*(band_mult*7), length)
  • Likely bug

    ta.ema((main_plot*(1-band_mult*0.01*7)), 5) ignores the settings line 67

    Line 67 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1-band_mult*0.01*7)), 5)ta.ema((main_plot*(1-band_mult*0.01*7)), length)
  • Likely bug

    ta.ema(main_plot - atr*(band_mult*8), 5) ignores the settings line 68

    Line 68 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema(main_plot - atr*(band_mult*8), 5)ta.ema(main_plot - atr*(band_mult*8), length)
  • Likely bug

    ta.ema((main_plot*(1-band_mult*0.01*8)), 5) ignores the settings line 68

    Line 68 hard-codes 5 where line 32 uses “MA Length”. Changing those settings moves one band but not this one.

    ta.ema((main_plot*(1-band_mult*0.01*8)), 5)ta.ema((main_plot*(1-band_mult*0.01*8)), length)
  • Check

    1 setting does nothing

    “ATR Length” is declared but never read.

  • Check

    No stop loss

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

  • 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
MA
MA Length100intmaPrice ema sma main_plot atr
MA TypeSMAstring · options ['EMA', 'HMA', 'LSMA', 'RMA', 'SMA', 'WMA']main_plot
Grid LogicATRstring · options ['ATR', 'Percent']premium_zone_1 premium_zone_2 premium_zone_3 premium_zone_4 premium_zone_5 premium_zone_6 premium_zone_7 premium_zone_8 discount_zone_1 discount_zone_2 discount_zone_3 discount_zone_4 discount_zone_5 discount_zone_6 discount_zone_7 discount_zone_8
Parameter
Band Multiplier/Percent2.5float · step 0.1premium_zone_1 premium_zone_2 premium_zone_3 premium_zone_4 premium_zone_5 premium_zone_6 premium_zone_7 premium_zone_8 discount_zone_1 discount_zone_2 discount_zone_3 discount_zone_4 discount_zone_5 discount_zone_6 discount_zone_7 discount_zone_8
parameter
ATR Length100intunused

What it calculates

  • EMA / SMA / HMA / WMA / RMA / Linregsource, MA Length (100)maPrice · line 32
  • EMAsource, MA Length (100)ema · line 33
  • SMAsource, MA Length (100)sma · line 34
  • ATRMA Length (100)atr · line 50
  • EMAmain_plot + atr*(band_mult*1), 5 · chosen by Grid Logicpremium_zone_1 · line 51
  • EMAmain_plot + atr*(band_mult*2), 5 · chosen by Grid Logicpremium_zone_2 · line 52
  • EMAmain_plot + atr*(band_mult*3), 5 · chosen by Grid Logicpremium_zone_3 · line 53
  • EMAmain_plot + atr*(band_mult*4), 5 · chosen by Grid Logicpremium_zone_4 · line 54
  • EMAmain_plot + atr*(band_mult*5), 5 · chosen by Grid Logicpremium_zone_5 · line 55
  • EMAmain_plot + atr*(band_mult*6), 5 · chosen by Grid Logicpremium_zone_6 · line 56
  • EMAmain_plot + atr*(band_mult*7), 5 · chosen by Grid Logicpremium_zone_7 · line 57
  • EMAmain_plot + atr*(band_mult*8), 5 · chosen by Grid Logicpremium_zone_8 · line 58
  • EMAmain_plot - atr*(band_mult*1), 5 · chosen by Grid Logicdiscount_zone_1 · line 61
  • EMAmain_plot - atr*(band_mult*2), 5 · chosen by Grid Logicdiscount_zone_2 · line 62
  • EMAmain_plot - atr*(band_mult*3), 5 · chosen by Grid Logicdiscount_zone_3 · line 63
  • EMAmain_plot - atr*(band_mult*4), 5 · chosen by Grid Logicdiscount_zone_4 · line 64
  • EMAmain_plot - atr*(band_mult*5), 5 · chosen by Grid Logicdiscount_zone_5 · line 65
  • EMAmain_plot - atr*(band_mult*6), 5 · chosen by Grid Logicdiscount_zone_6 · line 66
  • EMAmain_plot - atr*(band_mult*7), 5 · chosen by Grid Logicdiscount_zone_7 · line 67
  • EMAmain_plot - atr*(band_mult*8), 5 · chosen by Grid Logicdiscount_zone_8 · line 68
  • Crossunderlow, discount_zone_7longCondition1 · line 119
  • Crossunderlow, discount_zone_6longCondition2 · line 120
  • Crossunderlow, discount_zone_5longCondition3 · line 121
  • Crossunderlow, discount_zone_4longCondition4 · line 122
  • Crossunderlow, discount_zone_3longCondition5 · line 123
  • Crossunderlow, discount_zone_2longCondition6 · line 124
  • Crossunderlow, discount_zone_1longCondition7 · line 125
  • Crossunderlow, main_plotlongCondition8 · line 126
  • Crossunderlow, premium_zone_1longCondition9 · line 127
  • Crossunderlow, premium_zone_2longCondition10 · line 128
  • Crossunderlow, premium_zone_3longCondition11 · line 129
  • Crossunderlow, premium_zone_4longCondition12 · line 130
  • Crossunderlow, premium_zone_5longCondition13 · line 131
  • Crossunderlow, premium_zone_6longCondition14 · line 132
  • Crossunderlow, premium_zone_7longCondition15 · line 133
  • Crossoverhigh, discount_zone_6shortCondition1 · line 180
  • Crossoverhigh, discount_zone_5shortCondition2 · line 181
  • Crossoverhigh, discount_zone_4shortCondition3 · line 182
  • Crossoverhigh, discount_zone_3shortCondition4 · line 183
  • Crossoverhigh, discount_zone_2shortCondition5 · line 184
  • Crossoverhigh, discount_zone_1shortCondition6 · line 185
  • Crossoverhigh, main_plotshortCondition7 · line 186
  • Crossoverhigh, premium_zone_1shortCondition8 · line 187
  • Crossoverhigh, premium_zone_2shortCondition9 · line 188
  • Crossoverhigh, premium_zone_3shortCondition10 · line 189
  • Crossoverhigh, premium_zone_4shortCondition11 · line 190
  • Crossoverhigh, premium_zone_5shortCondition12 · line 191
  • Crossoverhigh, premium_zone_6shortCondition13 · line 192
  • Crossoverhigh, premium_zone_7shortCondition14 · line 193
  • Crossoverhigh, premium_zone_8shortCondition15 · line 194

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

Order rules

OrderFires whenBy defaultLine
Open Long1 long(longCondition1) and order_1 == falseOn135
Open Long2 long(longCondition2) and order_2 == falseOn138
Open Long3 long(longCondition3) and order_3 == falseOn141
Open Long4 long(longCondition4) and order_4 == falseOn144
Open Long5 long(longCondition5) and order_5 == falseOn147
Open Long6 long(longCondition6) and order_6 == falseOn150
Open Long7 long(longCondition7) and order_7 == falseOn153
Open Long8 long(longCondition8) and order_8 == falseOn156
Open Long9 long(longCondition9) and order_9 == falseOn159
Open Long10 long(longCondition10) and order_10 == falseOn162
Open Long11 long(longCondition11) and order_11 == falseOn165
Open Long12 long(longCondition12) and order_12 == falseOn168
Open Long13 long(longCondition13) and order_13 == falseOn171
Open Long14 long(longCondition14) and order_14 == falseOn174
Open Long14 long(longCondition15) and order_15 == falseOn177
Close Long1(shortCondition1) and order_1 == trueOn196
Close Long2(shortCondition2) and order_2 == trueOn199
Close Long3(shortCondition3) and order_3 == trueOn202
Close Long4(shortCondition4) and order_4 == trueOn205
Close Long5(shortCondition5) and order_5 == trueOn208
Close Long6(shortCondition6) and order_6 == trueOn211
Close Long7(shortCondition7) and order_7 == trueOn214
Close Long8(shortCondition8) and order_8 == trueOn217
Close Long9(shortCondition9) and order_9 == trueOn220
Close Long10(shortCondition10) and order_10 == trueOn223
Close Long11(shortCondition11) and order_11 == trueOn226
Close Long12(shortCondition12) and order_12 == trueOn229
Close Long13(shortCondition13) and order_13 == trueOn232
Close Long14(shortCondition14) and order_14 == trueOn235
Close Long15(shortCondition15) and order_15 == trueOn238

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, and the live replay matched history.

11/11trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.

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 1D−0.2%+102.5%6151%0.9926.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+5.2%+5.5%6269%1.848.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−22.8%+9.8%6245%0.6340.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+7.3%+8.4%4078%2.688.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−3.9%+16.7%5157%0.9129.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+9.9%+21.5%6067%2.338.9%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+1.9%+148.3%6763%1.0527.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+3.0%+17.1%5961%1.438.6%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market1839%−$2,646.65
Sideways market2658%−$1,866.30
Falling market1753%$4,321.81

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

12.1%

The 95th percentile of the worst drawdown when the same 61 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 5.3% to 12.1%; the tick is what actually happened, 18.8%. Order luck alone moves it this much.

0%22%
All 61 trades
SideEntryExitBarsP&L
long9 May 2024 63,074.0020 May 2024 71,446.6011$1,318.90
long11 Jun 2024 67,314.2015 Jul 2024 64,724.1034−$392.62
long24 Jun 2024 60,293.3015 Jul 2024 64,724.1021$75.78
long24 Jun 2024 60,293.308 Aug 2024 61,686.0045$199.65
long4 Aug 2024 58,161.008 Aug 2024 61,686.004$127.13
long4 Aug 2024 58,161.0023 Aug 2024 64,037.2019$788.87
long5 Aug 2024 54,018.8023 Aug 2024 64,037.2018$364.58
long5 Aug 2024 54,018.8018 Sep 2024 61,760.0044$1,143.13
long4 Sep 2024 57,970.9018 Sep 2024 61,760.0014$89.58
long4 Sep 2024 57,970.9015 Oct 2024 67,074.1041$1,344.92
long21 Oct 2024 67,377.506 Nov 2024 75,572.0016$1,207.72
long25 Nov 2024 93,010.0015 Dec 2024 104,464.0020$1,173.34
long25 Nov 2024 93,010.0017 Jan 2025 104,077.0053$47.96
long5 Dec 2024 96,945.6017 Jan 2025 104,077.0043$727.36
long19 Dec 2024 97,461.9017 Jan 2025 104,077.0029$3.47
long19 Dec 2024 97,461.902 Mar 2025 94,270.0073−$333.63
long23 Dec 2024 94,881.502 Mar 2025 94,270.0069−$11.32
long23 Dec 2024 94,881.5019 Mar 2025 86,845.9086−$720.93
long9 Jan 2025 92,552.5019 Mar 2025 86,845.9069−$221.42
long9 Jan 2025 92,552.509 Apr 2025 82,615.2090−$697.78
long27 Jan 2025 102,083.009 Apr 2025 82,615.2072−$1,105.93
long27 Jan 2025 102,083.0022 Apr 2025 93,443.0085−$360.63
long3 Feb 2025 101,329.0022 Apr 2025 93,443.0078−$568.58
long3 Feb 2025 101,329.008 May 2025 103,262.0094$50.52
long25 Feb 2025 88,680.408 May 2025 103,262.0072$1,035.60
long25 Feb 2025 88,680.4019 May 2025 105,574.0083$695.59
long28 Feb 2025 84,349.9019 May 2025 105,574.0080$1,196.84
long28 Feb 2025 84,349.9010 Jul 2025 116,010.00132$1,956.68
long10 Mar 2025 78,595.9010 Jul 2025 116,010.00122$1,301.08
long10 Mar 2025 78,595.902 Oct 2025 120,529.00206$3,687.77
long10 Mar 2025 78,595.9012 Oct 2025 114,959.00216$155.12
long7 Apr 2025 79,163.2012 Oct 2025 114,959.00188$3,014.51
long7 Apr 2025 79,163.2026 Oct 2025 114,559.00202$1,480.69
long20 Jun 2025 103,298.0026 Oct 2025 114,559.00128$564.33
long20 Jun 2025 103,298.0028 Nov 2025 90,890.70161−$578.11
long1 Aug 2025 113,298.0028 Nov 2025 90,890.70119−$1,600.39
long1 Aug 2025 113,298.005 Jan 2026 93,859.70157−$333.80
long24 Aug 2025 113,494.005 Jan 2026 93,859.70134−$1,737.26
long10 Oct 2025 112,775.005 Jan 2026 93,859.7087−$9.59
long10 Oct 2025 112,775.0014 Jan 2026 96,951.8096−$1,402.45
long10 Oct 2025 112,775.0014 Jan 2026 96,951.8096−$66.00
long10 Oct 2025 112,775.0025 Feb 2026 67,988.00138−$3,791.62
long16 Oct 2025 108,194.0025 Feb 2026 67,988.00132−$2,997.96
long16 Oct 2025 108,194.0013 Mar 2026 70,930.00148−$671.76
long30 Oct 2025 108,323.0013 Mar 2026 70,930.00134−$3,458.60
long14 Nov 2025 94,594.0013 Mar 2026 70,930.00119−$396.05
long14 Nov 2025 94,594.0014 Apr 2026 74,131.60151−$1,827.68
long21 Nov 2025 85,129.4014 Apr 2026 74,131.60144−$266.16
long21 Nov 2025 85,129.404 May 2026 79,861.00164−$473.02
long21 Nov 2025 85,129.4015 Jun 2026 66,328.70206−$89.29
long20 Jan 2026 88,427.7015 Jun 2026 66,328.70146−$2,506.10
long31 Jan 2026 78,741.1015 Jun 2026 66,328.70135−$573.16
long31 Jan 2026 78,741.106 Jul 2026 64,042.00156−$1,195.79
long5 Feb 2026 62,909.906 Jul 2026 64,042.00151$89.42
long5 Feb 2026 62,909.9019 Aug 2026 69,334.80195$485.99
long28 May 2026 73,617.5019 Aug 2026 69,334.8083−$319.07
long28 May 2026 73,617.5020 Aug 2026 73,025.1084−$40.57
long2 Jun 2026 66,760.8020 Aug 2026 73,025.1079$456.44
long2 Jun 2026 66,760.8021 Aug 2026 78,338.0080$878.56
long5 Jun 2026 61,056.5021 Aug 2026 78,338.0077$206.60
long5 Jun 2026 61,056.5021 Sep 2026 86,620.00108$2,688.03

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
Grid Strategy with MA this page—v5 strategy−0.2%6126.6%
Multi MA Trend Following Strategy Template by TradeAutomationema hma linreg rma sma wma atrv5 strategy+12.3%326.9%
Profit Maximizer PMax Strategy - Long-Short by melihtunasma atr ema linregv4 strategy+16.2%427.8%
Strategy - Profit Maximizer by PMax by MartinCresposma atr ema linregv4 strategyNo trades on this market
High-Low Channel Multi averages Crypto Swing strategy by exlux99sma ema wma rma linregv4 strategyNo trades on this market
Open Close Cross Strategy plus Explorer by roses27sma ema wma linreg atrv4 strategydoes not run in Zeal Terminal

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?

Yes

Same 61 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.

Download the v6 script

⋯// © Seungdori_-//@version=5+//@version=6strategy("Grid Strategy with MA", overlay=true, initial_capital = 100000, default_qty_type = strategy.cash, default_qty_value = 10000, pyramiding = 10, process_orders_on_close = true, commission_type = strategy.commission.percent, commission_value = 0.04)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 103 msYes 1,000 bars in 189 msNot measured
PineTSNot testedNot testedNot 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/// © Seungdori_//@version=5strategy("Grid Strategy with MA", overlay=true, initial_capital = 100000, default_qty_type = strategy.cash, default_qty_value = 10000, pyramiding = 10, process_orders_on_close = true, commission_type = strategy.commission.percent, commission_value = 0.04)//Inputs//length = input.int(defval = 100, title = 'MA Length', group = 'MA')MA_Type = input.string("SMA", title="MA Type", options=['EMA', 'HMA', 'LSMA', 'RMA', 'SMA', 'WMA'],group = 'MA')logic = input.string(defval='ATR', title ='Grid Logic', options = ['ATR', 'Percent'])band_mult = input.float(2.5, step = 0.1, title = 'Band Multiplier/Percent', group = 'Parameter')atr_len = input.int(defval=100, title = 'ATR Length', group ='parameter')//Var//var int order_cond = 0var bool order_1 = falsevar bool order_2 = falsevar bool order_3 = falsevar bool order_4 = falsevar bool order_5 = falsevar bool order_6 = falsevar bool order_7 = falsevar bool order_8 = falsevar bool order_9 = falsevar bool order_10 = falsevar bool order_11 = falsevar bool order_12 = falsevar bool order_13 = falsevar bool order_14 = falsevar bool order_15 = false///////////////////////Region : Function///////////////////////getMA(source ,ma_type, length) =>    maPrice = ta.ema(source, length)    ema = ta.ema(source, length)    sma = ta.sma(source, length)    if ma_type == 'SMA'        maPrice := ta.sma(source, length)        maPrice    if ma_type == 'HMA'        maPrice := ta.hma(source, length)        maPrice    if ma_type == 'WMA'        maPrice := ta.wma(source, length)        maPrice    if ma_type == "RMA"        maPrice := ta.rma(source, length)    if ma_type == "LSMA"        maPrice := ta.linreg(source, length, 0)    maPricemain_plot = getMA(ohlc4, MA_Type, length)atr = ta.atr(length)premium_zone_1 = logic == 'ATR' ? ta.ema(main_plot + atr*(band_mult*1), 5) : ta.ema((main_plot*(1+band_mult*0.01*1)), 5)premium_zone_2 = logic == 'ATR' ? ta.ema(main_plot + atr*(band_mult*2), 5) : ta.ema((main_plot*(1+band_mult*0.01*2)), 5)premium_zone_3 = logic == 'ATR' ? ta.ema(main_plot + atr*(band_mult*3), 5) : ta.ema((main_plot*(1+band_mult*0.01*3)), 5)premium_zone_4 = logic == 'ATR' ? ta.ema(main_plot + atr*(band_mult*4), 5) : ta.ema((main_plot*(1+band_mult*0.01*4)), 5)premium_zone_5 = logic == 'ATR' ? ta.ema(main_plot + atr*(band_mult*5), 5) : ta.ema((main_plot*(1+band_mult*0.01*5)), 5)premium_zone_6 = logic == 'ATR' ? ta.ema(main_plot + atr*(band_mult*6), 5) : ta.ema((main_plot*(1+band_mult*0.01*6)), 5)premium_zone_7 = logic == 'ATR' ? ta.ema(main_plot + atr*(band_mult*7), 5) : ta.ema((main_plot*(1+band_mult*0.01*7)), 5)premium_zone_8 = logic == 'ATR' ? ta.ema(main_plot + atr*(band_mult*8), 5) : ta.ema((main_plot*(1+band_mult*0.01*8)), 5)//premium_zone_9 = ta.rma(main_plot + atr*(band_mult*9), 5)//premium_zone_10 = ta.rma(main_plot + atr*(band_mult*10), 5)discount_zone_1 = logic == 'ATR' ? ta.ema(main_plot - atr*(band_mult*1), 5) : ta.ema((main_plot*(1-band_mult*0.01*1)), 5)discount_zone_2 = logic == 'ATR' ? ta.ema(main_plot - atr*(band_mult*2), 5) : ta.ema((main_plot*(1-band_mult*0.01*2)), 5)discount_zone_3 = logic == 'ATR' ? ta.ema(main_plot - atr*(band_mult*3), 5) : ta.ema((main_plot*(1-band_mult*0.01*3)), 5)discount_zone_4 = logic == 'ATR' ? ta.ema(main_plot - atr*(band_mult*4), 5) : ta.ema((main_plot*(1-band_mult*0.01*4)), 5)discount_zone_5 = logic == 'ATR' ? ta.ema(main_plot - atr*(band_mult*5), 5) : ta.ema((main_plot*(1-band_mult*0.01*5)), 5)discount_zone_6 = logic == 'ATR' ? ta.ema(main_plot - atr*(band_mult*6), 5) : ta.ema((main_plot*(1-band_mult*0.01*6)), 5)discount_zone_7 = logic == 'ATR' ? ta.ema(main_plot - atr*(band_mult*7), 5) : ta.ema((main_plot*(1-band_mult*0.01*7)), 5)discount_zone_8 = logic == 'ATR' ? ta.ema(main_plot - atr*(band_mult*8), 5) : ta.ema((main_plot*(1-band_mult*0.01*8)), 5)//discount_zon_9 = ta.sma(main_plot - atr*(band_mult*9), 5)//discount_zone_10 =ta.sma( main_plot - atr*(band_mult*10), 5)//Region End//////////////////////// Region : Plots/////////////////////dis_low1 = plot(discount_zone_1, color=color.new(color.green, 80))dis_low2 = plot(discount_zone_2, color=color.new(color.green, 70))dis_low3 = plot(discount_zone_3, color=color.new(color.green, 60))dis_low4 = plot(discount_zone_4, color=color.new(color.green, 50))dis_low5 = plot(discount_zone_5, color=color.new(color.green, 40))dis_low6 = plot(discount_zone_6, color=color.new(color.green, 30))dis_low7 = plot(discount_zone_7, color=color.new(color.green, 20))dis_low8 = plot(discount_zone_8, color=color.new(color.green, 10))//dis_low9 = plot(discount_zone_9, color=color.new(color.green, 0))//dis_low10 = plot(discount_zone_10, color=color.new(color.green, 0))plot(main_plot, color =color.new(color.gray, 10))pre_up1 = plot(premium_zone_1, color=color.new(color.red, 80))pre_up2 = plot(premium_zone_2, color=color.new(color.red, 70))pre_up3 = plot(premium_zone_3, color=color.new(color.red, 60))pre_up4 = plot(premium_zone_4, color=color.new(color.red, 50))pre_up5 = plot(premium_zone_5, color=color.new(color.red, 40))pre_up6 = plot(premium_zone_6, color=color.new(color.red, 30))pre_up7 = plot(premium_zone_7, color=color.new(color.red, 20))pre_up8 = plot(premium_zone_8, color=color.new(color.red, 10))//pre_up9 = plot(premium_zone_9, color=color.new(color.red, 0))//pre_up10 = plot(premium_zone_10, color=color.new(color.red, 0))fill(dis_low1, dis_low2, color=color.new(color.green, 95))fill(dis_low2, dis_low3, color=color.new(color.green, 90))fill(dis_low3, dis_low4, color=color.new(color.green, 85))fill(dis_low4, dis_low5, color=color.new(color.green, 80))fill(dis_low5, dis_low6, color=color.new(color.green, 75))fill(dis_low6, dis_low7, color=color.new(color.green, 70))fill(dis_low7, dis_low8, color=color.new(color.green, 65))//fill(dis_low8, dis_low9, color=color.new(color.green, 60))//fill(dis_low9, dis_low10, color=color.new(color.green, 55))fill(pre_up1, pre_up2, color=color.new(color.red, 95))fill(pre_up2, pre_up3, color=color.new(color.red, 90))fill(pre_up3, pre_up4, color=color.new(color.red, 85))fill(pre_up4, pre_up5, color=color.new(color.red, 80))fill(pre_up5, pre_up6, color=color.new(color.red, 75))fill(pre_up6, pre_up7, color=color.new(color.red, 70))fill(pre_up7, pre_up8, color=color.new(color.red, 65))//fill(pre_up8, pre_up9, color=color.new(color.red, 60))//fill(pre_up9, pre_up10, color=color.new(color.red, 55))//Region End///////////////////////////Region : Strategies///////////////////////////Longs//longCondition1 = ta.crossunder(low, discount_zone_7)longCondition2 = ta.crossunder(low, discount_zone_6)longCondition3 = ta.crossunder(low, discount_zone_5)longCondition4 = ta.crossunder(low, discount_zone_4)longCondition5 = ta.crossunder(low, discount_zone_3)longCondition6 = ta.crossunder(low, discount_zone_2)longCondition7 = ta.crossunder(low, discount_zone_1)longCondition8 = ta.crossunder(low, main_plot)longCondition9 = ta.crossunder(low, premium_zone_1)longCondition10 = ta.crossunder(low, premium_zone_2)longCondition11 = ta.crossunder(low, premium_zone_3)longCondition12 = ta.crossunder(low, premium_zone_4)longCondition13 = ta.crossunder(low, premium_zone_5)longCondition14 = ta.crossunder(low, premium_zone_6)longCondition15 = ta.crossunder(low, premium_zone_7)if (longCondition1) and order_1 == false    strategy.entry("Long1", strategy.long)    order_1 := trueif (longCondition2) and order_2 == false    strategy.entry("Long2", strategy.long)    order_2 := trueif (longCondition3) and order_3 == false    strategy.entry("Long3", strategy.long)    order_3 := trueif (longCondition4) and order_4 == false    strategy.entry("Long4", strategy.long)    order_4 := trueif (longCondition5) and order_5 == false    strategy.entry("Long5", strategy.long)    order_5 := trueif (longCondition6) and order_6 == false    strategy.entry("Long6", strategy.long)    order_6 := trueif (longCondition7) and order_7 == false    strategy.entry("Long7", strategy.long)    order_7 := trueif (longCondition8) and order_8 == false    strategy.entry("Long8", strategy.long)    order_8 := trueif (longCondition9) and order_9 == false    strategy.entry("Long9", strategy.long)    order_9 := trueif (longCondition10) and order_10 == false    strategy.entry("Long10", strategy.long)    order_10 := trueif (longCondition11) and order_11 == false    strategy.entry("Long11", strategy.long)    order_11 := trueif (longCondition12) and order_12 == false    strategy.entry("Long12", strategy.long)    order_12 := trueif (longCondition13) and order_13 == false    strategy.entry("Long13", strategy.long)    order_13 := trueif (longCondition14) and order_14 == false    strategy.entry("Long14", strategy.long)    order_14 := trueif (longCondition15) and order_15 == false    strategy.entry("Long14", strategy.long)    order_15 := true//Close//shortCondition1 = ta.crossover(high, discount_zone_6)shortCondition2 = ta.crossover(high, discount_zone_5)shortCondition3 = ta.crossover(high, discount_zone_4)shortCondition4 = ta.crossover(high, discount_zone_3)shortCondition5 = ta.crossover(high, discount_zone_2)shortCondition6 = ta.crossover(high, discount_zone_1)shortCondition7 = ta.crossover(high, main_plot)shortCondition8 = ta.crossover(high, premium_zone_1)shortCondition9 = ta.crossover(high, premium_zone_2)shortCondition10 = ta.crossover(high, premium_zone_3)shortCondition11 = ta.crossover(high, premium_zone_4)shortCondition12 = ta.crossover(high, premium_zone_5)shortCondition13 = ta.crossover(high, premium_zone_6)shortCondition14 = ta.crossover(high, premium_zone_7)shortCondition15 = ta.crossover(high, premium_zone_8)if (shortCondition1) and order_1 == true    strategy.close("Long1")    order_1 := falseif (shortCondition2) and order_2 == true    strategy.close("Long2")    order_2 := falseif (shortCondition3) and order_3 == true    strategy.close("Long3")    order_3 := falseif (shortCondition4) and order_4 == true    strategy.close("Long4")    order_4 := falseif (shortCondition5) and order_5 == true    strategy.close("Long5")    order_5 := falseif (shortCondition6) and order_6 == true    strategy.close("Long6")    order_6 := falseif (shortCondition7) and order_7 == true    strategy.close("Long7")    order_7 := falseif (shortCondition8) and order_8 == true    strategy.close("Long8")    order_8 := falseif (shortCondition9) and order_9 == true    strategy.close("Long9")    order_9 := falseif (shortCondition10) and order_10 == true    strategy.close("Long10")    order_10 := falseif (shortCondition11) and order_11 == true    strategy.close("Long11")    order_11 := falseif (shortCondition12) and order_12 == true    strategy.close("Long12")    order_12 := falseif (shortCondition13) and order_13 == true    strategy.close("Long13")    order_13 := falseif (shortCondition14) and order_14 == true    strategy.close("Long14")    order_14 := falseif (shortCondition15) and order_15 == true    strategy.close("Long15")    order_15 := false