OPEN-SOURCE SCRIPT
Quasimodo (QML) Pattern [Kodexius]

Quasimodo (QML) Pattern is a market structure indicator that automatically detects Bullish and Bearish Quasimodo formations using confirmed swing pivots, then visualizes the full structure directly on the chart. The script focuses on the classic liquidity-grab narrative of the QML: a sweep beyond a prior swing (the Head) followed by a decisive market structure break (MSB), leaving behind a clearly defined reaction zone between the Left Shoulder and the Head.
Detection is built on pivot highs and lows, so patterns are evaluated only after swing points are validated. Once a valid 4 pivot sequence is identified, the indicator draws the pattern legs, highlights the internal triangle area to emphasize the grab, marks the MSB leg, and projects a QML zone that can be used as a potential area of interest for retests.
This tool is designed for traders who work with structure, liquidity concepts, and reversal/continuation triggers, and who want a clean, repeatable QML visualization without manually marking swings.

🔹 Features
🔸 Confirmed Pivot Based Structure Mapping
The script uses classic built-in pivot logic to detect swing highs and swing lows.
🔸 Automatic Bullish and Bearish QML Detection
The indicator evaluates the most recent 4 pivots and checks for a valid alternating sequence (High-Low-High-Low or Low-High-Low-High). When the sequence matches QML requirements, the script classifies the setup as bullish or bearish:

Bullish logic (structure reversal up):
- Left Shoulder is a pivot Low
- Head is a lower Low than the Left Shoulder (liquidity sweep)
- MSB pivot exceeds the Reaction pivot

Bearish logic (structure reversal down):
- Left Shoulder is a pivot High
- Head is a higher High than the Left Shoulder (liquidity sweep)
- MSB pivot breaks below the Reaction pivot

🔸 Full Pattern Visualization (Legs + Highlighted Core)
When a pattern triggers, the script draws:
Three main legs: Left Shoulder to Reaction, Reaction to Head, Head to MSB
A shaded triangular highlight over the internal structure to make the liquidity-grab shape easy to spot at a glance
🔸 QML Zone Projection
A QML Zone box is drawn using the price range defined between the Left Shoulder and the Head, then extended to the right to remain visible as price develops. This zone is intended to act as a practical reference area for potential retests and reaction planning after MSB confirmation.
🔸 MSB Emphasis
A dotted MSB line is drawn between the Reaction point and the MSB point to visually emphasize the confirmation leg that completes the pattern logic.
🔸 Clean Point Tagging and Directional Labeling
Key points are labeled directly on the chart:
- “LS” at the Left Shoulder
- “Head” at the sweep pivot
- “MSB” at the break pivot
A directional label (“Bullish QML” or “Bearish QML”) is also printed to quickly identify the detected bias.
🔸 Configurable Visual Style
All main visual components are user configurable:
- Bullish and bearish colors
- Line width
- Label size
🔸 Efficient Update Logic
Pattern checks are only performed when a new pivot is confirmed, avoiding unnecessary repeated calculations on every bar. The most recent pattern’s projected elements (zone and label positioning) are updated as new bars print to keep the latest setup readable.
🔹 Calculations
This section summarizes the core logic used for detection and plotting.
1. Pivot Detection (Swing Highs and Lows)
The script relies on confirmed pivots using the user inputs:
Left Bars: how many bars must exist to the left of the pivot
Right Bars: how many bars must exist to the right to confirm it
Pine Script®
When a pivot is confirmed, its true bar index is the pivot bar, not the current bar, so the script stores:
Pine Script®
2. Pivot Storage and History Window
Each pivot is stored as a structured object containing:
- price
- index
- isHigh (true for pivot high, false for pivot low)
A rolling history is maintained (up to 50 pivots) to keep processing stable and memory usage controlled.
3. Sequence Validation (Alternation Check)
The pattern evaluation always uses the latest 4 pivots:
p0: Left Shoulder candidate
p1: Reaction candidate
p2: Head candidate
p3: MSB candidate
Before checking bullish/bearish rules, the script enforces alternating pivot types:
Pine Script®
This prevents invalid structures like consecutive highs or consecutive lows from being interpreted as QML.
4. Bullish QML Conditions
A bullish QML is evaluated when the Left Shoulder is a Low:
Head must be lower than Left Shoulder (sweep)
MSB must be higher than Reaction (break)
Pine Script®
Interpretation:
p2 < p0 represents the liquidity grab below the prior swing low
p3 > p1 represents the market structure break above the reaction high
5. Bearish QML Conditions
A bearish QML is evaluated when the Left Shoulder is a High:
Head must be higher than Left Shoulder (sweep)
MSB must be lower than Reaction (break)
Pine Script®
Interpretation:
p2 > p0 represents the liquidity grab above the prior swing high
p3 < p1 represents the market structure break below the reaction low
6. Drawing Logic (Structure, Highlight, Zone, Labels)
When confirmed, the script draws:
Three connecting legs (LS to Reaction, Reaction to Head, Head to MSB)
A shaded triangle using a transparent “ghost” line to enable filling
A dotted MSB emphasis line between Reaction and MSB
A QML Zone box spanning the LS to Head price range and projecting to the right
Point labels: LS, Head, MSB
A direction label: “Bullish QML” or “Bearish QML”
7. Latest Pattern Extension
To keep the newest setup readable, the script updates the most recently detected pattern by extending its projected elements as new bars print:
QML zone right edge is pushed forward
The main label x position is pushed forward
This keeps the last identified QML zone visible as price evolves, without having to redraw historical patterns on every bar.
Detection is built on pivot highs and lows, so patterns are evaluated only after swing points are validated. Once a valid 4 pivot sequence is identified, the indicator draws the pattern legs, highlights the internal triangle area to emphasize the grab, marks the MSB leg, and projects a QML zone that can be used as a potential area of interest for retests.
This tool is designed for traders who work with structure, liquidity concepts, and reversal/continuation triggers, and who want a clean, repeatable QML visualization without manually marking swings.
🔹 Features
🔸 Confirmed Pivot Based Structure Mapping
The script uses classic built-in pivot logic to detect swing highs and swing lows.
🔸 Automatic Bullish and Bearish QML Detection
The indicator evaluates the most recent 4 pivots and checks for a valid alternating sequence (High-Low-High-Low or Low-High-Low-High). When the sequence matches QML requirements, the script classifies the setup as bullish or bearish:
Bullish logic (structure reversal up):
- Left Shoulder is a pivot Low
- Head is a lower Low than the Left Shoulder (liquidity sweep)
- MSB pivot exceeds the Reaction pivot
Bearish logic (structure reversal down):
- Left Shoulder is a pivot High
- Head is a higher High than the Left Shoulder (liquidity sweep)
- MSB pivot breaks below the Reaction pivot
🔸 Full Pattern Visualization (Legs + Highlighted Core)
When a pattern triggers, the script draws:
Three main legs: Left Shoulder to Reaction, Reaction to Head, Head to MSB
A shaded triangular highlight over the internal structure to make the liquidity-grab shape easy to spot at a glance
🔸 QML Zone Projection
A QML Zone box is drawn using the price range defined between the Left Shoulder and the Head, then extended to the right to remain visible as price develops. This zone is intended to act as a practical reference area for potential retests and reaction planning after MSB confirmation.
🔸 MSB Emphasis
A dotted MSB line is drawn between the Reaction point and the MSB point to visually emphasize the confirmation leg that completes the pattern logic.
🔸 Clean Point Tagging and Directional Labeling
Key points are labeled directly on the chart:
- “LS” at the Left Shoulder
- “Head” at the sweep pivot
- “MSB” at the break pivot
A directional label (“Bullish QML” or “Bearish QML”) is also printed to quickly identify the detected bias.
🔸 Configurable Visual Style
All main visual components are user configurable:
- Bullish and bearish colors
- Line width
- Label size
🔸 Efficient Update Logic
Pattern checks are only performed when a new pivot is confirmed, avoiding unnecessary repeated calculations on every bar. The most recent pattern’s projected elements (zone and label positioning) are updated as new bars print to keep the latest setup readable.
🔹 Calculations
This section summarizes the core logic used for detection and plotting.
1. Pivot Detection (Swing Highs and Lows)
The script relies on confirmed pivots using the user inputs:
Left Bars: how many bars must exist to the left of the pivot
Right Bars: how many bars must exist to the right to confirm it
float ph = ta.pivothigh(leftLen, rightLen)
float pl = ta.pivotlow(leftLen, rightLen)
When a pivot is confirmed, its true bar index is the pivot bar, not the current bar, so the script stores:
bar_index[rightLen]
2. Pivot Storage and History Window
Each pivot is stored as a structured object containing:
- price
- index
- isHigh (true for pivot high, false for pivot low)
A rolling history is maintained (up to 50 pivots) to keep processing stable and memory usage controlled.
3. Sequence Validation (Alternation Check)
The pattern evaluation always uses the latest 4 pivots:
p0: Left Shoulder candidate
p1: Reaction candidate
p2: Head candidate
p3: MSB candidate
Before checking bullish/bearish rules, the script enforces alternating pivot types:
bool correctSequence =
(p0.isHigh != p1.isHigh) and
(p1.isHigh != p2.isHigh) and
(p2.isHigh != p3.isHigh)
This prevents invalid structures like consecutive highs or consecutive lows from being interpreted as QML.
4. Bullish QML Conditions
A bullish QML is evaluated when the Left Shoulder is a Low:
Head must be lower than Left Shoulder (sweep)
MSB must be higher than Reaction (break)
if not p0.isHigh
if p2.price < p0.price and p3.price > p1.price
// Bullish QML confirmed
Interpretation:
p2 < p0 represents the liquidity grab below the prior swing low
p3 > p1 represents the market structure break above the reaction high
5. Bearish QML Conditions
A bearish QML is evaluated when the Left Shoulder is a High:
Head must be higher than Left Shoulder (sweep)
MSB must be lower than Reaction (break)
if p0.isHigh
if p2.price > p0.price and p3.price < p1.price
// Bearish QML confirmed
Interpretation:
p2 > p0 represents the liquidity grab above the prior swing high
p3 < p1 represents the market structure break below the reaction low
6. Drawing Logic (Structure, Highlight, Zone, Labels)
When confirmed, the script draws:
Three connecting legs (LS to Reaction, Reaction to Head, Head to MSB)
A shaded triangle using a transparent “ghost” line to enable filling
A dotted MSB emphasis line between Reaction and MSB
A QML Zone box spanning the LS to Head price range and projecting to the right
Point labels: LS, Head, MSB
A direction label: “Bullish QML” or “Bearish QML”
7. Latest Pattern Extension
To keep the newest setup readable, the script updates the most recently detected pattern by extending its projected elements as new bars print:
QML zone right edge is pushed forward
The main label x position is pushed forward
This keeps the last identified QML zone visible as price evolves, without having to redraw historical patterns on every bar.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.