Skip to content
All library documents

A Grid Strategy That Adds to Losing Positions and Uses a Size Cap

Code Quant course library

Summary

This strategy starts by placing buy and sell limit orders around the best bid, then follows whichever side fills. After a fill, it cancels opposing and profit-taking orders and adds another same-direction order at a wider, position-dependent grid interval. As exposure grows, the interval steps increase. The code also places a profit-taking order one grid step beyond the calculated average price, adjusted against the current quote, and caps accumulation at a configured position threshold.

At the maximum position, the strategy checks for adverse price movement relative to average entry and submits a marketable exit, then pauses new rounds for a configured interval. A timer replenishes missing orders and periodically cancels stop orders. These mechanics illustrate averaging into a move and managing orders, but the document presents code only: it offers no backtest, profitability evidence, execution-cost model, or robust analysis of partial fills, fees, and fast-market risk. The widening exposure makes its loss and margin risks material.

Key ideas

  • The strategy begins with buy and sell orders placed around the best bid.
  • After one side fills, it cancels opposing orders and adds exposure in the same direction.
  • The spacing between additional orders increases as position size grows.
  • Profit-taking targets are based on average entry price and adjusted using the current quote.
  • A position cap triggers an adverse-move exit and a timed pause before trading resumes.

Tags

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