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 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
Order type used: Limit (maker only by default). Market - initial buy and grid stop.
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.
⚠️ 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.
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 |
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 |
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. A short grid with trailing follows the price down the same way.
Works only with range_type percent and atr and does not apply to neutral.
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. Only forrange_typepercentandatr
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. The bot calculates the size at the start price and keeps it until the next grid rebuild.
Maximum position = cell size × number of cells. Example: balance 1,000 USDT, balance_percentage_long: 4, grid_count: 20 -
one cell is about 40 USDT, a fully filled grid is about 800 USDT, i.e. 80% of the balance. Keep this in mind when choosing the percentage and leverage.
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 (in the example above - about 10 cells, ~400 USDT 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.
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: ±10% and 20 cells with geometric spacing give a step of about 1%; with a 0.02% maker fee, 0.04% goes to fees and a cell earns ~0.96%. A ±2% range with the same 20 cells gives a step of only 0.2%, and fees already eat a fifth of the profit.
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(defaultpercent)lower_price,upper_price- lower and upper bound (fixedonly)range_percent- range width in % from the start price in each direction (percentonly, default 10)atr_len- ATR period on the strategy timeframe (atronly, default 14)atr_mult- range width in ATR in each direction (atronly, default 8)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,shortorneutral(defaultlong)initial_market- on start, 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 (percentandatronly, default off)stop_out_percent- how many % the price may go beyond a bound before the stop (default 0 - no stop)restart_after_stop- after the stop, build a new grid from the current price (default off)
Example block for a ±8% long grid with 20 cells:
"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": false,
"stop_out_percent": 0,
"restart_after_stop": false
}
Important to know
- Changing the settings rebuilds the grid. If you change the bounds, number of cells, spacing or direction, 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 - 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 common take-profit and stop-loss from the
optionsblock should stay off (0): the grid takes profit at every level itself, andstop_out_percentprotects against a trend - Position filters (the
filterblock) do not apply to the grid: the trading side is set bydirection. The needed side must still be enabled inbasic.use_longorbasic.use_short
Backtest the strategy on historical data in the tester and run it in hamster-bot.