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.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.