Gann Box in Pine Script
A price range divided into eighths, with the 1/2 line as its centre, and the period after it divided in time, so a week or a day gets a fixed map of levels drawn before price reaches them.
Definition
A Gann box takes one price range, divides it into fixed fractions and lays those fractions across a stretch of time. The range is the height of the box: a prior week's high and low, a prior day's, or the high and low of a short opening window. The fractions are eighths, so the lines sit at 1/8, 1/4, 3/8, 1/2, 5/8, 3/4 and 7/8 of the range. It belongs to the ratio-level family, next to Fibonacci retracements, but its ratios are simple fractions rather than powers of the golden ratio.
The reason the levels matter is that they are drawn from a range the whole market saw. Last week's high and low are the edges every participant watched, and the halfway point of that range is where the two sides met in the middle. Traders who use the box treat the 1/2 line as the balance of the prior period. Above it, the market is trading in the upper half of what it accepted. Below it, the lower half. The 3/8 and 5/8 lines frame the centre, and the edges mark where the old range ends.
The divisions come from W. D. Gann, a trader and writer of the first half of the 20th century, who split ranges into eighths and thirds and held the 50 percent point to be the most important. He also divided time the same way as price, so that a level and a moment in time could be read together. The standard settings today are eighths in price, quarters in time, and the prior period's high and low as the range. Some traders swap in Fibonacci ratios, which changes the inner lines but keeps the 1/2 line.
On the chart, expect a ladder of horizontal lines that stays fixed for the whole period, with the 1/2 line drawn stronger than the rest. Price spends most of a week inside or near the prior week's range, so it touches several lines and often pauses or turns at the 3/8, 1/2 and 5/8 lines. When price leaves the box, the same spacing projects above and below in quarters of the range. A new box appears at the start of each period, built from the range that just closed.
Reading the chart
Reading a Gann box starts with the range it divides, because every line is a fraction of that range.
- Choose the range. For a weekly box take the prior week's high and low. For a daily box take the prior day's. A short window, such as the first hour of the week, gives a small box that needs its projections.
- Draw the eighths across the coming period. The 0 and 1 lines are the range's low and high, the 1/2 line is the midpoint, and the 1/4 and 3/4 lines split each half again.
- Note where the period opens. An open above the 1/2 line puts the market in the upper half of last period's range, an open below puts it in the lower half, and the first test of the 1/2 line is the first decision.
- Mark the zone you plan to trade, usually two adjacent lines such as 3/8 to 1/2. A zone gives price room to wick into a level without the read flipping on a single tick.
- Watch for rejections. A candle that comes down into the zone and closes back above it is a long rejection; one that comes up into it and closes back below is a short rejection. Closes through the zone end the read.
- Check the time divisions. The quarter lines of the period, such as midweek, are where a test is most likely to resolve. A rejection late on the final day has little time left to work.
The maths
Every level is the range's low plus a fixed fraction of the range, and every time division is the period's start plus a fixed fraction of its length.
The short rejection mirrors the long: the open is below the zone's lower edge, the high reaches it, and the close is back below it. Its stop sits above the zone and its target below.
A fake breakout variant reads the rejection the other way: price pokes through the zone's far edge and closes back inside. Both are rejections; they differ in which side of the zone price came from.
Thirds replace the eighths with 1/3 and 2/3 and keep the 1/2 line. Fibonacci variants replace the inner lines with 0.382 and 0.618.
The box is fixed for its period. Nothing is recalculated while the week trades, which is what makes it a map drawn in advance rather than an indicator that follows price.
Inputs that matter
| Input | Typical | What changing it does |
|---|---|---|
| Box from | the prior week's range | The single biggest choice. A prior week's range gives wide, well-watched levels; a first-hour range gives a small box whose projections do the work. |
| Divisions | eighths | Eighths give the most lines and the 3/8 and 5/8 framing of the centre. Quarters are cleaner on busy charts. Thirds suit traders who read the range in three parts. |
| Zone | 3/8 to 1/2 | Which pair of lines is traded. Zones next to the 1/2 line see the most tests; zones near the edges see fewer but larger reactions. |
| Target and stop in eighths | 2 and 1 | The reward and risk in units of the box. Larger targets need the move to carry through more levels and are reached less often. |
| Projection | one range above and below | Keeps lines on the chart when price leaves the box, which matters most for small boxes built from an opening window. |
In practice
- As a weekly map: draw the box from the prior week's range on a 1-hour chart and read the week from the 1/2 line, upper half bias above it and lower half bias below it.
- As a zone to trade: pick two adjacent lines, such as 3/8 to 1/2, and take the rejections, long when price comes down and closes back above, short when it comes up and closes back below.
- As a target ladder: after an entry at one level, the next lines are natural places to take profit, so a target of 2 eighths is the second line past the zone.
- As a stop placement: a stop one eighth past the far side of the zone gives the trade the whole zone plus a line of room, and a close beyond it ends the idea.
- As a timing frame: the quarter lines of the week, roughly each day and a half, are when tests tend to resolve, and a setup late on the last day has little room left.
- As confluence: where a box line sits on a prior day's high, a pivot level or a round number, the overlap is a stronger reference than the line alone.
Where it goes wrong
- Building the box from a single short candle and trading only its inner lines. Use a range the market watched, or turn the projections on so the lines reach where price trades.
- Treating every touch as a trade. Wait for the close back away from the zone, because a touch that closes through the line is acceptance, not rejection.
- Holding a box trade over the weekend or into the next period. The box describes one period, so close before it ends and start again from the new range.
- Setting targets far beyond the zone in the hope of a high reward to risk. Measure how far rejections usually run before they give the move back, and set the target inside that distance.
Compared with
Fibonacci retracement. Both divide a range into ratios. A retracement is drawn on the last swing and uses 0.382, 0.5 and 0.618; a Gann box is drawn on a fixed period's range and uses simple eighths, with a time axis that a retracement does not have.
Pivot points. Pivots compute a central level and support and resistance from the prior period's high, low and close by formula. A Gann box keeps the prior range itself and splits it evenly, so its lines are fractions of what happened rather than projections from the close.
Previous day high and low. The prior day's high and low are the 0 and 1 lines of a daily Gann box. The box adds the lines in between, so a level halfway or three eighths into yesterday's range becomes a reference too.
Opening range. An opening range trades the break of the first window's high and low. A Gann box built from the first hour divides that same window into eighths and projects it, and trades rejections of the lines rather than the breakout.
Build it in Quant
Type one of these in the Quant desk, or click it. A request that fits a checked template is assembled on the spot without a credit; anything beyond the blanks goes to the copilot, which edits on top of the checked script.
Questions
What is the most important line in a Gann box?
The 1/2 line. It is the midpoint of the range the box divides, the price where the prior period was balanced between its high and low. Traders read the week from it: above it the market is in the upper half of the range it accepted, below it in the lower half. The 3/8 and 5/8 lines either side of it frame the centre and see the most tests.
Why eighths and not Fibonacci ratios?
Eighths are the original divisions, and they include the quarters and the half, so the most watched fractions are all on the chart. Fibonacci ratios put the inner lines at 0.382 and 0.618 instead of 3/8 and 5/8, which is close but not the same. Neither is more correct; what matters is using one scheme consistently so your tests and your trades read the same lines.
Which range should the box be built from?
For a weekly box on 1-hour bars, the prior week's high and low is the standard, because every participant saw that range. A first-hour box is much smaller, so its inner lines sit close together and its projections carry the trades. A daily box from the prior day's range suits 5-minute to 15-minute charts. Test the choice, since the range sets every line.
What counts as a rejection of a Gann box level?
A candle that reaches the zone and closes back on the side it came from. For a long, the candle opens above the zone, its low reaches the zone's upper line, and it closes back above it. For a short, the mirror from below. A close inside or through the zone is not a rejection; it shows the level being accepted.
How far should a Gann box target be?
Measure it. For each rejection, record how far price ran in its favour before trading back to the entry price. The median of those runs is the distance the setup usually offers. A target well beyond it is reached rarely, however good the reward to risk looks. In eighths, targets of 1 to 3 lines past the zone are where most reactions end.
Do the time divisions matter?
They are a guide rather than a trigger. Dividing the week into quarters marks roughly every day and a half, and tests of a level often resolve near those points. They are most useful as a filter: a clean rejection early in the week has time to reach its target, while one in the last hours before the close has to be closed before it can work.