OPEN-SOURCE SCRIPT
P3 Candle Grouping

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.
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.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.