Price Percentile Heatmap [QuantAlgo]🟢 Overview
This indicator visualizes where price currently stands within its recent historical distribution, displayed as a dynamic gradient heatmap directly on the chart. It is built on the concept of percentile ranking: rather than using lagging momentum oscillators or fixed overbought/oversold thresholds, it measures price relative to every bar within a user-defined lookback window and expresses that position as a smooth, continuous gradient. The result is an at-a-glance read of whether price is historically cheap, historically expensive, or somewhere in between, all without leaving the main chart.
The defining visual feature is the thermal color gradient applied to the price bars, background, and source line. Bullish colors represent price trading near the top of its recent range, signaling historically elevated conditions. Bearish colors represent price trading near the bottom of its range, signaling historically depressed conditions. A built-in Heat Thermometer reinforces this reading by showing exactly where the current percentile rank falls along the full spectrum in real time.
🟢 How It Works
The foundation of the indicator is a per-bar percentile rank calculated over a rolling lookback window. For each bar, the selected price source is compared against every value within the lookback period to determine what percentage of historical bars traded below the current price:
percentile_rank = ta.percentrank(price_source, lookback_length)
A rank of 100 means the current price is higher than every bar in the lookback sample. A rank of 0 means it is lower than all of them. A rank of 50 places price exactly at the median of its recent distribution. This single value drives every visual output in the indicator.
The raw rank is then mapped directly into a continuous color gradient, transitioning smoothly from the bearish color at rank 0 to the bullish color at rank 100:
gradient_color = color.from_gradient(percentile_rank, 0, 100, bearish_color, bullish_color)
Because the rank is recalculated on every bar using a rolling window, the gradient never relies on fixed thresholds or static levels. It adapts continuously to the most recent price history, meaning the same absolute price level can read bullish in one market environment and bearish in another depending on what has happened within the lookback period.
The lookback length is the primary tuning parameter. Short periods (10 to 30) make the rank reactive to recent moves and suit scalping and intraday setups. Medium periods (50 to 100) provide a balanced read suitable for swing trading. Long periods (150 to 500) produce a slow-moving, macro-level view best suited for position trading and identifying historically extreme conditions.
🟢 Key Features
1. Thermal Color Gradient
Every visual element on the chart, including the source line, the bar colors, and the background tint, reflects the current percentile rank through a smooth color transition.
▶ Bullish Color: Applied when price ranks high within its recent distribution, drawing attention to historically elevated price levels.
▶ Bearish Color: Applied when price ranks low, highlighting historically depressed conditions and potential mean-reversion or continuation setups.
▶ Bar Coloring: Each individual candlestick is colored according to the current rank, giving instant bar-by-bar feedback without requiring a separate panel.
▶ Background Coloring: The full chart canvas receives a semi-transparent tint that reinforces the heatmap reading across the entire visible price area. Transparency is fully adjustable so price action is never obscured.
▶ Color Presets: Six pre-configured schemes, Classic, Aqua, Cosmic, Cyber, Neon, and Custom, allow you to match the heatmap to any chart theme or personal preference.
2. Heat Thermometer
An optional thermometer panel displays the full bearish-to-bullish color spectrum and marks exactly where the current percentile rank sits along that spectrum with a real-time arrow indicator.
▶ Real-Time Positioning: The arrow updates on every bar, giving an immediate visual anchor for the current rank without needing to read a number.
▶ Resolution: The number of gradient segments in the thermometer is adjustable from 5 to 20, letting you choose between a clean simplified display or a finer, smoother gradient.
▶ Position and Size: The thermometer can be placed in any of nine chart positions and its text size is independently adjustable, making it easy to integrate into dense multi-indicator layouts or standalone setups.
🟢 Practical Applications
▶ Mean Reversion Setups: When price reaches an extreme low percentile rank, it is historically cheap relative to recent bars, a potential entry signal for mean reversion strategies. The opposite applies at high ranks.
▶ Trend Confirmation: In a strong trend, the percentile rank will persistently hue toward one color. A sustained bullish gradient confirms trend strength; a persistent bearish gradient confirms sustained selling pressure.
▶ Multi-Timeframe Alignment: Apply the indicator across multiple timeframes and look for gradient agreement. When both a higher and lower timeframe show the same extreme color, the percentile signal carries significantly more weight.
อินดิเคเตอร์ Pine Script®






