PROTECTED SOURCE SCRIPT
Mis à jour

Malama's Quantum Swing Modulator

285
# Multi-Indicator Swing Analysis with Probability Scoring

## What Makes This Script Original

This script combines pivot point detection with a **weighted scoring system** that dynamically adjusts indicator weights based on market regime (trending vs. ranging). Unlike standard multi-indicator approaches that use fixed weightings, this implementation uses ADX to detect market conditions and automatically rebalances the influence of RSI, MFI, and price deviation components accordingly.

## Core Methodology

**Dynamic Weight Allocation System:**
- **Trending Markets (ADX > 25):** Prioritizes momentum (50% weight) with reduced oscillator influence (20% each for RSI/MFI)
- **Ranging Markets (ADX < 25):** Emphasizes mean reversion signals (40% each for RSI/MFI) with no momentum bias
- **Price Wave Component:** Uses EMA deviation normalized by ATR to measure distance from central tendency

**Pivot-Based Level Analysis:**
- Detects swing highs/lows using configurable left/right lookback periods
- Maintains the most recent pivot levels as key reference points
- Calculates proximity scores based on current price distance from these levels

**Volume Confirmation Logic:**
- Defines "volume entanglement" when current volume exceeds SMA by user-defined factor
- Integrates volume confirmation into confidence scoring rather than signal generation

## Technical Implementation Details

**Scoring Algorithm:**
The script calculates separate bullish and bearish "superposition" scores using:
```
Bullish Score = (RSI_bull × weight) + (MFI_bull × weight) + (price_wave × weight × position_filter) + (momentum × weight)
```

Where:
- RSI_bull = 100 - RSI (inverted for oversold bias)
- MFI_bull = 100 - MFI (inverted for oversold bias)
- Position_filter = Only applies when price is below EMA for bullish signals
- Momentum component = Only active in trending markets

**Confidence Calculation:**
Base confidence starts at 25% and increases based on:
- Market regime alignment (trending/ranging appropriate conditions)
- Volume confirmation presence
- Oscillator extreme readings (RSI < 30 or > 70 in ranging markets)
- Price position relative to wave function (EMA)

**Probability Output:**
Final probability = (Base Score × 0.6) + (Proximity Score × 0.4)
This balances indicator confluence with proximity to identified levels.

## Key Differentiators

**vs. Standard Multi-Indicator Scripts:** Uses regime-based dynamic weighting instead of fixed combinations
**vs. Simple Pivot Indicators:** Adds quantified probability and confidence scoring to pivot levels
**vs. Basic Oscillator Combinations:** Incorporates market structure analysis through ADX regime detection

## Visual Components

**Wave Function Display:** EMA with ATR-based uncertainty bands for trend context
**Pivot Markers:** Clear visualization of detected swing highs and lows
**Analysis Table:** Real-time probability, confidence, and action recommendations for current pivot levels

## Practical Application

The dynamic weighting system helps avoid common pitfalls of multi-indicator analysis:
- Reduces oscillator noise during strong trends by emphasizing momentum
- Increases mean reversion sensitivity during sideways markets
- Provides quantified probability rather than subjective signal interpretation

## Important Limitations

- Requires sufficient historical data for pivot detection and volume calculations
- Probability scores are based on current market regime and may change as conditions evolve
- The scoring system is designed for confluence analysis, not standalone trading decisions
- Past probability accuracy does not guarantee future performance

## Technical Requirements

- Works on all timeframes but requires adequate lookback history
- Volume data required for entanglement calculations
- Best suited for liquid instruments where volume patterns are meaningful

This approach provides a systematic framework for evaluating swing trading opportunities while acknowledging the probabilistic nature of technical analysis.
Notes de version
Malama's Quantum Swing Modulator (MQSM) is an overlay indicator inspired by quantum mechanics principles to analyze swing structures and potential reversal zones. It identifies key support and resistance levels from recent pivots, then assigns probability and confidence scores for trading actions like buying dips near support or selling rallies near resistance. By blending momentum oscillators, volume dynamics, and market regime detection, it helps swing traders gauge when price is "entangled" in high-conviction setups versus uncertain ranges. This version corrects logical flaws from prior iterations, adds runtime safeguards, and enhances input flexibility for more reliable signals across assets like stocks, forex, or crypto.

Core Mechanics
The indicator simulates quantum concepts to process price action:

Wave Function Center: A smoothed exponential moving average (EMA) of closing prices acts as the "equilibrium" path, revealing the underlying trend bias.
Uncertainty Zones: Bands around the EMA, derived from Average True Range (ATR) multiplied by a user factor, highlight areas of expected volatility—price inside suggests ranging indecision, outside indicates potential extremes.
Superposition Scoring: Combines normalized scores from RSI (Relative Strength Index) and MFI (Money Flow Index) for mean-reversion signals, weighted by price deviation from the EMA (favoring oversold/near-support for buys). In trending regimes, it shifts emphasis to short-term momentum alignment.
Entanglement Filter: Detects volume spikes (above a multiple of recent average) to boost conviction, as high volume often "entangles" price with institutional interest.
Regime Detection: Uses ADX (Average Directional Index) with separate directional index (DI) length and smoothing periods to classify markets as trending (high ADX) or ranging (low ADX), dynamically adjusting score weights—e.g., oscillators dominate in ranges for reversion plays, momentum in trends for continuation.
Pivot Levels: Automatically spots swing highs/lows using left/right bar lookbacks, treating them as dynamic support/resistance.

For each level, it computes:

Probability: 60% from superposition scores + 40% from proximity to current price (normalized by ATR; closer = higher).
Confidence: Starts at 25%, adding for favorable EMA position (+15%), volume spikes (+25%), trend-aligned momentum (+15% in trends), or extreme oscillator readings (+20% in ranges). Capped at 100%.
Actions trigger at thresholds: >75% probability = "Buy Near" (support) or "Sell Near" (resistance); 50-75% = "Monitor"; <50% = "Avoid."

Key Improvements in This Version

Runtime Stability: Added safeguards against rare ATR zero values in deviation and proximity calcs, preventing division errors.
Intuitive Confidence Logic: Now boosts scores when momentum aligns with the trade direction (e.g., positive momentum for support buys in uptrends), fixing prior counterintuitive penalties.
Flexible Regime Inputs: Split ADX into independent DI length and smoothing for standard tuning (e.g., 14/14), improving accuracy over fixed periods.
Cleaner Structure: Organized code into sections for easier reading, with descriptive comments; table header updated to "MQSM" for brevity.

How to Use

Add to Chart: Defaults suit most swing setups on 1H-4H timeframes for liquid assets. Adjust pivot hands (e.g., 10/5 for shorter swings) or ATR multiplier (1.5 for tighter zones).
Interpret Visuals:

White EMA line: Trend baseline.
Gray-filled ATR bands: Stay inside for caution, outside for extremes.
Blue/red circles: Confirmed swing lows/highs (delayed by right-hand bars).


Table Guidance (top-right by default):

Support Row: Green cells for "Buy Near" (high prob/conf >75%)—consider longs if price nears the level with volume.
Resistance Row: Red for "Sell Near"—shorts on approaches.
Gray: Monitor or avoid low-confidence zones.


Trading Tips: Use on higher timeframes for pivots, lower for entries. Pair with overall trend (e.g., only buy supports in bull markets). Set alerts on table actions. Test on historical data to tune for your asset.

Why This Mashup Adds Value
While drawing from standard tools like EMA, ATR, RSI, MFI, and ADX, MQSM uniquely "quantizes" them into a probabilistic framework: Superposition weights adapt via regime detection to avoid over-relying on oscillators in trends (where they lag) or ignoring momentum in ranges (where reversion shines). Volume entanglement adds a conviction layer missing in basic pivot scripts, while normalized proximity ensures scores scale across volatilities. This holistic integration reduces noise—e.g., a support near EMA low with volume spike and positive momentum scores 90%+ probability—making it more actionable than standalone indicators. It's original for educational swing analysis, not a rehash, as the dynamic weighting and quantum-themed heuristics create emergent signals not found in simple combos.
Limitations & Disclaimer
Pivots confirm with delay (right-hand bars), so signals lag real-time swings—best for planning, not scalping. Scores assume mean-reversion bias near levels but can underperform in prolonged trends without manual filters. ATR normalization helps, but extreme volatility (e.g., news) may skew zones. Not financial advice; backtest thoroughly and risk only what you can afford. Past performance isn't indicative of future results. For questions, comment below.
Notes de version
Malama's Quantum Swing Modulator (MQSM) is an overlay indicator inspired by quantum mechanics principles to analyze swing structures and potential reversal zones. It identifies key support and resistance levels from recent pivots, then assigns probability and confidence scores for trading actions like buying dips near support or selling rallies near resistance. By blending momentum oscillators, volume dynamics, and market regime detection, it helps swing traders gauge when price is "entangled" in high-conviction setups versus uncertain ranges. This version corrects logical flaws from prior iterations, adds runtime safeguards, and enhances input flexibility for more reliable signals across assets like stocks, forex, or crypto.
Core Mechanics
The indicator simulates quantum concepts to process price action:

Wave Function Center: A smoothed exponential moving average (EMA) of closing prices acts as the "equilibrium" path, revealing the underlying trend bias.
Uncertainty Zones: Bands around the EMA, derived from Average True Range (ATR) multiplied by a user factor, highlight areas of expected volatility—price inside suggests ranging indecision, outside indicates potential extremes.
Superposition Scoring: Combines normalized scores from RSI (Relative Strength Index) and MFI (Money Flow Index) for mean-reversion signals, weighted by price deviation from the EMA (favoring oversold/near-support for buys). In trending regimes, it shifts emphasis to short-term momentum alignment.
Entanglement Filter: Detects volume spikes (above a multiple of recent average) to boost conviction, as high volume often "entangles" price with institutional interest.
Regime Detection: Uses ADX (Average Directional Index) with separate directional index (DI) length and smoothing periods to classify markets as trending (high ADX) or ranging (low ADX), dynamically adjusting score weights—e.g., oscillators dominate in ranges for reversion plays, momentum in trends for continuation.
Pivot Levels: Automatically spots swing highs/lows using left/right bar lookbacks, treating them as dynamic support/resistance.

For each level, it computes:

Probability: 60% from superposition scores + 40% from proximity to current price (normalized by ATR; closer = higher).
Confidence: Starts at 25%, adding for favorable EMA position (+15%), volume spikes (+25%), trend-aligned momentum (+15% in trends), or extreme oscillator readings (+20% in ranges). Capped at 100%.
Actions trigger at thresholds: >75% probability = "Buy Near" (support) or "Sell Near" (resistance); 50-75% = "Monitor"; <50% = "Avoid."

Key Improvements in This Version

Runtime Stability: Added safeguards against rare ATR zero values in deviation and proximity calcs, preventing division errors.
Intuitive Confidence Logic: Now boosts scores when momentum aligns with the trade direction (e.g., positive momentum for support buys in uptrends), fixing prior counterintuitive penalties.
Flexible Regime Inputs: Split ADX into independent DI length and smoothing for standard tuning (e.g., 14/14), improving accuracy over fixed periods.
Cleaner Structure: Organized code into sections for easier reading, with descriptive comments; table header updated to "MQSM" for brevity.

How to Use

Add to Chart: Defaults suit most swing setups on 1H-4H timeframes for liquid assets. Adjust pivot hands (e.g., 10/5 for shorter swings) or ATR multiplier (1.5 for tighter zones).
Interpret Visuals:

White EMA line: Trend baseline.
Gray-filled ATR bands: Stay inside for caution, outside for extremes.
Blue/red circles: Confirmed swing lows/highs (delayed by right-hand bars).


Table Guidance (top-right by default):

Support Row: Green cells for "Buy Near" (high prob/conf >75%)—consider longs if price nears the level with volume.
Resistance Row: Red for "Sell Near"—shorts on approaches.
Gray: Monitor or avoid low-confidence zones.


Trading Tips: Use on higher timeframes for pivots, lower for entries. Pair with overall trend (e.g., only buy supports in bull markets). Set alerts on table actions. Test on historical data to tune for your asset.

Why This Mashup Adds Value
While drawing from standard tools like EMA, ATR, RSI, MFI, and ADX, MQSM uniquely "quantizes" them into a probabilistic framework: Superposition weights adapt via regime detection to avoid over-relying on oscillators in trends (where they lag) or ignoring momentum in ranges (where reversion shines). Volume entanglement adds a conviction layer missing in basic pivot scripts, while normalized proximity ensures scores scale across volatilities. This holistic integration reduces noise—e.g., a support near EMA low with volume spike and positive momentum scores 90%+ probability—making it more actionable than standalone indicators. It's original for educational swing analysis, not a rehash, as the dynamic weighting and quantum-themed heuristics create emergent signals not found in simple combos.
Limitations & Disclaimer
Pivots confirm with delay (right-hand bars), so signals lag real-time swings—best for planning, not scalping. Scores assume mean-reversion bias near levels but can underperform in prolonged trends without manual filters. ATR normalization helps, but extreme volatility (e.g., news) may skew zones. Not financial advice; backtest thoroughly and risk only what you can afford. Past performance isn't indicative of future results. For questions, comment below.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.