Directional Logistic Oscillator | GainzAlgoOverview
The Directional Logistic Oscillator (DLO) is a momentum-based indicator designed to measure directional market strength and identify potential trend reversals or mean-reversion opportunities. It builds on the classic Directional Movement Index (DMI) by transforming its components (+DI, -DI, and ADX) into probabilistic signals using logistic functions, then combining them into a bounded oscillator that oscillates between approximately -1 and +1.
Unlike traditional oscillators like RSI or MACD, DLO emphasizes directional probability by estimating the likelihood of bullish or bearish dominance while factoring in overall trend strength (via ADX). This makes it particularly useful for:
Spotting overbought/oversold conditions in ranging markets.
Confirming trend shifts in trending markets.
Generating reversal signals based on oscillator cycles.
The oscillator is plotted as histogram bars (columns) for visual clarity, with color-coding to highlight strength and direction. Positive values indicate bullish momentum, negative values bearish, and crossings of key levels can signal trading opportunities.
How It Works
At its core, DLO processes DMI data through a logistic transformation to create "probabilities" of directional movement:
1. DMI Calculation : Uses the standard DMI with a user-defined length (default 14) to compute +DI (upward movement), -DI (downward movement), and ADX (trend strength).
2. Logistic Probability : Each DMI component is normalized against its long-term mean and passed through a logistic (sigmoid) function. This creates smooth probabilities between 0 and 1.
The logistic function is defined as:
logistic_prob(series, mean_lb, slope, smooth_len) =>
mean = ta.sma(series, mean_lb)
z = (series - mean) * slope
prob_raw = 1.0 / (1.0 + math.exp(-z))
ta.ema(prob_raw, smooth_len)
This step makes the indicator adaptive to market conditions, with the "slope" controlling how sharply it reacts to deviations from the mean.
3. Net Directional Strength : Bullish minus bearish probability, scaled by ADX probability and a user-defined multiplier, then bounded using a hyperbolic tangent (tanh) function to keep values between -1 and +1.
net_dir = prob_plus - prob_minus
strength_raw = net_dir * prob_adx * osc_scale
strength_bound = tanh(strength_raw)
Tanh ensures smooth, bounded output without clipping extremes unnaturally.
4. Smoothing and Signals: The raw strength is smoothed with EMA, then further processed into SMA and EMA lines for signal generation. Percentile-based thresholds (adaptive over a lookback period) detect extreme zones for mean-reversion signals.
The result is a visually intuitive oscillator: Green bars for bullish, red for bearish, with varying intensity based on momentum.
Inputs
DLO offers customizable settings grouped for ease of use. Defaults are tuned for balanced performance on daily charts.
DMI Settings
DI Length (default: 14): Controls DMI sensitivity. Shorter lengths react faster to price changes but add noise; longer lengths smooth signals for trends.
Mean Lookback (default: 360): The period for calculating the long-term average of DMI components. Higher values provide a more stable baseline, reducing false signals from short-term volatility. Lower values make the indicator more responsive but noisier
Difference between high and low mean lookback period, lower length can pick up on new trends faster but at the cost of increased noise.
Logistic Probability Settings
LR Slope (higher = steeper) (default: 0.18): Adjusts the steepness of the logistic curve. Lower values create gradual transitions (smoother oscillator); higher values make sharp shifts, emphasizing extremes.
Probability Smoothing (EMA) (default: 3): Short EMA to reduce noise in probabilities. Keep low (1-5) for responsiveness; higher for smoothness.
Oscillator Settings
Oscillator Scale (pre-tanh) (default: 2.5): Multiplies net strength before bounding. Higher values increase sensitivity and amplitude (larger swings); lower values compress the range for subtler signals.
Comparison of 4 different settings for Oscillator scale, showing that as the scale parameter increases, the oscillator output becomes more pronounced, exhibiting higher amplitude compression toward the bounds and spending more time saturated near the extreme values of +1 and −1.
Oscillator Smoothing Length (default: 7): Period for SMA/EMA smoothing of the final oscillator. Longer = smoother, fewer signals; shorter = more reactive.
Color & Display Settings
Buy Color / Sell Color: Customize colors for bullish/bearish visuals.
Plot Reversion Signals (default: true): Shows arrows for cycle reversals (local highs/lows).
Plot Mean-Reversion Signals (default: true): Arrows for crossings from extreme percentile zones.
Plot Oscillator MA (default: false): Overlays an SMA on the oscillator for additional confirmation.
Allow Intrabar Updating (default: true): Enables real-time updates within incomplete bars (may cause minor repainting).
Visuals
Oscillator Histogram: Columns colored green (bullish) or red (bearish), with lighter shades for weaker momentum. Crosses above/below zero signal momentum shifts.
Horizontal Lines: Zero (neutral), +0.5 (strong bullish), -0.5 (strong bearish).
Background Highlights: Subtle green/red shading when in strong zones.
Bar Colors: Mirrors oscillator direction on the price chart.
Color-coded trend regimes: green/teal highlight strong and weak uptrends, red/purple mark strong and weak downtrends, while the oscillator histogram confirms direction and strength through its polarity and amplitude.
Signals
Mean-Reversion (MR) Signals : Triangles (▲/▼) when the smoothed oscillator crosses up from low percentiles (oversold) or down from high percentiles (overbought). These are adaptive, using historical data for dynamic extremes.
Buy: Oscillator crosses above lower threshold (e.g., 10th/5th percentile).
Sell: Crosses below upper threshold (e.g., 90th/95th percentile).
Reversion Signals : Arrows (⬆/⬇) at local turning points in the oscillator cycle, indicating potential reversals.
Zero-Line Crosses : Basic bullish/bearish momentum changes.
Usage Tips
Trend Confirmation: Use in trending markets—persistent positive/negative values confirm up/down trends. Pair with moving averages for entries.
Mean-Reversion: In sideways markets, trade MR signals from extremes. Combine with support/resistance.
Divergences: Look for price making new highs/lows while DLO doesn't for reversal setup.
Alerts
MR Buy/Sell: Extreme zone crosses (percentile-based).
Reversion Up/Down: Cycle turning points.
Osc Bullish/Bearish Cross: Zero-line crosses.
Limitations
Like all oscillators, DLO can lag in strong trends or produce false signals in choppy markets, use with confirmation.
Percentile thresholds adapt over time but may vary by asset volatility.
Not a standalone system; always combine with risk management.
อินดิเคเตอร์ Pine Script®







