OPEN-SOURCE SCRIPT

Composite Reversal Indicator

245
Overview
The "Composite Reversal Indicator" aggregates five technical signals to produce a composite score that ranges from -5 (strongly bearish) to +5 (strongly bullish). These signals come from:
Relative Strength Index (RSI)

Moving Average Convergence Divergence (MACD)

Accumulation/Distribution (A/D)

Volume relative to its moving average

Price proximity to support and resistance levels

Each signal contributes a value of +1 (bullish), -1 (bearish), or 0 (neutral) to the total score. The raw score is plotted as a histogram, and a smoothed version is plotted as a colored line to highlight trends.
Step-by-Step Explanation
1. Customizable Inputs
The indicator starts with user-defined inputs that allow traders to tweak its settings. These inputs include:
RSI: Length (e.g., 14), oversold level (e.g., 30), and overbought level (e.g., 70).

MACD: Fast length (e.g., 12), slow length (e.g., 26), and signal length (e.g., 9).

Volume: Moving average length (e.g., 20) and multipliers for high (e.g., 1.5) and low (e.g., 0.5) volume thresholds.

Price Levels: Period for support and resistance (e.g., 50) and proximity percentage (e.g., 2%).

Score Smoothing: Length for smoothing the score (e.g., 5).

These inputs make the indicator adaptable to different trading styles, assets, or timeframes.
2. Indicator Calculations
The script calculates five key indicators using the input parameters:
RSI: Measures momentum and identifies overbought or oversold conditions.
Formula: rsi = ta.rsi(close, rsi_length)

Example: With a length of 14, it analyzes the past 14 bars of closing prices.

MACD: Tracks trend and momentum using two exponential moving averages (EMAs).
Formula: [macd_line, signal_line, _] = ta.macd(close, macd_fast, macd_slow, macd_signal)

Components: MACD line (fast EMA - slow EMA), signal line (EMA of MACD line).

Accumulation/Distribution (A/D): A volume-based indicator showing buying or selling pressure.
Formula: ad = ta.accdist

Reflects cumulative flow based on price and volume.

Volume Moving Average: A simple moving average (SMA) of trading volume.
Formula: vol_ma = ta.sma(volume, vol_ma_length)

Example: A 20-bar SMA smooths volume data.

Support and Resistance Levels: Key price levels based on historical lows and highs.
Formulas:
support = ta.lowest(low, price_level_period)

resistance = ta.highest(high, price_level_period)

Example: Over 50 bars, it finds the lowest low and highest high.

These calculations provide the raw data for generating signals.
3. Signal Generation
Each indicator produces a signal based on specific conditions:
RSI Signal:
+1: RSI < oversold level (e.g., < 30) → potential bullish reversal.

-1: RSI > overbought level (e.g., > 70) → potential bearish reversal.

0: Otherwise.

Logic: Extreme RSI values suggest price may reverse.

MACD Signal:
+1: MACD line > signal line → bullish momentum.

-1: MACD line < signal line → bearish momentum.

0: Equal.

Logic: Crossovers indicate trend shifts.

A/D Signal:
+1: Current A/D > previous A/D → accumulation (bullish).

-1: Current A/D < previous A/D → distribution (bearish).

0: Unchanged.

Logic: Rising A/D shows buying pressure.

Volume Signal:
+1: Volume > high threshold (e.g., 1.5 × volume MA) → strong activity (bullish).

-1: Volume < low threshold (e.g., 0.5 × volume MA) → weak activity (bearish).

0: Otherwise.

Logic: Volume spikes often confirm reversals.

Price Signal:
+1: Close near support (within proximity %, e.g., 2%) → potential bounce.

-1: Close near resistance (within proximity %) → potential rejection.

0: Otherwise.

Logic: Price near key levels signals reversal zones.

4. Composite Score
The raw composite score is the sum of the five signals:
Formula: score = rsi_signal + macd_signal + ad_signal + vol_signal + price_signal

Range: -5 (all signals bearish) to +5 (all signals bullish).

Purpose: Combines multiple perspectives into one number.

5. Smoothed Score
A smoothed version of the score reduces noise:
Formula: score_ma = ta.sma(score, score_ma_length)

Example: With a length of 5, it averages the score over 5 bars.

Purpose: Highlights the trend rather than short-term fluctuations.

6. Visualization
The indicator plots two elements:
Raw Score: A gray histogram showing the composite score per bar.
Style: plot.style_histogram

Color: Gray.

Smoothed Score: A line that changes color:
Green: Score > 0 (bullish).

Red: Score < 0 (bearish).

Gray: Score = 0 (neutral).

Style: plot.style_line, thicker line (e.g., linewidth=2).

These visuals make it easy to spot potential reversals.
How It Works Together
The indicator combines signals from:
RSI: Momentum extremes.

MACD: Trend shifts.

A/D: Buying/selling pressure.

Volume: Confirmation of moves.

Price Levels: Key reversal zones.

By summing these into a composite score, it filters out noise and provides a unified signal. A high positive score (e.g., +3 to +5) suggests a bullish reversal, while a low negative score (e.g., -3 to -5) suggests a bearish reversal. The smoothed score helps traders focus on the trend.
Practical Use
Bullish Reversal: Smoothed score is green and rising → look for buying opportunities.

Bearish Reversal: Smoothed score is red and falling → consider selling or shorting.

Neutral: Score near 0 → wait for clearer signals.

Traders can adjust inputs to suit their strategy, making it versatile for stocks, forex, or crypto.

Aviso legal

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.