A ladder of orders that harvests the chop.
A grid doesn't predict anything. It lays buys below and sells above, and every time price crosses a rung it banks the step and re-arms the other side. It's a genuinely good tool in a ranging market, and a genuinely bad one in a trend, so we build it with the bounds and the kill switch that keep the bad case survivable.
The grid, in real code.
No black box. The whole thing is a short, readable file: a band it works inside, a step between rungs, a size, and a cap. The two rules that matter are re-arm on a fill and halt when price leaves the band.
1# grid.py — a bounded grid that harvests a ranging market2from burneh.grid import Grid, Order34class ChopHarvester(Grid):5 band = (138, 162) # only operate inside this range6 step = 3 # one rung every $37 size = 8 # lots per rung8 cap = 6 # never hold more than 6 rungs on one side910 def build(self):11 # lay resting buys below mid and sells above, one every step12 for level in self.rungs(*self.band, self.step):13 side = "buy" if level < self.mid else "sell"14 self.rest(Order(side, level, self.size))1516 def on_fill(self, fill):17 # a fill banks the step and re-arms the other side, one rung away18 if self.inventory >= self.cap:19 return self.pause("max inventory — not adding into the move")20 self.rest(Order.flip(fill, by=self.step))2122 def on_leave_band(self, price):23 # price left the range: the bad case. halt, do not average in.24 self.cancel_all()25 self.halt(f"left the band at {price}")It re-arms as it fills.
Buys rest below the price, sells above. Each time it crosses a rung the order fills, banks the step, and immediately arms the opposite side one rung away. In a market that keeps crossing back and forth, that step gets banked over and over.
The same grid, in two markets.
In a range it does exactly what it's sold to do. In a trend the very same grid stacks losing inventory, until the bound we build in stops it. Switch the market and watch the P&L flip.
harvesting the chop
Anyone selling a grid as a set-and-forget money printer is selling you only the good half of that sentence.
The bounds are the point.
The danger in a grid is unbounded accumulation into a trend, exactly what you just watched. So every grid we build ships with the brakes on.
It only operates inside a band you set. Price leaves, it stops adding risk.
A hard cap on how much it can hold on one side before it stops buying deeper.
One command halts the grid and cancels every resting order at once.
A grid is a tool for one kind of market, not a forecast for all of them.
When price ranges, a grid is a genuinely good way to earn the back-and-forth. When it trends, the same grid leans the wrong way and bleeds. We don't pretend to know which market you'll get. What we can build is the version that harvests the good one and survives the bad one, because the bounds and the kill switch are in from the first line, not bolted on after a loss.
A ladder of orders that harvests the chop.
It re-arms as it fills, profits in a range and is honest about the trend, and ships bounded with a max-inventory cap and a kill switch.