Logo hamster-bot Claude new: MCP Hyperliquid new: Hyperliquid 1 852 of us in the chat
RU EN PT
Loading…

← All strategies

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.

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

ValueGrid boundsWhen it fits
fixedSet manually: lower_price and upper_priceYou know the corridor the price moves in
percent± range_percent % from the start priceThe universal default
atr± atr_mult × ATR from the start priceThe grid width adapts to the current volatility
bollingerBetween the Bollinger bands (bb_len, bb_mult) at build timeThe 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

ValueHoldsHow it works
longLongBuys below the price, sells above. The classic spot grid: accumulates the coin on the way down and sells it on the way up
shortShortMirrored: sells above the price, buys back below. Builds a short as the price rises
neutralLong or shortNo position at the start price. Builds a long below it and a short above it. Futures only and only without a start signal
bothLong or shortOnly for signal start (start): the signal picks the side of each cycle

On spot only the long direction is available.

Level spacing - spacing

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.

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.

ValueLong signalShort signal
immediateThe grid is built right away-
deviationPrice is start_deviation_percent % below the moving averagePrice is the same % above the average
bollingerPrice is below the lower Bollinger bandPrice 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:

  1. The bot waits for a signal. Example: the price dropped 5% below the average
  2. A long grid is built from the signal price with the current range settings. With initial_market the bot buys the grid position
  3. 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_* or options.time_close
  4. 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.

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

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

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

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.