PulseHub
OPEN-SOURCE SCRIPT
Updated

Market Compass - Dynamic Range Framework

1 450
Hello English readers, the English version is provided below. Please scroll down to view it.


Market Compass - Dynamic Range Framework
市场指南针 · 动态区间框架
版本:1.0 | 类型:非预测性价格结构定位工具 | 作者:[william_wq]


绝大多数交易亏损,根源并非方向判断错误,而是 “位置感”的缺失。本指标旨在为您解决这一核心痛点——它不告诉您涨跌,但它告诉您 “此时此刻,价格在地图上的精确坐标”

---

[1. 是什么 (What) —— 一套主图叠加的“价格经纬度坐标系”]

本指标并非传统的均线或动量振荡器,而是一个 基于固定回溯周期的价格百分位区间定位系统。它以最近 N 根 K 线(默认 252 根,对应约 1 个交易年度)的最高价与最低价为天然边界,构建出一个覆盖 0% 至 100% 的动态箱体网格

该网格并非平均分割,而是采用 非对称的黄金分割与极值锚定法,精确定制了 9 条关键水平轨道。这些轨道以彩色矩形色带和右侧实时浮动标签的形式,干净利落地叠加于主图 K 线之上:

  1. 100% 顶部极值轨(红色):回溯周期内的绝对天花板。
  2. 89% 超买警戒轨(橙色):情绪极度亢奋区,多头衰竭高发带。
  3. 75% 强势分界轨(黄色):牛熊分水岭,站上此线意味中期趋势转强。
  4. 62.5% 强界枢轴轨(紫色):多头趋势中的次级回踩支撑位。
  5. 50% 多空中轴轨(白色):价值均衡线,长线资金的成本密集区。
  6. 37.5% 弱界枢轴轨(青色):空头趋势中的次级反弹阻力位。
  7. 25% 弱势分界轨(亮蓝):跌破此线意味中期趋势正式转入空头。
  8. 11% 超卖警戒轨(浅绿):情绪极度恐慌区,空头衰竭高发带。
  9. 0% 底部极值轨(深蓝):回溯周期内的绝对地板。


随着新 K 线的生成,整个框架会滚动迭代,始终锚定最新的价格活动范围,确保参考坐标永不失效。

---

[2. 为什么 (Why) —— 解决传统 K 线分析的两大认知缺陷]

传统价格图表存在严重的视角局限性,导致交易者频繁陷入误判:

  1. “绝对值幻觉”与锚定效应:股价 100 元是高是低?脱离近期波动区间谈绝对价格毫无意义。本指标将价格转化为 0~100 的相对百分位数,消除了价格基数的干扰,让您客观评判当前价格是“相对高位”还是“相对低位”。
  2. “区间失忆症”与近因偏好:人类大脑天然对最近 5~10 根 K 线赋予过高权重,极易遗忘前期关键的支撑与阻力结构。本指标通过固定窗口的滚动计算,强制将 过去 N 根 K 线的价格极值 醒目地绘制在当前图表上,纠正了这种认知偏差。
  3. 均值回归与极端磁吸理论:金融市场价格长期遵循 “极端值向中轴(50% 均衡线)回归” 的统计规律。当价格进入 89% 以上或 11% 以下的极端尾部区域时,统计概率上必然面临向 50% 中轴的牵引力。本框架为这种“牵引力”提供了精确的量化刻度。


---

[3. 怎么用 (How) —— 从“观察”到“决策”的完整作战手册]

本指标是趋势过滤、盈亏比评估与动态止盈止损的绝佳辅助工具。请勿将其视为独立入场信号,而应作为“价格行为决策的量化底座”

3.1 基于市场环境的三种经典战法

  1. 【趋势跟踪战法】—— 适用于强势单边行情
    当价格经过充分调整后,以放量大阳线有效突破 75% 强势分界轨 时,视为中期趋势由震荡转强的关键确认点。若后续价格回踩 75% 轨并获得支撑(收出长下影线),则为绝佳的顺大势、逆小势加仓机会。此时可将止损设于 62.5% 强界枢轴轨下方。
  2. 【均值回归战法】—— 适用于宽幅震荡行情
    当价格快速冲高至 89% 超买轨 上方,且 K 线出现明显滞涨形态(如射击之星、看跌吞没)时,可视为短线高空机会,第一目标位看向 75% 轨,第二目标位看向 50% 中轴。反之,价格急跌至 11% 超卖轨 下方并出现止跌反转形态时,可视为短线低吸机会。
  3. 【突破回踩确认战法】—— 适用于关键阻力支撑转换
    任何一条百分比轨道都具备动态支撑/阻力的属性。当价格自下而上突破某一轨道(如 62.5% 轨)后,若随后缩量回踩该轨道且未跌破,则说明该轨道已由阻力转换为支撑,此处是风险收益比极高的 “0 级入场点”(止损极小,空间极大)。


3.2 动态止盈与止损设置指南

  • 波段多头持仓:可将 37.5% 弱界枢轴轨 设为最终的硬性离场线。只要价格在此轨之上,多头头寸便可安心持有,避免被早期震荡洗出。
  • 短线空头持仓:可将 62.5% 强界枢轴轨 设为硬性止损线。一旦价格强势反抽并站上此轨,则空头逻辑被证伪,需果断离场。


3.3 参数动态调整建议(针对不同交易周期)

  • 日线级别(中长线 / 波段):建议保持默认 252(约 1 年交易日),用于捕捉年度大箱体的牛熊转换。
  • 周线级别(大趋势 / 仓位布局):建议调整为 52(约 1 年周线),用于识别超大周期的价格百分位极值。
  • 小时 / 分钟级别(日内短线 / 剥头皮):建议调整为 50 ~ 100,过长的周期在分钟图上会导致框架钝化,失去短线参考意义。


---

[4. 用在哪里 (Where) —— 适用品种、场景与风控红线]

4.1 最佳适用场景

  • 流动性充裕的权益市场:沪深 300、中证 500、标普 500 等主流指数及成分股。
  • 高流动性大宗商品与外汇:黄金、原油、欧元/美元等主要交易对。
  • 高市值加密货币:比特币(BTC)、以太坊(ETH)等。


4.2 禁用与慎用场景(风控红线)

  • 严禁用于上市不足 N 根 K 线的新股/次新股:尽管代码内置了自适应缩窄逻辑,但新股价格极不稳定,高低点极易被操纵,百分位框架参考价值极低。
  • 慎用于连续无量涨跌停的极端行情:在极强的单边轧空或流动性枯竭的踩踏中,价格可能长期粘合在 100% 轨之上或 0% 轨之下,此时指标出现 “钝化” 现象,需立即切换至趋势跟踪指标(如 SAR 抛物线或均线系统)进行二次印证。
  • 慎用于高度控盘的“庄股”或低成交量仙股:稀疏的成交导致价格跳跃性极大,计算出的区间极易失真。


---

[5. 底层原理 (Underlying Mechanics) —— 数学引擎与渲染优化全解析]

本指标严格遵循 PulseWire 最佳实践,完全不包含未来函数,所有信号均基于确定性的历史数据实时滚动计算。

5.1 自适应周期核心算法
系统优先读取用户设定的 `lookbackLength`(默认 252)。然而,当图表加载的品种上市天数不足时,引擎会自动触发保护机制:
Pine Script®

该行代码确保指标在上市首日即能工作,且随着新 K 线增加,窗口期自然增长,直至达到用户设定的标准周期。

5.2 九宫格线性映射(百分位分割数学)
首先确定箱体极值与范围:
Pine Script®

随后基于 斐波那契数列与统计学标准差启发式阈值 进行非均匀切割:
Pine Script®

注:62.5% 与 37.5% 的选取来源于对 0.618 黄金分割率的整数微调,旨在提供比传统 61.8% 更为清晰且易于记忆的刻度。

5.3 图形渲染引擎优化(内存与性能管理)
为了避免在大量历史 K 线上重复绘制矩形和线条导致图表卡顿,引擎采用 “惰性删除与单次实例化” 策略:
Pine Script®

所有标签采用 label.style_label_left 右对齐样式,确保在图表最右侧整齐排列,绝不遮挡最新的 K 线实体,同时提供精确至交易所最小报价单位(`format.mintick`)的实时读数。

---

[6. 总结:该指标的哲学定位]

它不是占卜未来的水晶球,而是衡量当下的卡尺。
在充满不确定性的金融市场中,“位置感”是纪律执行的基石。`Market Compass` 为您提供的不是圣杯,而是一张永远保持更新的战场态势感知地图。请将它融入您现有的交易系统中,作为过滤低质量交易机会的第一道关卡。

---

[免责声明]
本指标及此说明文件仅供教育及技术分析参考之用,绝不构成任何形式的买入、卖出或持仓建议。金融衍生品及证券交易蕴含巨大风险,过往价格结构及百分位分布不构成对未来走势的绝对保证。您必须结合自身财务状况、风险承受能力及独立研判做出交易决策,盈亏自负。作者不承担任何因使用本指标而产生的直接或间接损失。

---

如果您认可这套价格定位逻辑,欢迎点赞、收藏并关注!
期待您在评论区分享将该框架融入实战交易后的心得体会。



Market Compass - Dynamic Range Framework
Version: 1.0 | Type: Non-Predictive Price Structure Positioning Tool | Author: [william_wq]


The vast majority of trading losses stem not from incorrect directional judgment, but from a lack of "positional awareness". This indicator addresses this core pain point — it does not tell you whether price will go up or down, but it does tell you "the precise coordinates of price on the map, at this very moment".

---

[1. What It Is — A "Price Latitude & Longitude Coordinate System" Overlaid on the Main Chart]

This indicator is not a traditional moving average or momentum oscillator. Instead, it is a price percentile range positioning system based on a fixed lookback period. It uses the highest high and lowest low over the most recent N bars (default 252, corresponding to approximately one trading year) as natural boundaries, constructing a dynamic box grid spanning from 0% to 100%.

The grid is not evenly divided. It employs an asymmetric golden ratio and extreme-value anchoring methodology to precisely define 9 key horizontal threshold levels. These levels are cleanly overlaid on the main price chart using colored rectangular bands and real-time right-aligned floating labels:

  1. 100% Peak Threshold (Red): The absolute ceiling within the lookback period.
  2. 89% Overbought Warning Zone (Orange): Extreme euphoria zone; high probability of bullish exhaustion.
  3. 75% Bullish Boundary (Yellow): The bull-bear dividing line; breaking above signals medium-term strength.
  4. 62.5% Bull Pivot Threshold (Purple): Secondary retracement support level within an uptrend.
  5. 50% Equilibrium Axis (White): The value equilibrium line; a dense area of long-term capital cost.
  6. 37.5% Bear Pivot Threshold (Cyan): Secondary retracement resistance level within a downtrend.
  7. 25% Bearish Boundary (Light Blue): Breaking below signals a confirmed medium-term bearish trend.
  8. 11% Oversold Warning Zone (Light Green): Extreme panic zone; high probability of bearish exhaustion.
  9. 0% Floor Threshold (Dark Blue): The absolute floor within the lookback period.


As new bars are generated, the entire framework rolls forward iteratively, always anchored to the most recent price activity range, ensuring the reference coordinates never become obsolete.

---

[2. Why It Matters — Addressing Two Critical Cognitive Biases in Traditional K-Line Analysis]

Traditional price charts suffer from severe perspective limitations, leading traders into frequent misjudgments:

  1. "Absolute Value Illusion" and Anchoring Bias: Is a price of $100 high or low? Discussing absolute price without reference to the recent trading range is meaningless. This indicator converts price into a relative percentile from 0 to 100, eliminating the distortion of price magnitude and allowing you to objectively assess whether the current price is "relatively high" or "relatively low."
  2. "Range Amnesia" and Recency Bias: The human brain naturally assigns excessive weight to the most recent 5–10 bars, easily forgetting key prior support and resistance structures. Through rolling window calculations, this indicator forcibly and prominently plots the price extremes of the past N bars on the current chart, correcting this cognitive bias.
  3. Mean Reversion and Extreme Magnetic Attraction Theory: Financial market prices have long exhibited a statistical tendency to "revert from extreme values toward the center (50% equilibrium line)". When price enters the extreme tail regions above 89% or below 11%, statistical probability dictates an inevitable gravitational pull toward the 50% axis. This framework provides precise quantitative刻度 for this "magnetic force."


---

[3. How to Use It — A Complete Battle Manual from "Observation" to "Decision"]

This indicator serves as an excellent auxiliary tool for trend filtering, risk-reward assessment, and dynamic stop-loss/take-profit placement. Do not treat it as an independent entry signal; instead, regard it as a "quantitative foundation for price-action decision-making."

3.1 Three Classic Strategies Based on Market Context

  1. 【Trend Following Strategy】— For Strong Directional Markets
    When price, after sufficient consolidation, breaks decisively above the 75% Bullish Boundary with a high-volume bullish candle, this serves as a key confirmation that the medium-term trend is shifting from consolidation to strength. If price subsequently retests the 75% level and finds support (forming a long lower wick), it represents an excellent "go with the macro trend, counter the micro pullback" add-on opportunity. In such cases, place your stop-loss below the 62.5% Bull Pivot Threshold.
  2. 【Mean Reversion Strategy】— For Range-Bound Markets
    When price spikes rapidly above the 89% Overbought Warning Zone and simultaneously exhibits clear exhaustion patterns (such as shooting stars or bearish engulfing), this can be viewed as a short-term selling opportunity. The first target is the 75% level, and the second target is the 50% Equilibrium Axis. Conversely, when price plummets below the 11% Oversold Warning Zone and shows reversal signals, a short-term buying opportunity emerges.
  3. 【Breakout-Pullback Confirmation Strategy】— For Key Support/Resistance Transitions
    Every percentage threshold possesses dynamic support/resistance properties. When price breaks upward through a given level (e.g., the 62.5% level) and subsequently retests that level on diminishing volume without breaking back below, this confirms that the level has successfully transitioned from resistance to support. This represents a highly favorable "Grade-A Entry Point" (minimal stop-loss, substantial upside potential).


3.2 Dynamic Stop-Loss and Take-Profit Placement Guide

  • Swing Long Positions: Use the 37.5% Bear Pivot Threshold as your ultimate hard exit line. As long as price remains above this level, you can confidently hold your long position, avoiding premature exits caused by early-stage volatility.
  • Short-Term Short Positions: Use the 62.5% Bull Pivot Threshold as your hard stop-loss line. Should price stage a strong rally and close above this level, the bearish thesis is invalidated, and you must exit decisively.


3.3 Parameter Adjustment Recommendations (By Trading Timeframe)

  • Daily Chart (Swing / Medium-to-Long Term): Keep the default 252 (approximately one trading year), ideal for capturing annual bull-bear transitions.
  • Weekly Chart (Macro Trend / Position Sizing): Consider adjusting to 52 (approximately one year of weekly bars) for identifying extreme percentiles within broader cycles.
  • Hourly / Minute Charts (Intraday / Scalping): Consider adjusting to 50–100. Longer lookbacks on lower timeframes cause the framework to become overly rigid, diminishing its short-term relevance.


---

[4. Where to Apply It — Suitable Instruments, Scenarios, and Risk Red Lines]

4.1 Optimal Use Cases

  • Highly Liquid Equity Markets: CSI 300, S&P 500, major index constituents, and liquid individual stocks.
  • High-Liquidity Commodities and FX: Gold, Crude Oil, EUR/USD, and other major pairs.
  • Large-Cap Cryptocurrencies: Bitcoin (BTC), Ethereum (ETH), and similar assets.


4.2 Scenarios to Avoid or Use with Caution (Risk Red Lines)

  • Strictly avoid newly listed stocks with fewer than N bars of history: Although the code includes a built-in adaptive shortening mechanism, new issues are extremely unstable, and their highs/lows are vulnerable to manipulation, rendering the percentile framework nearly worthless.
  • Use with caution during continuous limit-up/limit-down extreme conditions: In powerful short squeezes or liquidity-driven crashes, price may remain persistently glued above the 100% level or below the 0% level. In such cases, the indicator becomes "blunted", and you must immediately switch to trend-following tools (such as SAR or moving average systems) for secondary confirmation.
  • Avoid low-float "pump-and-dump" penny stocks: Sparse trading volume leads to erratic price jumps, causing the computed range to become highly distorted.


---

[5. Underlying Mechanics — A Comprehensive Breakdown of the Mathematical Engine and Rendering Optimization]

This indicator strictly adheres to PulseWire best practices and contains absolutely no future functions. All signals are computed in real time based on deterministic historical data.

5.1 Adaptive Lookback Core Algorithm
The system first reads the user-defined `lookbackLength` (default 252). However, when the loaded instrument has fewer total bars on the chart than the configured period, the engine automatically triggers a protective mechanism:
Pine Script®

This single line ensures the indicator functions from the very first trading day, and the window gradually expands as new bars are added until it reaches the user's desired standard period.

5.2 Nine-Level Linear Mapping (Percentile Segmentation Mathematics)
The process begins by determining the box extremes and range:
Pine Script®

The range is then divided using a heuristic blend of Fibonacci ratios and statistically inspired thresholds:
Pine Script®

Note: The selection of 62.5% and 37.5% is derived from a slight integer adjustment to the 0.618 golden ratio, intended to provide cleaner and more memorable reference刻度 than the traditional 61.8%.

5.3 Rendering Engine Optimization (Memory & Performance Management)
To prevent chart lag caused by repeatedly drawing rectangles and lines across numerous historical bars, the engine employs a "lazy deletion with single-instantiation" strategy:
Pine Script®

All labels use the label.style_label_left right-aligned format, ensuring they line up neatly on the far right of the chart without ever obscuring the most recent price bars. Prices are displayed with precision down to the exchange's minimum tick size (`format.mintick`).

---

[6. Conclusion — The Philosophical Positioning of This Indicator]

It is not a crystal ball for predicting the future; it is a caliper for measuring the present.
In the inherently uncertain financial markets, "positional awareness" is the cornerstone of disciplined execution. `Market Compass` does not offer you a holy grail; it offers you an ever-updating situational awareness map of the battlefield. Integrate it into your existing trading system and use it as the first filter to eliminate low-probability trade setups.

---

[Disclaimer]
This indicator and its accompanying description are provided for educational and technical analysis purposes only. They do not constitute, and should not be construed as, any form of investment advice or recommendation to buy, sell, or hold any financial instrument. Trading securities and derivatives involves substantial risk of loss. Past price structures and percentile distributions do not guarantee future results. You are solely responsible for your own trading decisions, taking into account your financial situation, risk tolerance, and independent judgment. Neither the author nor the hosting platform accepts any liability for losses arising from the use of this indicator.

---

If you find this price-positioning logic valuable, please like, bookmark, and follow!
I look forward to hearing how you integrate this framework into your live trading. Feel free to share your experiences and feedback in the comments section below.

Release Notes
v1.1 Release Notes / v1.1 版本更新说明

Special thanks to community member birdm4484 for the valuable feature suggestion!
特别感谢社区成员 birdm4484 提出的宝贵改进建议!


What's New in v1.1 / v1.1 核心更新内容:

  1. Custom Line Width Controls / 自定义轨迹线宽度:
    Added independent width settings for boundary lines (0% / 100%) and inner level lines (1–10 px).
    新增边界线(0% / 100% 轨)与内部轨迹线的独立粗细调节(支持 1 ~ 10 像素)。
  2. Adjustable Label Text Sizes / 标签字号动态调节:
    Added option to customize label sizes from Tiny to Huge (`size.tiny` ~ `size.huge`), optimizing visibility for 4K displays and multi-chart layouts.
    支持自由设置右侧实时价格标签字号(微小到特大),完美适配 4K 高分屏与多图表分屏视角。
  3. Optimized UI Panel / 设置界面结构优化:
    Integrated size controls into the "UI Display Controls" section for quick micro-adjustments without modifying code.
    将所有尺寸参数统一集成至“显示界面控制”面板,无需改动代码即可一键配置。
Release Notes
v2.0 Release Notes / v2.0 版本更新说明

What's New in v2.0 / v2.0 核心更新内容:

Flexible Anchor & Date Range Modes / 自定义锚定与时间段模式:
Supports 3 calculation modes: Fixed Lookback, Anchor Date to Present, and Custom Date Range, allowing precise analysis of specific historical cycles.
新增 3 种计算模式(固定根数、锚定起点至当前、自定义起止时间段),支持自由锁定和复盘特定历史波段。

Adaptive Range Bounding Box / 智能区域背景框渲染:
The background box automatically scales to fit selected time ranges, while level lines and price labels extend smoothly to current live data.
背景矩形框自动贴合所选时间区间,轨迹线与价格标签持续向右延伸,方便随时对比当前价格与历史结构。

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by PulseWire. Read more in the Terms of Use.