PINE LIBRARY
Cập nhật OscLib

Library "OscLib"
OscLib — Oscillator primitives and normalization utilities.
Provides centered/clamped normalization for bounded and unbounded oscillators,
multi-oscillator dispatcher, and pivot-based divergence detection.
Architecture: L0 (no library dependencies, uses ta.* primitives only)
f_center_bounded(raw, midpoint)
Centered normalization for bounded [0,100] oscillators (RSI, MFI, Stoch, WPR)
Parameters:
raw (float): Raw oscillator value
midpoint (float): Center point (typically 50.0 for RSI/MFI/Stoch)
Returns: Centered value in [-1, 1] range
f_clamp_normalize(raw, threshold)
Clamped normalization for unbounded oscillators (CCI, MACD Hist, ATR)
Parameters:
raw (float): Raw oscillator value
threshold (float): Scaling threshold (e.g., 200 for CCI, 2*ATR for MACD)
Returns: Clamped value in [-1, 1] range
f_compute_osc(kind, src, len)
Multi-oscillator dispatcher
Parameters:
kind (string): Oscillator type: "RSI", "CCI", "MFI", "STOCH", "WPR"
src (float): Source series (typically close or hlc3)
len (simple int): Oscillator period/length
Returns: Raw oscillator value
f_divergence_pivot(osc, price, lb_left, lb_right)
Pivot-based divergence detection (matches REOS production pattern)
Parameters:
osc (float): Oscillator series
price (float): Price series (typically close)
lb_left (int): Left lookback for pivot detection
lb_right (int): Right lookback for pivot detection
Returns: [bearish_divergence, bullish_divergence]
bearish_div: price makes higher high, oscillator doesn't
bullish_div: price makes lower low, oscillator doesn't
OscLib — Oscillator primitives and normalization utilities.
Provides centered/clamped normalization for bounded and unbounded oscillators,
multi-oscillator dispatcher, and pivot-based divergence detection.
Architecture: L0 (no library dependencies, uses ta.* primitives only)
f_center_bounded(raw, midpoint)
Centered normalization for bounded [0,100] oscillators (RSI, MFI, Stoch, WPR)
Parameters:
raw (float): Raw oscillator value
midpoint (float): Center point (typically 50.0 for RSI/MFI/Stoch)
Returns: Centered value in [-1, 1] range
f_clamp_normalize(raw, threshold)
Clamped normalization for unbounded oscillators (CCI, MACD Hist, ATR)
Parameters:
raw (float): Raw oscillator value
threshold (float): Scaling threshold (e.g., 200 for CCI, 2*ATR for MACD)
Returns: Clamped value in [-1, 1] range
f_compute_osc(kind, src, len)
Multi-oscillator dispatcher
Parameters:
kind (string): Oscillator type: "RSI", "CCI", "MFI", "STOCH", "WPR"
src (float): Source series (typically close or hlc3)
len (simple int): Oscillator period/length
Returns: Raw oscillator value
f_divergence_pivot(osc, price, lb_left, lb_right)
Pivot-based divergence detection (matches REOS production pattern)
Parameters:
osc (float): Oscillator series
price (float): Price series (typically close)
lb_left (int): Left lookback for pivot detection
lb_right (int): Right lookback for pivot detection
Returns: [bearish_divergence, bullish_divergence]
bearish_div: price makes higher high, oscillator doesn't
bullish_div: price makes lower low, oscillator doesn't
Phát hành các Ghi chú
v2Added:
f_default_vis_config()
Get default visual configuration
Returns: VisConfig with sensible defaults
OscSpec
Oscillator specification (kind + behavior descriptor)
Fields:
kind (series string): Oscillator type: "RSI", "MFI", "CCI", "STOCH", "WPR", "OBV", "CVD", "Close"
source (series string): Price source: "close", "hlc3", "hl2", "ohlc4"
soft_clip (series bool): Use tanh soft-clip (true) or hard clamp (false)
debug_code (series int): Integer debug code for logging/introspection
OscReading
Oscillator reading (single bar)
Fields:
raw_value (series float): Raw oscillator value before normalization
normalized_value (series float): Z-score normalized value (soft-clipped or hard-clamped to ±6)
bar_index (series int): Bar index when reading was captured
VisConfig
Visual configuration (separate from OscSpec for serialization purity)
Fields:
line_color (series color): Plot line color
transparency (series int): Color transparency (0-100)
line_width (series int): Plot line width
display_name (series string): Human-readable name for legend
Updated:
f_compute_osc(spec, period, zscore_len, src, vol)
Compute oscillator reading from specification
Parameters:
spec (OscSpec): OscSpec defining oscillator parameters
period (simple int): Oscillator period (simple int required for ta.* functions)
zscore_len (simple int): Z-score normalization window (simple int required for ta.sma/ta.stdev)
src (float): Price source series (overrides spec.source if provided)
vol (float): Volume series (required for MFI, CVD)
Returns: OscReading with raw and normalized values
Removed:
f_center_bounded(raw, midpoint)
Centered normalization for bounded [0,100] oscillators (RSI, MFI, Stoch, WPR)
f_clamp_normalize(raw, threshold)
Clamped normalization for unbounded oscillators (CCI, MACD Hist, ATR)
f_divergence_pivot(osc, price, lb_left, lb_right)
Pivot-based divergence detection (matches REOS production pattern)
Thư viện Pine
Theo đúng tinh thần TradingView, tác giả đã công bố mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác trong cộng đồng có thể tái sử dụng. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này cho mục đích cá nhân hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc tái sử dụng mã này trong các ấn phẩm phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Thư viện Pine
Theo đúng tinh thần TradingView, tác giả đã công bố mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác trong cộng đồng có thể tái sử dụng. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này cho mục đích cá nhân hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc tái sử dụng mã này trong các ấn phẩm phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.