OPEN-SOURCE SCRIPT

Scientific MACD

190
Scientific MACD v5.1 — User Guide
An advanced momentum oscillator featuring eight scientifically-modeled moving average algorithms with adaptive signal generation and real-time calculation stability.
Overview
This indicator reimagines the traditional MACD through the lens of multiple scientific disciplines. Rather than relying on simple exponential moving averages, it offers eight distinct mathematical frameworks for calculating trend components—each derived from physics, biology, information theory, or behavioral science. The result is a highly adaptive momentum system that adjusts its sensitivity to market conditions through dynamic error-tracking and hybrid ensemble methods.
Core Architecture
Three-Component Structure
Like the classic MACD, this indicator maintains three essential elements:
  • []Fast Line: Short-term trend component (default: 12 periods)
    []Slow Line: Long-term trend component (default: 26 periods)
  • Signal Line: Smoothed derivative of the MACD line (default: 9 periods)

Independent Algorithm Selection
Each component can use any of the eight available moving average types independently. This allows sophisticated combinations such as Wave fast + Entropy slow + Synaptic signal, creating multi-domain confirmation systems.
Scientific Moving Average Models
1. Wave Mechanics MA
A Fourier-inspired bandpass filter that decomposes price into harmonic components. Uses multiple sine wave harmonics (fundamental + overtones) centered around a mean price, with amplitude derived from period range. Higher harmonics receive decreasing weights. Ideal for identifying cyclical price structures and filtering noise through frequency domain analysis.
2. Thermodynamic Entropy MA
Applies information theory concepts to market returns. Calculates Shannon entropy across a 5-bin probability distribution of returns, then uses entropy ratio to adapt smoothing intensity. High entropy (disorder) increases smoothing; low entropy (trending) decreases smoothing. Adds small entropy-based adjustments to center the moving average.
3. Biological Synaptic MA
Implements Hebbian learning rules from neural biology. Maintains adaptive weights for recent price history that strengthen when current price movements correlate with past movements (associative learning). Weights decay exponentially with time and normalize between 0.5 and 2.0. Excels at capturing momentum persistence and regime changes.
4. Quantum Uncertainty MA
Models price as a quantum superposition of states with probabilistic amplitudes. Uses Gaussian distance functions to project current price onto historical basis states, then calculates expectation values. Incorporates decoherence (mixing with previous states) for stability. Naturally handles uncertainty and provides smooth transitions between trend states.
5. Fluid Dynamics MA
Treats price movement as fluid flow with Reynolds number classification. Calculates characteristic velocity, viscosity, and Reynolds number to determine flow regime. Laminar flow (low Re) uses diffusion-dominated smoothing; turbulent flow (high Re) uses advection-dominated smoothing. Includes stability clamps to prevent extreme deviations.
6. Network Cascade MA
Applies epidemiological SIR (Susceptible-Infected-Recovered) models to price trends. Models trend strength as infection rate spreading through market participants. Adaptive smoothing based on active infections (trend strength) with mean reversion as recovery increases. Beta parameter derived from return surprises relative to volatility.
7. Behavioral Economics MA
Incorporates Prospect Theory from psychology. Maintains an adaptation level (reference point) that updates slowly. Applies Tversky-Kahneman value functions with loss aversion (lambda = 2.25) and diminishing sensitivity (alpha = 0.88). Weights prices by psychological value rather than linear distance, emphasizing gains/losses relative to perceived anchors.
8. Hybrid Ensemble MA
Combines all seven models through inverse-error weighting. Tracks exponential moving average of prediction errors for each component model, then assigns weights inversely proportional to recent error. Automatically favors whichever scientific model best fits current market conditions. Displays real-time weight distribution table when enabled.
Signal Generation
Quality-Filtered Crossovers
Standard MACD crossovers are enhanced with statistical quality gates:
  • []Bull Signal: MACD crosses above Signal while MACD is below zero and histogram exceeds 80th percentile of recent values
    []Bear Signal: MACD crosses below Signal while MACD is above zero and histogram below 20th percentile of recent values

High-Quality Signals
Additional filter requiring signal quality ratio (histogram magnitude divided by histogram volatility) to exceed 2.0. These appear as HQ↑ and HQ↓ markers, indicating statistically significant momentum shifts.
Visualization Features
Dynamic Color Coding
  • []MACD Line: Lime/olive when above signal (bullish), red/maroon when below (bearish)
    []Histogram: Intensity varies with signal quality—brighter colors indicate stronger statistical significance
    []Signal Line: Orange for clear differentiation
    []Zero Line: Dashed gray reference
  • Volatility Zone: Gray fill between ±1 standard deviation of MACD values

Hybrid Weight Display
When Hybrid MA is selected and Show Hybrid Weights is enabled, a real-time table displays current ensemble weightings for all seven component models as percentages. Updates dynamically as market conditions favor different scientific approaches.
Key Input Parameters
Core Settings
  • []Fast Length: Short-term lookback (2-200, default 12)
    []Slow Length: Long-term lookback (3-500, default 26)
  • Signal Length: Smoothing period for signal line (2-100, default 9)

Scientific Parameters
  • []ZigZag Detection Depth: Influences cyclicality measures in Wave and Fluid models (3-20, default 5)
    []Real-Time Calculation Fix: Blends calculated values with current price during unconfirmed bars to prevent repainting artifacts

MA Configuration
Independent algorithm selection for Fast, Slow, and Signal components. Options: Wave, Entropy, Synaptic, Quantum, Fluid, Cascade, Behavioral, Hybrid.
Display Settings
Toggle for Hybrid weight table visibility.
Operational Workflow
  1. []Select appropriate lengths for your timeframe and trading style
    []Choose MA algorithms based on market characteristics:
    []Trending markets: Synaptic, Cascade, or Behavioral
    []Cyclical/ranging markets: Wave or Quantum
    []High volatility: Entropy or Fluid
    []Unknown regime: Hybrid (adaptive ensemble)
    []Enable Real-Time Calculation Fix for live trading to prevent repainting
    []Monitor standard crossovers for entry signals
    []Prioritize HQ (High Quality) signals for lower-risk entries
    []Use histogram color intensity to gauge signal strength
  2. When using Hybrid, monitor weight table to understand which models are currently dominant

Best Practices
  • []Use longer lengths (20-50-10) for swing trading, standard (12-26-9) for day trading
    []Combine complementary algorithms: fast Wave + slow Entropy captures cycles within noise-filtered trends
    []Enable Hybrid during regime uncertainty—it automatically selects optimal models
    []Disable Real-Time Calculation Fix for historical analysis, enable for live signals
    []Watch for divergence between MACD and price while monitoring histogram quality for confirmation
    []Volatility zone fill helps identify when MACD moves reach statistical extremes

This indicator provides mathematically sophisticated trend analysis. Algorithm selection significantly impacts signal characteristics—experiment with combinations to find optimal fit for your market and timeframe.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.