Cup and Handle Quality [AGPro Series]Cup and Handle Quality
🧩 OVERVIEW
Cup and Handle Quality is a visual pattern-quality overlay for one of the most recognized continuation structures in technical analysis: the cup and handle.
The script is designed to map the full pattern lifecycle instead of only marking a breakout candle. It studies the left cup rim, the cup base, the right rim recovery, the controlled handle pullback, the breakout behavior, and the measured projection context. The goal is to make cup and handle structures easier to recognize, compare, and explain directly on the chart.
The final visual output is intentionally clear. The detected cup and handle candle ranges are framed with subtle boxes, while thick curved outlines make the formation readable at a glance. The rim line, target line, DEPTH arrow, and MOVE arrow help users understand how the structure is measured, not just where the label appears.
✅ WHAT MAKES IT DIFFERENT
Most public cup and handle tools focus on one of two things: either they draw a simple breakout marker, or they scan aggressively and leave the chart crowded with low-context shapes. Cup and Handle Quality takes a narrower approach.
It combines three layers:
- Structure recognition: left rim, cup base, right rim, and handle low
- Quality scoring: cup symmetry, handle depth, and breakout quality
- Visual education: cup box, handle box, thick pattern outline, rim line, target line, and measurement arrows
This makes the script more than a pattern detector. It is also a visual explanation tool. The chart shows where the cup was detected, where the handle formed, how deep the cup is, and where the measured projection line comes from.
🧭 WHY THIS DOES NOT OVERLAP WITH OTHER AGPRO TOOLS
This script has its own lane inside the AGPro Series.
It is not a flag scanner, wedge detector, triangle breakout module, inside-bar breakout tool, Donchian breakout validator, double-top detector, head-and-shoulders detector, generic support-resistance map, or supply-demand zone script.
Its lane is specifically:
Cup rim recovery -> controlled handle depth -> breakout participation -> measured projection line.
The script focuses on the complete cup and handle lifecycle. It does not try to replace broader breakout engines, market-structure tools, support-resistance tools, liquidity tools, or trend dashboards. The defining feature is the combination of a recognizable cup-and-handle drawing with a quality panel that grades the actual pattern components.
⚙️ METHODOLOGY
The engine builds the pattern from pivot structure. A qualified setup begins with a left rim, moves into a cup low, recovers into a right rim, and then forms a handle pullback after the right rim.
The quality model evaluates:
1. Cup Symmetry
The script compares the two rim areas and measures how balanced the cup is over time. A cleaner return from the cup base into the right rim area produces a stronger symmetry reading.
2. Handle Depth
The handle is measured as a percentage of cup depth. A useful handle should create structure without pulling so deeply that the cup profile loses strength. The input range allows the user to control how strict or flexible the handle requirement should be.
3. Breakout Quality
Breakout quality is calculated from candle behavior and participation context. The script checks distance beyond the rim, candle body efficiency, close location, and relative volume against a configurable baseline.
4. Final Score
The final score combines the structure score and breakout behavior into a compact quality reading. Developing setups can be shown before breakout confirmation, while confirmed breakouts require the breakout quality gate.
📊 PANEL
The AGPro panel displays the main quality dimensions in a compact format:
- Cup Symmetry
- Handle Depth
- Breakout Quality
- Score
The first row follows the AGPro standard with a merged blue title row. Panel location, panel theme, panel font size, and label font size are adjustable from settings.
🎛️ KEY INPUTS
- Pivot Span controls structural sensitivity.
- Minimum Cup Bars defines the shortest accepted cup duration.
- Maximum Cup Bars defines the longest accepted cup duration.
- Maximum Rim Variance % controls how closely the left and right rims must align.
- Minimum Cup Depth ATR filters shallow structures.
- Minimum Handle Depth % filters handles that are too shallow.
- Maximum Handle Depth % filters handles that are too deep.
- Breakout Volume Baseline controls the relative volume comparison.
- Minimum Setup Score controls developing setup visibility.
- Minimum Breakout Quality controls confirmed breakout strictness.
- Minimum Pattern Score controls the final quality gate.
- Show Developing Setup controls pre-breakout visualization.
- Show Cup Path controls the curved cup drawing and cup candle box.
- Show Handle Box controls the detected handle range.
- Show Target Line controls the measured projection line.
- Show Measurement Arrows controls the DEPTH and MOVE explanation arrows.
- Pattern Stroke Width controls the thickness of the cup and handle outlines.
- Target Projection Bars controls how far the measured target line extends.
🔍 HOW TO READ IT
Start with the rim line. This is the reference level the structure must recover into and eventually move beyond.
Then read the cup. The subtle cup box marks the detected candle range, while the thick curved outline helps the formation read visually as a cup instead of a simple V-shaped swing.
Next read the handle. The handle box marks the controlled pullback area after the right rim. The curved handle outline makes the handle easier to recognize without turning it into a generic rectangle pattern.
The DEPTH arrow shows the measured cup depth. The MOVE arrow transfers that depth upward from the rim area. The TARGET line shows the forward measured projection level.
The panel summarizes the same structure numerically. Stronger Cup Symmetry, disciplined Handle Depth, and stronger Breakout Quality combine into the final Score.
🧩 BEST USE CASES
Cup and Handle Quality is best used on liquid symbols and timeframes where swing structure has enough room to develop. It is especially useful for users who want a clean visual map of a classic continuation pattern without filling the chart with unrelated pattern families.
The default settings are tuned for active discovery. Users who want fewer patterns can raise pivot sensitivity or score thresholds. Users who want a more reactive view can lower the score thresholds, while still using the chart visuals to review pattern quality.
🧠 VISUAL DESIGN PHILOSOPHY
The design philosophy is simple: make the pattern understandable without making the chart noisy.
The cup and handle are drawn with thick curved lines because this pattern is visual by nature. Newer users should be able to see the shape immediately. At the same time, the candle boxes keep the drawing grounded in the actual detected structure.
The target is shown as a line rather than a large zone, keeping the projection clean. The DEPTH and MOVE arrows explain the measurement logic without turning the indicator into a crowded education panel. Labels are compact, and the panel is restrained so the chart remains the main focus.
🔔 ALERTS
The script includes an alert condition for confirmed cup and handle breakouts.
Alert name:
Cup and Handle Quality Breakout
Alert message:
Cup and Handle Quality : high-quality cup and handle breakout confirmed on {{ticker}} at {{close}}.
Alerts are tied to confirmed breakout logic, which means the structure, breakout quality, and pattern score must pass the configured gates.
🔹 LIMITATIONS AND TRANSPARENCY
Cup and handle structures are pattern-based and depend on pivot interpretation. Different sensitivity settings can produce different structures on the same chart.
Very noisy markets, illiquid symbols, extreme gaps, and unusually compressed price action can reduce pattern readability. Lower thresholds may produce more setups, but visual review remains important when using any chart-pattern tool.
The thick cup and handle lines are designed as visual guides. The subtle candle boxes identify the detected structure ranges, while the curved outlines make the pattern easier to understand on the chart.
✅ IDEAL USER
This script is built for traders and analysts who want a clean, visual, and structured way to study cup and handle formations.
It is especially useful for:
- Users who want classic chart patterns with a modern quality layer
- Price-action traders who care about structure, handle depth, and breakout behavior
- Chart reviewers who want a clear visual explanation of the setup
- Newer users who benefit from seeing the cup, handle, depth, move, and target drawn directly on the chart
- AGPro users who want a focused cup-and-handle tool that does not overlap with broader breakout or market-structure scripts
Pine Script® indicator


