Grid
Grid strategy (grid). The bot places limit buy and sell orders at equal intervals within a set price range.
When the price goes down, the bot buys; when it rises by one grid step, the bot sells what it bought. Each pair of trades "bought at a level → sold at the next level up"
earns one grid step minus fees.
The grid does not need to guess the market direction: it profits from price swings inside the range, so it works best in a sideways market. The grid can run permanently or start in cycles on a signal: for example, when the price deviates from a moving average or moves outside a Bollinger band.
- The range from the lower to the upper bound is split into
grid_countcells: 20 cells - 21 price levels. Buy orders sit below the current price, sell orders above it, and one level next to the price stays empty - A buy is filled - a sell is placed one level higher. A sell is filled - a buy is placed one level lower
- One cell is one fixed size that the bot buys or sells at one level
- The bot derives the grid state from the position size, not from a saved order history. The grid survives a bot restart, partial fills and manual intervention: on the next minute the bot places missing orders and removes extra ones. Orders that are not on grid levels are left untouched
- Where to buy and sell is defined by the bounds, number of cells and step, not by indicators. Candles of the strategy timeframe (
basic.time_frame) are only needed for ATR, Bollinger bands, the start signal, filters andtime_close
Order type used: Limit (maker only by default). Market - initial buy, grid stop and stop-loss.
The bot chart shows the grid levels: buys, sells, the empty level and the bounds. With more than 60 levels only the bounds are shown. While the grid waits for a signal, the chart shows the threshold lines.
⚠️ In a strong trend the grid accumulates a position against the move (a long grid in a decline) or exits the position too early (a long grid in a rally).
Protection against a prolonged trend - stop_out_percent, position filters and the position limit.
How the range is set - range_type
| Value | Grid bounds | When it fits |
fixed | Set manually: lower_price and upper_price | You know the corridor the price moves in |
percent | ± range_percent % from the start price | The universal default |
atr | ± atr_mult × ATR from the start price | The grid width adapts to the current volatility |
bollinger | Between the Bollinger bands (bb_len, bb_mult) at build time | The grid covers the current price swing corridor |
The percent, atr and bollinger bounds are calculated once, when the grid is built. After that the grid stays in place until it is rebuilt by trailing,
a restart after a stop or a new signal cycle. If at build time the price is outside a Bollinger band, the bound on that side moves to the price.
Direction - direction
| Value | Holds | How it works |
long | Long | Buys below the price, sells above. The classic spot grid: accumulates the coin on the way down and sells it on the way up |
short | Short | Mirrored: sells above the price, buys back below. Builds a short as the price rises |
neutral | Long or short | No position at the start price. Builds a long below it and a short above it. Futures only and only without a start signal |
both | Long or short | Only for signal start (start): the signal picks the side of each cycle |
On spot only the long direction is available.
Level spacing - spacing
geometric- equal step in percent. For wide ranges: the cell profit in percent is the same across the gridarithmetic- equal step in price. For narrow ranges
Trailing - trailing
A regular long grid sells everything in a strong rally and stops above the range with no position. With trailing the grid follows the price:
when the price moves one step above the upper bound, the bot rebuilds the grid around the new price. With initial_market the bot buys the grid position again.
A short grid with trailing follows the price down the same way.
Trailing works with range_type percent, atr and bollinger. It does not apply to neutral and does not work in signal cycles: there the price leaving the range means the end of the cycle.
Grid stop - stop_out_percent and restart_after_stop
If the price moves beyond the lower or upper bound by more than stop_out_percent %, the bot cancels all grid orders and closes the position at market.
restart_after_stop: false- the grid stays stopped until you change its settingsrestart_after_stop: true- the bot immediately builds a new grid around the current price. Does not work withrange_type: fixed
In signal cycles restart_after_stop is not needed: after a stop the grid always waits for the next signal.
Signal start - start
By default (start: immediate) the grid starts right away and runs permanently. It can also be started in cycles on a signal, like the entry in the MRS2 strategy.
| Value | Long signal | Short signal |
immediate | The grid is built right away | - |
deviation | Price is start_deviation_percent % below the moving average | Price is the same % above the average |
bollinger | Price is below the lower Bollinger band | Price is above the upper band |
The moving average for deviation is set by start_ma_type, start_ma_len and start_ma_source. The bands for bollinger - by bb_len, bb_mult and bb_ma_type.
How a cycle goes:
- The bot waits for a signal. Example: the price dropped 5% below the average
- A long grid is built from the signal price with the current range settings. With
initial_marketthe bot buys the grid position - The grid trades until it sells all cells. Usually this means the price came back up through the whole range. A cycle also ends on a stop:
stop_out_percent,options.stop_loss_*oroptions.time_close - The bot cancels the orders and waits for the next signal. A new cycle in the same direction starts only after a new crossing: the price must return above the threshold and drop below it again. So after a stop in a deep decline the grid does not restart right away
For a short everything is mirrored. Which sides are allowed is set by direction: long - only long cycles on a downward signal, short - only short cycles on an upward signal,
both - the signal picks the side.
Signal start works with range_type percent, atr and bollinger. While the grid waits for a signal, the bot status shows the thresholds and the chart shows the signal lines.
If the bot starts with an existing position, the grid continues the cycle in that position's direction.
- Combining
start: bollingerandrange_type: bollinger. At the signal the price is at the edge of the grid, so a long grid withinitial_marketimmediately buys almost all cells and then sells them as the price returns to the upper band. If you want the grid to buy more on a further decline, userange_type: percentoratrwith the signal: then the signal price is in the middle of the grid - With
direction: bothshort cycles also open in a rising market. If the rally continues after an upward signal, the short grid fills up completely. Limit this risk withstop_out_percentor choose one side
Size and risk
The size of one cell equals the regular strategy lot from the basic section: for long and neutral - lot_long or balance_percentage_long,
for short - lot_short or balance_percentage_short, for both - by the side of the current cycle.
The bot calculates the size at the grid build price and keeps it until the next rebuild.
Maximum position = cell size × number of cells. For a new strategy the default cell is 10% of the balance, 20 cells, and the balance used for the calculation is capped at 1,000 (max_balance).
Then one cell is about 100 USDT and a fully filled grid is about 2,000 USDT, i.e. 200% of the balance. On futures this needs leverage of at least 2. On spot the lower buys will fail once the money runs out.
If this risk is too high, reduce balance_percentage_long (5% per cell gives about 100% of the balance for the whole grid) or enable the position limit options.size_control.max_balance_percent.
Initial buy - initial_market. If the start price is in the middle of the range, a long grid has empty levels above the price and nothing to sell there.
With initial_market: true the bot buys at market on start as many cells as there are levels above the price. With the default settings that is about 10 cells, ~1,000 USDT, the whole calculated balance, at once.
For short the bot likewise sells the cells below the price, for neutral it closes the existing position.
With initial_market: false the bot buys nothing on start and counts the existing position as filled cells. Without a position a long grid will only buy on dips and will not profit from a rise.
Filters and common settings
- Position filters (the
filterblock) - ADX, SuperTrend, trend MA, trading time and others - only limit entries for the grid. While a filter forbids long, the grid does not place orders that increase the long. Orders that reduce the position keep working, and the grid calmly closes the cells already filled. When the filter allows entries again, the missing orders appear by themselves. Short works the same way. Aneutralgrid with long forbidden does not build a long below the start price but still buys back its short - While entries are forbidden, the grid is not built, does not start a signal cycle and is not moved by trailing if that requires buying the position at market (
initial_market). The reason is shown in the bot status. Example:filter.adxwithmax: 25keeps the grid working only in a calm market - when ADX rises above 25 and a trend starts, no new cells are filled - Position limit -
options.size_control.max_balance_percent. The grid will not fill more cells than fit into this percentage of the balance, including the initial market buy. For example, a grid of 20 cells at 10% of the balance would fill up to 200%, but with a 50% limit it stops at about 5 cells. Far buys are not placed until the grid sells part of the position - Stop-loss (
options.stop_loss_*) is calculated from the average price of the grid position. If the price moves further than the set percentage, the bot closes the position at market, cancels the orders and stops the grid. The stop-loss is executed at market even ifsl_by_orderis on time_closewithbars_countcloses the position N bars after the grid opened it from zero and also stops the grid. Fills of individual levels do not reset this counttime_closeby day of week or month closes the position on the set day, starting fromtime_of_day. Time is taken from the bar open, so on hourly bars 15:30 triggers from the 16:00 bar. A new grid or new cycle starts on the next day- After a stop by stop-loss or
time_closethe grid behaves the same as afterstop_out_percent: withrestart_after_stop: trueit is rebuilt from the current price, in signal cycles it waits for a new signal, otherwise it stays stopped until the settings change - Take-profit from
optionsis not used by the grid: it takes profit at every level itself
Fees: minimum step
Each cell is two trades, a buy and a sell. The cell profit is roughly the grid step minus two fees. If the step is smaller than two fees, every trade loses money, and the more actively the grid trades, the more it loses. Example: ±8% and 20 cells with geometric spacing give a step of about 0.8%; with a 0.02% maker fee, 0.04% goes to fees and a cell earns ~0.76%. A ±2% range with the same 20 cells gives a step of only 0.2%, and fees already eat a fifth of the profit. Bollinger bands on a short timeframe often give a narrow range: check the step in the bot status after the grid is built.
To pay the maker fee, keep post_only: true. An order that would fill immediately at market is rejected by the exchange, and the bot places it again on the next minute.
Parameters
The grid block in the bot settings, basic.strategy: grid
range_type- how the bounds are set:fixed,percent,atr,bollinger(defaultpercent)lower_price,upper_price- lower and upper bound (fixedonly)range_percent- range width in % from the start price in each direction (percentonly, default 8)atr_len- ATR period on the strategy timeframe (atronly, default 14)atr_mult- range width in ATR in each direction (atronly, default 8)bb_len- Bollinger bands period (forrange_type: bollingerandstart: bollinger, default 20)bb_mult- band width in standard deviations (default 2)bb_ma_type- middle line of the bands (defaultSMA)grid_count- number of cells (default 20). More cells - smaller step and profit per trade, more frequent tradesspacing-geometric(step in %) orarithmetic(step in price), defaultgeometricdirection-long,short,neutralorboth(only with a start signal), defaultlonginitial_market- when building, bring the position to the grid position at market (default on)orders_per_side- how many orders closest to the price to keep on each side (default 10); 0 - all levels. Saves margin and the exchange open-order limitpost_only- place orders as maker only (default on)trailing- move the grid after the price (percent,atr,bollinger; only withstart: immediate, default on)stop_out_percent- how many % the price may go beyond a bound before the stop (default 3); 0 - no stoprestart_after_stop- after the stop, build a new grid from the current price (only withstart: immediate, default on)start- when to start the grid:immediate,deviationorbollinger(defaultimmediate)start_deviation_percent- price deviation from the average for the signal, % (deviationonly, default 5)start_ma_type,start_ma_len,start_ma_source- type, period and price source of the average fordeviation(defaultSMA, 20,close)
Example: a permanent grid (default settings). A new grid strategy is created like this: a ±8% long grid with 20 cells, trailing and a 3% stop with restart.
In basic only long is enabled, a cell is 10% of the balance, and the balance used for the calculation is capped at 1,000 (max_balance).
"grid": {
"range_type": "percent",
"range_percent": 8,
"grid_count": 20,
"spacing": "geometric",
"direction": "long",
"initial_market": true,
"orders_per_side": 10,
"post_only": true,
"trailing": true,
"stop_out_percent": 3,
"restart_after_stop": true,
"start": "immediate"
}
Example: cycles on deviation from the average. A long grid starts when the price drops 5% below SMA 20, and a short grid when the price is 5% above it. For the short, enable use_short in basic.
"grid": {
"range_type": "percent",
"range_percent": 8,
"grid_count": 20,
"spacing": "geometric",
"direction": "both",
"initial_market": true,
"orders_per_side": 10,
"post_only": true,
"stop_out_percent": 3,
"start": "deviation",
"start_deviation_percent": 5,
"start_ma_type": "SMA",
"start_ma_len": 20,
"start_ma_source": "close"
}
Important to know
- Changing the settings rebuilds the grid. If you change the bounds, number of cells, spacing, direction, Bollinger band parameters or start mode, the bot cancels all orders and builds the grid again from the current price. With
initial_market: trueit brings the position to the new grid at market. In signal cycles a grid with an open position continues the cycle in its direction - One symbol - one grid. When building the grid the bot cancels all orders for this symbol on the account
- Position against the direction. If a long grid ends up with a short or vice versa, the grid does not trade and reports in its status that the position must be closed manually
- The trading side is set by
direction, but it must be enabled inbasic.use_longorbasic.use_short, otherwise the grid will not start. Forbothat least one side must be enabled; signals for a disabled side are skipped - Start of a tester run. Until there are enough bars for the average or the bands (
start_ma_lenorbb_len+ 1), the signal is not calculated and the log shows a "not enough bars" warning - Other exits from
options(trailing stop, MA exit and similar) are designed for single-entry strategies. Better not to enable them with the grid
Before running on a real account, test your parameters in the tester over several periods, including declines.
Backtest the strategy on historical data in the tester and run it in hamster-bot.
Need this strategy adjusted or have your own logic? Custom trading bot development.