Grid Trading Bot: Calculate the Levels and the Remaining Exposure

A grid trading bot places orders at defined levels and attempts to capture repeated price movements. Completed buy/sell cycles can earn gross gains while the remaining inventory loses more. Evaluate total equity and all open exposure, not only the counter labeled grid profit. A grid still depends on the price path, available capital and execution.

Key Takeaways

  • Distinguish price levels from the intervals between them.
  • Arithmetic spacing is a constant price difference; geometric spacing is a constant ratio.
  • Neither spacing method guarantees constant risk or automatically moves the range.
  • Include open inventory, fees and failed orders when evaluating results.

Define arithmetic and geometric levels precisely

With lower bound L, upper bound U and n intervals, an arithmetic grid uses spacing (U − L) / n and has n + 1 boundary levels. For a hypothetical range 90 to 110 with four intervals, the levels are 90, 95, 100, 105 and 110. A geometric grid uses ratio (U / L) raised to 1/n for positive bounds. From 100 to 121 with two intervals, that gives 100, 110 and 121, each 10% above the previous level.

  • Say whether “10 grids” means ten intervals or ten levels; platform conventions can differ.
  • Define quantity per level separately: equal units and equal cash create different exposure.
  • Re-centering the range is an additional rule, not an automatic property of a geometric grid.
  • Equal percentage spacing does not make cash risk constant.

Specify the order lifecycle and funding

A grid needs more than a list of prices. Define which orders are active initially, what happens after each partial or full fill, and when replacement orders are allowed. A spot sell ordinarily reduces owned inventory; a margin or derivative sell can have different position effects. Do not assume every upper-level sell opens a short.

  • Track each level’s active entry, filled quantity, exit order and completed state.
  • Set maximum aggregate inventory and reserved funds, not only per-order size.
  • Check price and quantity rounding and minimum order value.
  • Define behavior outside the range: stop new orders, cancel pending orders, hold or exit according to an explicit rule.

Calculate net cycle P&L and remaining inventory

For an illustrative one-unit buy at 100 and sell at 101, gross profit is 1. With a hypothetical 0.1% fee on each side, charges are 0.100 and 0.101, leaving 0.799 before other costs. An order that never fills contributes no completed-cycle gain. Narrower spacing can make fees a larger fraction of the gross difference.

  • Separately mark open inventory to market. Three units bought at 100, 95 and 90 cost 285; at price 80 they are worth 240, an unrealized loss of 45 before costs.
  • If other completed cycles earned 10, total trading P&L in that simplified example is still −35 before remaining costs.
  • Include funding or borrowing where applicable. A positive completed-cycle report alone is insufficient.

Test the price path and operational states

Historical bars do not necessarily reveal the sequence of intrabar touches at multiple levels. Check the simulator’s order assumptions and lower-timeframe fill facilities where applicable. Test a monotonic decline, a rally beyond the upper bound, a gap and repeated oscillations. None is a promise about the next market regime.

  • Check whether several levels can fill during one bar and whether replacements were active before a later touch.
  • Test partial fills, duplicate notifications and a restart without placing every order twice.
  • For leverage, inspect liquidation and margin behavior in addition to a planned stop; stop prices are not guaranteed.

Build the specification with Pineify

Pineify can draft code for the chosen platform from explicit grid rules. Inspect order identifiers, accumulated positions, exit allocation and fill timing in the generated source. TradingView research uses its broker emulator; a live grid requires a compatible execution system. Strategy Optimizer varies exposed inputs with Advanced or above access, while Backtest Deep Report analyzes compatible trade CSV files.

  • Do not assume a closed-trade CSV captures all unfinished grid inventory.
  • Changing spacing in a grid search does not prove an optimal future range.
  • Hummingbot’s documented Grid Executor is a separate implementation example with order states and realized/unrealized P&L tracking, not a Pineify feature.

Educational guidance, not investment advice or a record of tested performance. Automated systems can submit unintended orders and lose money. Simulated results do not guarantee live execution or future returns.

Frequently Asked Questions