OPEN-SOURCE SCRIPT

Bookmap Traps - Lite

7 378
Overview
The Bookmap Traps (Lite) indicator is a highly advanced, machine-learning enhanced volume visualization tool designed to uncover hidden liquidity traps within candlestick wicks. Moving beyond traditional volume indicators, this script employs a synthetic lower-timeframe footprint engine to analyze the microstructure of price action, locating exactly where buyers or sellers have been caught offside. By plotting dynamic, volume-weighted bubbles directly on the chart, it allows traders to visualize trapped liquidity in real-time. This provides an x-ray view into order flow exhaustion and high-probability reversal zones, completely bypassing the need for expensive footprint data feeds.

Core Calculations & Logic
The indicator's engine relies on a granular breakdown of price delivery, utilizing multi-timeframe arrays, synthetic Volume Price Trend (VPT), and rigorous wick analysis to identify trapped volume:

  • Synthetic Footprint Generation: Instead of relying on premium data, the script uses `request.security_lower_tf` to fetch 1-minute (or user-defined lower timeframe) OHLCV data. It calculates a Volume Price Trend (VPT) ratio to accurately model the volume distribution within the parent candle, allowing for high-fidelity order flow analysis on the main chart.
  • Direct Wick Volume Measurement: The core logic isolates the parent candle's upper and lower wicks, identifying them as potential trap zones if they meet a minimum percentage of the total bar range. It then iterates through the lower timeframe data, mapping exactly how much relative volume was executed within those specific wick extremities.
  • Strict "Deep Wick" Filtering: To ensure only the most significant rejections are highlighted, the script features a "Deep Wick Only" mode. This forces the engine to disregard volume that occurred near the body of the candle, specifically tracking volume trapped in the outermost half of the wick where participants are most vulnerable.
  • Dynamic Outlier Auto-Scaling: The visualization engine constantly adapts to the current market environment. It calculates rolling volume percentiles to auto-scale the size or transparency of the trap bubbles, ensuring that massive volume anomalies stand out sharply while filtering out insignificant background noise.


The Machine Learning (kNN) Enhancement Engine
The standout feature of Bookmap Traps (Lite) is its built-in predictive k-Nearest Neighbors (kNN) algorithm, which actively scores the quality of detected traps based on historical success:

  • Feature Extraction & Normalization: Every time a trap forms, the script extracts key structural features—such as body-to-ATR ratios, upper/lower wick proportions, body positioning, and trapped volume metrics—and normalizes them for the ML model.
  • Pattern Recognition & Scoring: The kNN engine searches a rolling training window (e.g., the last 300 bars) to find the 'K' most structurally identical historical traps. It then analyzes the subsequent price action of those historical matches to determine a success rate.
  • Intelligent Volume Weighting: If historical data proves that a specific trap pattern consistently fails, the ML score suppresses its visual presence. Conversely, if a pattern is highly reliable, the ML score acts as a multiplier, boosting the trap's volume and amplifying its visual footprint on the chart.


How to Use in Practice

  • Identifying Exhaustion & Reversals: Watch for large teal (trapped buyers) bubbles forming in the upper wicks at resistance, or large red (trapped sellers) bubbles in the lower wicks at support. A massive bubble indicates high participation on the wrong side of the market, signaling an impending, aggressive mean reversion.
  • Interpreting Tooltips & ML Scores: By hovering over a bubble, traders can view the exact trapped volume and the ML confidence score. Prioritize trades where a high volume trap is backed by a high ML success percentage, filtering out statistically weak setups.
  • Customizing Visuals for Clarity: Utilize the "Size Scaling" or "Transparency Scaling" modes to fit your aesthetic preference. For cleaner charts, increase the "Show Top % of Traps" filter to only display the absolute most extreme liquidations (e.g., the top 15%), keeping the interface pristine.
  • Recommended Timeframes: Due to the granular nature of the synthetic lower-timeframe calculations, it is highly recommended to use this indicator on the 15-minute timeframe or higher. This allows the script to aggregate enough lower timeframe data (e.g., 1m candles) within the parent bar to somewhat effectively model the internal volume distribution.


Note: This script is an analytical tool intended to visualize market structure and trapped liquidity mechanics. It does not provide standalone buy/sell trading signals.

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.