OPEN-SOURCE SCRIPT

P3 Candle Grouping

339
P3 Candle Grouping — draws boxes around candles that trade within a shared range, making consolidation and balance visible at a glance.

A group holds as long as price stays inside the box's high/low. Wicks poking beyond the edge don't break the group — the boundary ratchets out to include them. A group ends only when a candle closes past the boundary by a set tick buffer (default 2 ticks), and that breakout bar seeds the next group. Both the upper and lower boundaries ratchet independently, and the logic runs on confirmed bars only, so boxes don't repaint.

Teal boxes closed bullish, maroon closed bearish, and the yellow box is the current group still forming live.

Settings:

Close must clear boundary by N ticks — how far past the edge a candle must close to end a group. Higher values give fewer, cleaner groups.
Keep last N group boxes — how many completed boxes remain on the chart.

Works on any symbol or timeframe; built with NQ/MNQ in mind. Source is open — feel free to study or build on the grouping logic.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.