OPEN-SOURCE SCRIPT

Adaptive Composite Oscillator (ACO)

1 341
Adaptive Composite Oscillator (ACO)

A momentum oscillator that adapts its own lookback length, normalization bands, and signal logic to current market conditions, rather than relying on the fixed parameters and fixed 70/30-style bands used by traditional oscillators like RSI or Stochastic.


How it works

1. Adaptive lookback. The effective momentum length shortens when recent volatility (ATR relative to its own average) is elevated, and lengthens when volatility is calm. The oscillator speeds up in choppy or volatile stretches and slows down in quiet ones, instead of using one fixed period regardless of context.

2. Manual adaptive RSI. Pine's built-in ta.rsi() requires a fixed length, which a bar-by-bar adaptive length can't satisfy. So the RSI is built manually with a Wilder-style recursive average whose smoothing factor is derived from the adaptive length on every bar — same underlying math as RSI, just computed in a way that tolerates a variable length.

3. KAMA-style smoothing. The raw adaptive RSI is passed through a Kaufman Adaptive Moving Average-style filter, using an efficiency ratio between fast and slow EMA constants. This makes the line track efficient, directional moves closely while damping down noise during back-and-forth chop.

4. Statistical normalization. Rather than fixed overbought/oversold levels, the smoothed momentum is converted into a z-score against its own rolling mean and standard deviation. The ±2 SD bands self-calibrate to each instrument's own volatility character instead of using one arbitrary threshold for every market.

5. Regime filter (ADX/DMI). An ADX reading classifies conditions as ranging or trending. In ranging conditions, z-score extremes are treated as mean-reversion signals. In strong trends (ADX above threshold), those same extremes are deliberately ignored — since momentum can stay "overbought" for a long time inside a real trend — and instead a zero-line cross in the direction confirmed by +DI/−DI is treated as a trend-continuation signal.

6. Volume confirmation. Every signal additionally requires volume above its own moving average, filtering out low-participation moves that wouldn't hold up.

7. Algorithmic divergence with connecting lines. Bullish and bearish divergence is detected by comparing confirmed price pivots to oscillator pivots — a defined rule, not a discretionary read — and drawn as connecting lines on both the price chart and the oscillator pane, so the actual shape of the divergence is visible rather than marked with a single dot.

What's plotted

Oscillator line (z-score), colored by regime — gray for ranging, blue for confirmed uptrend, orange for confirmed downtrend
Dashed ±2 SD statistical bands and a zero line
Yellow background shading while in a strong-trend regime
Green/red triangles for volume-confirmed long/short signals
Magenta/lime connecting lines for bearish/bullish divergence, on both panes

How to use it

Start by reading the regime background: yellow shading means the market is trending strongly by ADX; no shading means it's ranging. That tells you which of the two signal modes is currently active. Then read the line color — gray, blue, or orange — which tells you the direction of any active trend. Triangles mark volume-confirmed signals: green below the line for long, red above for short. Connecting lines mark divergence: magenta between two price/oscillator highs for bearish, lime between two lows for bullish — these appear a few bars after the second pivot confirms, since a pivot needs bars on both sides to validate.

The strongest setups combine elements rather than relying on one signal alone — for example, a long triangle firing alongside a lime divergence line, or a trend-mode zero-cross that agrees with a higher-timeframe trend you've checked separately. Avoid taking ranging-mode mean-reversion signals against a clearly shaded trending background — that's exactly the mismatch the regime filter exists to prevent.

All lengths, the ADX trend threshold, volume multiplier, pivot lookback, and KAMA constants are adjustable in settings; the defaults are a reasonable starting point, not a finished strategy. Four alert conditions are built in (Long Signal, Short Signal, Bullish Divergence, Bearish Divergence) via TradingView's standard Add Alert dialog.

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.