Loading…

Cup And Handle Scanner

A cup and handle is easy to describe in words and genuinely hard to define in code, because "rounded, not V-shaped" is a shape judgement, not a single number. This indicator pairs a swing high (the left lip) with a later swing high near the same price (the right lip, within a tolerance band) and requires the low point between them to clear several concrete tests rather than just "looks like a bowl": the bottom's depth relative to the lips must fall inside a configured range; the bottom itself must sit away from both lips, not hugging either edge, so both a real decline and a real recovery exist; and a minimum number of bars between the lips must have their low within a band of the bottom price - the roundedness check, which is what actually distinguishes a shallow bowl from a sharp V-spike that happens to have the right depth and duration. Once a cup validates, the right lip becomes the handle's ceiling. The indicator tracks the running lowest low reached after the right lip bar by bar: if that pullback ever exceeds a configured fraction of the cup's own depth, or runs on longer than the maximum handle duration, the setup is dropped and scanning starts fresh. A close back above the right lip, after the minimum handle duration has passed, is the breakout - it draws a dashed target line at the breakout price plus the cup's own depth, the standard published measured-move target for this pattern, and fires an alert. Being honest about the hardest part: roundedness here is a bar-count threshold against a price band around the bottom, not a curve fit or any kind of shape-matching algorithm. It reliably rejects a single-bar V-spike and accepts a base that genuinely spends time near its low, but it does not score how "rounded" a passing cup looks beyond that one threshold - two cups that both clear InpMinBaseWidthBars can still look quite different by eye. Only one candidate cup is tracked at a time (the nearest lip pairing that passes every check), so nested or overlapping candidate cups on the same stretch of chart are not all evaluated - the scanner takes the first valid one and moves on. Notes and limitations - Roundedness is a bar-count-in-band threshold, not a curve fit; see the full description above for exactly what it does and does not guarantee. - Only one candidate cup is tracked at a time; a second, independently valid cup forming elsewhere on the chart while one is already pending is not evaluated until the first resolves or expires. - The right-lip price is used as the handle's breakout trigger level directly - no separate handle-high is tracked if the handle's own high during the pullback is meaningfully below the right lip. - Depth, duration and retrace thresholds are read from configurable inputs with no built-in defaults claimed to be "the" correct textbook cup and handle - published descriptions vary, and these defaults are a reasonable starting point to tune per instrument and timeframe. - This is a structure-identification tool, not a trade signal; the breakout is reported as a shape completing, not as a recommendation.

Indicator · MT4 · v1.0 · Free

About Cup And Handle Scanner

Cup And Handle Scanner is an indicator for MetaTrader 4. It draws buy and sell arrows on the chart and can alert you with a pop-up, sound, email or push message. It has 12 settings, such as Swing bars, Min cup bars and Max cup bars. MQL source code included.

Files in the download: CupAndHandleScanner.ex4, CupAndHandleScanner.mq4, CupAndHandleScanner.txt.

Settings

SettingDefaultWhat it does
Swing bars5Bars each side required to confirm a swing
Min cup bars20Minimum bars from left lip to right lip
Max cup bars150Maximum bars from left lip to right lip
Min depth percent0.12Minimum cup depth as a fraction of the left lip price
Max depth percent0.50Maximum cup depth as a fraction of the left lip price
Lip tolerance percent0.04Max right-lip deviation from the left lip's price
Roundness band percent0.15Band around the bottom counted as "near the base"
Min base width bars6Minimum bars required inside the roundedness band
Max handle retrace percent0.5Max handle pullback as a fraction of cup depth
Min handle bars4Minimum bars the handle must consolidate
Max handle bars45Maximum bars allowed before the handle expires
AlertstrueAlert once on breakout

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: Breakout · Dashboards & Scanners · Buy/Sell Arrows · Alerts · MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria