Cup handle setup event
Marks the first cup-and-handle setup in the loaded history, then never marks again in that run.
This is the setup stage of a cup and handle, run as a five-state machine over the highest and lowest closes of the last 100 bars. It moves from Idle to RimL when the close sits within rim_eps of the 100-bar high, to Base when it sits within base_eps of the 100-bar low, and back to RimR when it returns near the high. From RimR it enters Handle once a channel (both lines sloping the same way, nearly in step) or a triangle (support rising, resistance falling) holds for handle_hold bars in a row, with slopes measured over 20 bars. Handle has no exit, so the state stays there for the rest of the run.
How to read it
- The marker sits on the candle that completes the handle_hold-bar run, after a rim, a base and a return to the rim.
- At defaults the September 2026 SPY sample (20,160 one-minute bars) shows one marker, at bar 243, and none after it.
- Read it as one early flag for the whole loaded history. Silence after the marker is the code's behavior, not a quiet market.
What it outputs
- Cup-handle setup
- Marks the bar that completes a handle: a channel or triangle held for handle_hold bars after a rim, a base and a return to the rim. Fires at most once per run.
When it fires
Fires on the bar that completes handle_hold bars in a row of a channel or triangle, after a rim, a base and a return to the rim. It marks a handle forming, not a breakout, and the state never clears, so it does not fire again in the same run.
Settings
- rim_eps
- How close the close must sit to the 100-bar high, as a fraction (0.004 is 0.4%). Tightening to 0.2% moves the marker to bar 249 and exact touches to bar 418; widening to 2% leaves it at bar 243. Negative values never match, so nothing fires.
- base_eps
- The same test against the 100-bar low, for the base after the first rim. Exact touches move the marker to bar 264; 0.2% and 2% both leave it at bar 243.
- handle_hold
- Bars in a row the channel or triangle must hold before the handle is reached. Shorter fires sooner: 3 bars moves the marker to bar 240. Longer delays it: 20 bars gives bar 257, 50 bars gives bar 4874, and 100 bars leaves no marker.
Pitfalls
- Fires once per run: Handle has no exit, so later setups never mark. cup_handle_buy_sell has an exit back to Idle, so the two versions disagree.
- Rare at defaults: one marker in the September 2026 SPY sample. Parameters move that marker earlier or later, but no tested setting added a second one.
- The 100-bar high and low use closes, though the trend helper's docstring says highs and lows. A negative rim_eps or base_eps never fires, though the slider allows it.