Skip to content
All library documents

Spot Grid Trading with Profit Targets and Position Stops

Code Quant course library

Summary

This spot grid strategy places paired buy and sell orders around the market, then rebuilds the grid after a fill using the filled order price and current bid and ask. Grid spacing and order size are configurable. A position calculator tracks net exposure and average entry price, while active order lists support cancellation and replacement as the grid changes. The code also includes a profit-taking rule: once one-sided exposure reaches a configured count of grid units, it submits an order intended to close that exposure at a target offset from the average price.

A separate stop mechanism checks exposure periodically. At the configured maximum position, it compares the market with either the last fill or average price and submits a closing order after a specified adverse move. When a stop fully closes the position, the strategy pauses grid placement for a configured interval. These are implementation rules, not evidence of profitability: the document provides no backtest or live results. Grid accumulation can build substantial directional exposure, and realized performance depends on fills, fees, liquidity, and market conditions.

Key ideas

  • The strategy maintains buy and sell grid orders around the market and resets them after fills.
  • A position calculator tracks net exposure and average price as orders update.
  • When one-sided exposure crosses a configured threshold, the strategy submits a profit-taking order.
  • At maximum exposure, a periodic check can submit a stop order after an adverse price move.
  • After a stop closes the position, grid trading is paused for a configured period.
  • The document provides implementation logic but no performance testing or results.

Tags

From a private course collection; the original is not published.