PINE LIBRARY
Atualizado 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
Notas de Lançamento
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)
Biblioteca do Pine
Em verdadeiro espírito TradingView, o autor publicou este código Pine como uma biblioteca de código aberto para que outros programadores Pine da nossa comunidade possam reutilizá-lo. Parabéns ao autor! Você pode usar esta biblioteca de forma privada ou em outras publicações de código aberto, mas a reutilização deste código em publicações é regida pelas Regras da Casa.
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.
Biblioteca do Pine
Em verdadeiro espírito TradingView, o autor publicou este código Pine como uma biblioteca de código aberto para que outros programadores Pine da nossa comunidade possam reutilizá-lo. Parabéns ao autor! Você pode usar esta biblioteca de forma privada ou em outras publicações de código aberto, mas a reutilização deste código em publicações é regida pelas Regras da Casa.
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.