PROTECTED SOURCE SCRIPT
Malama's Market Structure

: Malama's Market Structure is a comprehensive price action utility that unifies four essential institutional trading concepts—Supply/Demand, Liquidity, Trendlines, and Key Levels—into a single, optimized toolkit.
Justification for this Combination (The Mashup): Institutional analysis requires monitoring multiple layers of market structure simultaneously. Using separate indicators for S/D zones, liquidity pools, and daily levels creates chart clutter and conflicting visual signals. This script solves this by integrating these components into a single Zone Management Engine. This engine ensures that when a zone is broken, it is automatically invalidated or marked as a "Retest" candidate, creating a cleaner, actionable chart without manual drawing tools.
What Has Been Fixed in This Version:
Zero-Division Protection: Added safety checks in the Liquidity module avg_ph != 0 to prevent runtime crashes on assets with zero values.
Explicit Zone Typing: The code now strictly differentiates between "Standard Supply" and "Liquidity Supply" to apply correct breakout logic (Close > Top vs Close < Bottom).
Smart Garbage Collection: Implemented a FIFO (First-In, First-Out) memory management system that prioritizes deleting inactive/broken zones before active ones, ensuring critical levels remain on the chart longer without hitting TradingView drawing limits.
Optimized Key Levels: Switched from creating new line objects every bar (which causes memory leaks) to updating a single var line object using line.set_xy.
Underlying Calculations & Logic:
Pivot Analysis (The Foundation): The script identifies structural Swing Highs and Lows using a customizable lookback.
Liquidity Logic: It compares adjacent Pivot Highs. If they are within a strict threshold (0.15%), they are flagged as "Equal Highs (EQH)"—a magnet for price.
Zone Management: An internal array tracks every zone. If price closes beyond a zone, the script detects the "Break" event and visually fades the zone to gray. If price touches a valid zone without breaking, the label updates to "Retest."
How to Use:
Entries: Look for price to reject from active Red (Supply) or Blue (Demand) zones.
Targets: Target the Gray "Liquidity" zones (EQH/EQL), as price often gravitates toward these to clear stops.
Confluence: Use the intersection of Auto-Trendlines and Key Levels as high-probability reversal areas.
Disclaimer: This tool is for educational analysis only. Trading involves significant risk.
Justification for this Combination (The Mashup): Institutional analysis requires monitoring multiple layers of market structure simultaneously. Using separate indicators for S/D zones, liquidity pools, and daily levels creates chart clutter and conflicting visual signals. This script solves this by integrating these components into a single Zone Management Engine. This engine ensures that when a zone is broken, it is automatically invalidated or marked as a "Retest" candidate, creating a cleaner, actionable chart without manual drawing tools.
What Has Been Fixed in This Version:
Zero-Division Protection: Added safety checks in the Liquidity module avg_ph != 0 to prevent runtime crashes on assets with zero values.
Explicit Zone Typing: The code now strictly differentiates between "Standard Supply" and "Liquidity Supply" to apply correct breakout logic (Close > Top vs Close < Bottom).
Smart Garbage Collection: Implemented a FIFO (First-In, First-Out) memory management system that prioritizes deleting inactive/broken zones before active ones, ensuring critical levels remain on the chart longer without hitting TradingView drawing limits.
Optimized Key Levels: Switched from creating new line objects every bar (which causes memory leaks) to updating a single var line object using line.set_xy.
Underlying Calculations & Logic:
Pivot Analysis (The Foundation): The script identifies structural Swing Highs and Lows using a customizable lookback.
Liquidity Logic: It compares adjacent Pivot Highs. If they are within a strict threshold (0.15%), they are flagged as "Equal Highs (EQH)"—a magnet for price.
Zone Management: An internal array tracks every zone. If price closes beyond a zone, the script detects the "Break" event and visually fades the zone to gray. If price touches a valid zone without breaking, the label updates to "Retest."
How to Use:
Entries: Look for price to reject from active Red (Supply) or Blue (Demand) zones.
Targets: Target the Gray "Liquidity" zones (EQH/EQL), as price often gravitates toward these to clear stops.
Confluence: Use the intersection of Auto-Trendlines and Key Levels as high-probability reversal areas.
Disclaimer: This tool is for educational analysis only. Trading involves significant risk.
Script protetto
Questo script è pubblicato come codice protetto. Tuttavia, è possibile utilizzarle liberamente e senza alcuna limitazione – ulteriori informazioni qui.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script protetto
Questo script è pubblicato come codice protetto. Tuttavia, è possibile utilizzarle liberamente e senza alcuna limitazione – ulteriori informazioni qui.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.