H-L/TR/ATR 周期振幅 EX+

// 指标名称: H-L/TR/ATR 周期振幅 (Candle Range)
// 文件路径: d:\桌面\开发\振幅.pine
// Pine 版本: v6
// ----------------------------------------------------------------------------
// [简介]
// 在副图以柱状+三条参考线展示每根K棒的“范围/振幅”。支持三种口径:
// - 不含跳空的 H-L(高-低)
// - 含跳空的 TR(True Range)
// - 平滑后的 ATR(Average True Range)
//
// 支持两种显示:百分比/数值。百分比可按“基准价”转换(自动/开盘/收盘/前收盘/HL2/VWAP/OHLC4)。
// 提供均值/最低/最高三条参考线用于评估当前波动处于区间的相对位置。
// ----------------------------------------------------------------------------
// [主要输入]
// - 显示模式: 百分比 | 数值(仅影响单位与显示,不改变计算)
// - 统计长度 (lookback): 参考线窗口(均值/最低/最高)
// - 计算模式 (calcMode): H-L | TR | ATR
// - ATR长度 (atrLength): 仅 ATR 模式生效
// - 百分比基准 (percentBase): 自动/开盘/收盘/前收盘/HL2/VWAP/OHLC4
// · 自动规则: H-L→开盘;TR/ATR→前收盘
// · VWAP为空时回退 HL2,再回退 开盘
// · 所有分母做最小刻度保护 (syminfo.mintick)
// - 颜色: 柱状图颜色、平均/最低/最高线颜色
// ----------------------------------------------------------------------------
// [计算说明]
// - amplitudeValue:
// · H-L: high - low
// · TR: ta.tr(true) // max(H-L, |H-C[1]|, |L-C[1]|)
// · ATR: ta.atr(atrLength)
// - amplitudePercent: amplitudeValue / 基准价 × 100
// - 参考线(百分比/数值各自计算): ta.sma / ta.lowest / ta.highest
// - VWAP: 以交易日为会话锚定进行累计,日切换时重置
// ----------------------------------------------------------------------------
// [显示]
// - 柱状图: 百分比/数值二选一显示(另一项隐藏),histbase=0
// - 参考线: 平均/最低/最高(线宽1)
// - overlay=false: 在副图窗口显示
// ----------------------------------------------------------------------------
// [使用建议]
// - 日内关注盘中节奏: 用 H-L,百分比基准优先“开盘”或“自动”
// - 日线/周线关注缺口与风险: 用 TR/ATR,百分比基准优先“前收盘”或“自动”
// - 想更中性: 选择 HL2 或 OHLC4;想贴近当日成交重心: 选择 VWAP
// ============================================================================
//
// ============================================================================
// Indicator: H-L/TR/ATR Period Range (Candle Range)
// File: d:\桌面\开发\振幅.pine
// Pine Version: v6
// ----------------------------------------------------------------------------
// [Overview]
// Visualizes per-bar volatility as columns plus three reference lines (avg/min/max).
// Supports three range definitions:
// - H-L (intrabar range without gaps)
// - TR (True Range, includes gaps)
// - ATR (Average True Range, smoothed TR)
//
// Two display modes: percentage or absolute value. Percentage is normalized by
// a selectable base price: Auto/Open/Close/Prev Close/HL2/VWAP/OHLC4.
// ----------------------------------------------------------------------------
// [Inputs]
// - Display Mode: Percent | Value (display only; does not change core calc)
// - Lookback: window length for avg/min/max reference lines
// - Calc Mode: H-L | TR | ATR
// - ATR Length: effective only when Calc Mode = ATR
// - Percent Base: Auto/Open/Close/Prev Close/HL2/VWAP/OHLC4
// · Auto rule: H-L→Open; TR/ATR→Previous Close
// · VWAP fallback: HL2, then Open if VWAP is na
// · All bases are protected by syminfo.mintick to avoid division blowups
// - Colors: histogram and three line colors
// ----------------------------------------------------------------------------
// [Computation]
// - amplitudeValue:
// · H-L: high - low
// · TR: ta.tr(true)
// · ATR: ta.atr(atrLength)
// - amplitudePercent = amplitudeValue / base * 100
// - Reference lines (per-mode): ta.sma / ta.lowest / ta.highest
// - VWAP is session-anchored (daily reset)
// ----------------------------------------------------------------------------
// [Display]
// - Columns: show either Percent or Value (the other hidden), histbase=0
// - Lines: Avg/Min/Max (linewidth=1)
// - overlay=false: plotted in a separate pane
// ----------------------------------------------------------------------------
// [Usage Tips]
// - Intraday rhythm: prefer H-L with base=Open or Auto
// - Daily/weekly with gaps: prefer TR/ATR with base=Prev Close or Auto
// - Neutral baseline: HL2/OHLC4; cost-centric: VWAP
// ============================================================================
Skrip jemputan sahaja
Hanya pengguna yang diluluskan oleh penulis boleh mengakses skrip ini. Anda perlu memohon dan mendapatkan kebenaran untuk menggunakannya. Ini selalunya diberikan selepas pembayaran. Untuk lebih butiran, ikuti arahan penulis di bawah atau hubungi terus ntohpn_eng.
TradingView tidak menyarankan pembayaran untuk atau menggunakan skrip kecuali anda benar-benar mempercayai penulisnya dan memahami bagaimana ia berfungsi. Anda juga boleh mendapatkan alternatif sumber terbuka lain yang percuma dalam skrip komuniti kami.
Arahan penulis
The meaning of life lies in constant revision.
Penafian
Skrip jemputan sahaja
Hanya pengguna yang diluluskan oleh penulis boleh mengakses skrip ini. Anda perlu memohon dan mendapatkan kebenaran untuk menggunakannya. Ini selalunya diberikan selepas pembayaran. Untuk lebih butiran, ikuti arahan penulis di bawah atau hubungi terus ntohpn_eng.
TradingView tidak menyarankan pembayaran untuk atau menggunakan skrip kecuali anda benar-benar mempercayai penulisnya dan memahami bagaimana ia berfungsi. Anda juga boleh mendapatkan alternatif sumber terbuka lain yang percuma dalam skrip komuniti kami.
Arahan penulis
The meaning of life lies in constant revision.