OPEN-SOURCE SCRIPT

Better MACD

125
📘 Better MACD – Adaptive Momentum & Divergence Suite
Better MACD is a comprehensive momentum-trend tool that evolves the traditional MACD into a multi-dimensional, divergence-aware oscillator. It leverages exponential smoothing across logarithmic rate-of-change of OHLC data, adaptive signal processing, and intelligent divergence detection logic to provide traders with earlier, smoother, and more reliable momentum signals.

This indicator is built for professional-level analysis, suitable for scalping, swing trading, and trend-following systems.

🧬 Core Concept
Unlike the classic MACD which subtracts two EMAs of price, Better MACD constructs a signal by:

Applying logarithmic transformation on the change between OHLC components (Close, High, Low, Open).

Using double EMA smoothing to filter noise and volatility, Triangular method. 1st to 2nd Smoothing.

Averaging and de-biasing the results through a custom linear regression model, 4th Smoothing.

Subtracting a fast SMA and slow SMA response to yield a dynamic MACD value, 3rd Smoothing.

The result is a smooth, adaptive, and high-resolution MACD-style oscillator that responds more naturally to trend conditions and price geometry.

🧠 Features Breakdown
1. 📈 Multi-Layer MACD Engine
Src1: Smoothed Log Rate-of-Change on Close

Src2: Smoothed Log Rate-of-Change on High

Src3: Smoothed Log Rate-of-Change on Low

Src4: Smoothed Log Rate-of-Change on Open

These are blended using highest high, lowest low, and average Close price over a configurable window for more complete trend detection. The open-based Src4 is subtracted using SMA.

2. 🧮 Signal Line
A fast EMA (signalLength) of the Better MACD value is used for crossover logic.

Crossovers of MACD and Signal line signal potential entries or exits.

3. 📊 MACD Histogram
Visualizes the difference between MACD and Signal line.

Dynamically color-coded:

Green/Light Green for bullish impulse

Red/Pink for bearish impulse

Width and color intensity reflect strength and momentum slope.

🎨 Visual Enhancements
Feature Description
✅ Ribbon Fill Optional fill between MACD and Signal line, colored by trend direction
✅ Zero-Line Background Background highlights above/below 0 to easily read bullish/bearish bias
✅ Crossover Highlights Tiny circles plotted when MACD crosses Signal line

🔍 Divergence Detection Suite
The script includes a full Divergence Engine to detect:

🔼 Bullish Regular Divergence (Price lower lows + Indicator higher lows)

🔽 Bearish Regular Divergence (Price higher highs + Indicator lower highs)

🟢 Bullish Hidden Divergence (Price higher lows + Indicator lower lows)

🔴 Bearish Hidden Divergence (Price lower highs + Indicator higher highs)

🧩 Divergence Modes:
Supports both Regular, Hidden, or Both simultaneously

Detects from either Close Price or Heikin Ashi-derived candles

Uses dynamic pivot tracking with configurable lookback and divergence sensitivity

Divergence lines are labeled, colored, and plotted in real-time

🔁 Styling & Customization:
Choose from Solid, Dashed, or Dotted line styles

Configure separate colors and widths for all divergence types

Control number of divergence lines visible or only show the most recent

Divergences update live without repainting

⚠️ Alerts
Alerts are built-in for real-time notification:

MACD Histogram reversals (rising → falling, or vice versa)

Divergence signals (all 4 types, grouped and individually)

Combines seamlessly with TradingView alerts for actionable triggers

🔧 Input Controls (Grouped by Purpose)
Better MACD Group
1st–4th Smoothing Lengths: Controls responsiveness of MACD core engine

Signal Length: Smoothness of signal line

Toggles for crossover highlights, zero cross fills, and ribbon fills

Divergence Settings
Enable/disable divergence lines

Choose divergence type (Regular, Hidden, Both)

Set confirmation requirements

Customize pivot detection and bar search depth

Styling Options
Colors, line widths, and line styles for each divergence type

Heikin Ashi Mode for smoother pivots and divergences

🧠 How to Use
✅ For Trend Traders:
Use MACD > Signal + Histogram > 0 → Bullish confirmation

MACD < Signal + Histogram < 0 → Bearish confirmation

Wait for pullbacks with hidden divergences to enter in trend direction

✅ For Reversal Traders:
Look for Regular Divergences at trend exhaustion points

Combine with price action (e.g., support/resistance or candle pattern)

✅ For Swing & Day Traders:
Enable Heikin Ashi Mode for smoother divergence pivots

Use zero line background + histogram color to time entries

📌 Summary
Feature Description
🚀 Advanced MACD Core Smoother, more reliable, multi-source-based MACD
🔍 Divergence Engine Detects 4 divergence types with pivot logic
🎯 Real-Time Alerts Alerts for histogram slope and divergences
🎛️ Deep Customization Full styling, smoothing, and detection controls
📉 Heikin Ashi Support Improved signal quality in trend-based markets

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.