INVITE-ONLY SCRIPT
Kernel Market Dynamics [WFO - MAB]

Kernel Market Dynamics [WFO - MAB]
⚛️ CORE INNOVATION: KERNEL-BASED DISTRIBUTION ANALYSIS
The Kernel Market Dynamics system represents a fundamental departure from traditional technical indicators. Rather than measuring price levels, momentum, or oscillator extremes, KMD analyzes the statistical distribution of market returns using advanced kernel methods from machine learning theory. This allows the system to detect when market behavior has fundamentally changed—not just when price has moved, but when the underlying probability structure has shifted.
The Distribution Hypothesis:
Traditional indicators assume markets move in predictable patterns. KMD assumes something more profound: markets exist in distinct distributional regimes, and profitable trading opportunities emerge during regime transitions. When the distribution of recent returns diverges significantly from the historical baseline, the market is restructuring—and that's when edge exists.
Maximum Mean Discrepancy (MMD):
At the heart of KMD lies a sophisticated statistical metric called Maximum Mean Discrepancy. MMD measures the distance between two probability distributions by comparing their representations in a high-dimensional feature space created by a kernel function.
The Mathematics:
Given two sets of normalized returns:
• Reference period (X): Historical baseline (default 100 bars)
• Test period (Y): Recent behavior (default 20 bars)
MMD is calculated as:
MMD² = E[k(X,X)] + E[k(Y,Y)] - 2·E[k(X,Y)]
Where:
• E[k(X,X)] = Expected kernel similarity within reference period
• E[k(Y,Y)] = Expected kernel similarity within test period
• E[k(X,Y)] = Expected cross-similarity between periods
When MMD is low: Test period behaves like reference (stable regime)
When MMD is high: Test period diverges from reference (regime shift)
The final MMD value is smoothed with EMA(5) to reduce single-bar noise while maintaining responsiveness to genuine distribution changes.
The Kernel Functions:
The kernel function defines how similarity is measured. KMD offers four mathematically distinct kernels, each with different properties:
1. RBF (Radial Basis Function / Gaussian):
• Formula: k(x,y) = exp(-d² / (2·σ²·scale))
• Properties: Most sensitive to distribution changes, smooth decision boundaries
• Best for: Clean data, clear regime shifts, low-noise markets
• Sensitivity: Highest - detects subtle changes
• Use case: Stock indices, major forex pairs, trending environments
2. Laplacian:
• Formula: k(x,y) = exp(-|d| / σ)
• Properties: Medium sensitivity, robust to moderate outliers
• Best for: Standard market conditions, balanced noise/signal
• Sensitivity: Medium - filters minor fluctuations
• Use case: Commodities, standard timeframes, general trading
3. Cauchy (Default - Most Robust):
• Formula: k(x,y) = 1 / (1 + d²/σ²)
• Properties: Heavy-tailed, highly robust to outliers and spikes
• Best for: Noisy markets, choppy conditions, crypto volatility
• Sensitivity: Lower - only major distribution shifts trigger
• Use case: Cryptocurrencies, illiquid markets, volatile instruments
4. Rational Quadratic:
• Formula: k(x,y) = (1 + d²/(2·α·σ²))^(-α)
• Properties: Tunable via alpha parameter, mixture of RBF kernels
• Alpha < 1.0: Heavy tails (like Cauchy)
• Alpha > 3.0: Light tails (like RBF)
• Best for: Adaptive use, mixed market conditions
• Use case: Experimental optimization, regime-specific tuning
Bandwidth (σ) Parameter:
The bandwidth controls the "width" of the kernel, determining sensitivity to return differences:
• Low bandwidth (0.5-1.5): Narrow kernel, very sensitive
- Treats small differences as significant
- More MMD spikes, more signals
- Use for: Scalping, fast markets
• Medium bandwidth (1.5-3.0): Balanced sensitivity (recommended)
- Filters noise while catching real shifts
- Professional-grade signal quality
- Use for: Day/swing trading
• High bandwidth (3.0-10.0): Wide kernel, less sensitive
- Only major distribution changes register
- Fewer, stronger signals
- Use for: Position trading, trend following
Adaptive Bandwidth:
When enabled (default ON), bandwidth automatically scales with market volatility:
Effective_BW = Base_BW × max(0.5, min(2.0, 1 / volatility_ratio))
• Low volatility → Tighter bandwidth (0.5× base) → More sensitive
• High volatility → Wider bandwidth (2.0× base) → Less sensitive
This prevents signal flooding during wild markets and avoids signal drought during calm periods.
Why Kernels Work:
Kernel methods implicitly map data to infinite-dimensional space where complex, nonlinear patterns become linearly separable. This allows MMD to detect distribution changes that simpler statistics (mean, variance) would miss. For example:
• Same mean, different shape: Traditional metrics see nothing, MMD detects shift
• Same volatility, different skew: Oscillators miss it, MMD catches it
• Regime rotation: Price unchanged, but return distribution restructured
The kernel captures the entire distributional signature—not just first and second moments.
🎰 MULTI-ARMED BANDIT FRAMEWORK: ADAPTIVE STRATEGY SELECTION
Rather than forcing one strategy on all market conditions, KMD implements a Multi-Armed Bandit (MAB) system that learns which of seven distinct strategies performs best and dynamically selects the optimal approach in real-time.
The Seven Arms (Strategies):
Each arm represents a fundamentally different trading logic:
ARM 0 - MMD Regime Shift:
• Logic: Distribution divergence with directional bias
• Triggers: MMD > threshold AND direction_bias confirmed AND velocity > 5%
• Philosophy: Trade the regime transition itself
• Best in: Volatile shifts, breakout moments, crisis periods
• Weakness: False alarms in choppy consolidation
ARM 1 - Trend Following:
• Logic: Aligned EMAs with strong ADX
• Triggers: EMA(9) > EMA(21) > EMA(50) AND ADX > 25
• Philosophy: Ride established momentum
• Best in: Strong trending regimes, directional markets
• Weakness: Late entries, whipsaws at reversals
ARM 2 - Breakout:
• Logic: Bollinger Band breakouts with volume
• Triggers: Price crosses BB outer band AND volume > 1.2× average
• Philosophy: Capture volatility expansion events
• Best in: Range breakouts, earnings, news events
• Weakness: False breakouts in ranging markets
ARM 3 - RSI Mean Reversion:
• Logic: RSI extremes with reversal confirmation
• Triggers: RSI < 30 with uptick OR RSI > 70 with downtick
• Philosophy: Fade overbought/oversold extremes
• Best in: Ranging markets, mean-reverting instruments
• Weakness: Fails in strong trends, catches falling knives
ARM 4 - Z-Score Statistical Reversion:
• Logic: Price deviation from 50-period mean
• Triggers: Z-score < -2 (oversold) OR > +2 (overbought) with reversal
• Philosophy: Statistical bounds reversion
• Best in: Stable volatility regimes, pairs trading
• Weakness: Trend continuation through extremes
ARM 5 - ADX Momentum:
• Logic: Strong directional movement with acceleration
• Triggers: ADX > 30 with DI+ or DI- strengthening
• Philosophy: Momentum begets momentum
• Best in: Trending with increasing velocity
• Weakness: Late exits, momentum exhaustion
ARM 6 - Volume Confirmation:
• Logic: OBV trend + volume spike + candle direction
• Triggers: OBV > EMA(20) AND volume > average AND bullish candle
• Philosophy: Follow institutional money flow
• Best in: Liquid markets with reliable volume
• Weakness: Manipulated volume, thin markets
Q-Learning with Rewards:
Each arm maintains a Q-value representing its expected reward. After every bar, the system calculates a reward based on the arm's signal and actual price movement:
Reward Calculation:
If arm signaled LONG:
reward = (close - close[1]) / close[1]
If arm signaled SHORT:
reward = -(close - close[1]) / close[1]
If arm signaled NEUTRAL:
reward = 0
Penalty multiplier: If loss > 0.5%, reward × 1.3 (punish big losses harder)
Q-Value Update (Exponential Moving Average):
Q_new = Q_old + α × (reward - Q_old)
Where α (learning rate, default 0.08) controls adaptation speed:
• Low α (0.01-0.05): Slow, stable learning
• Medium α (0.06-0.12): Balanced (recommended)
• High α (0.15-0.30): Fast, reactive learning
This gradually shifts Q-values toward arms that generate positive returns and away from losing arms.
Arm Selection Algorithms:
KMD offers four mathematically distinct selection strategies:
1. UCB1 (Upper Confidence Bound) - Recommended:
Formula: Select arm with max(Q_i + c·√(ln(t)/n_i))
Where:
• Q_i = Q-value of arm i
• c = exploration constant (default 1.5)
• t = total pulls across all arms
• n_i = pulls of arm i
Philosophy: Balance exploitation (use best arm) with exploration (try uncertain arms). The √(ln(t)/n_i) term creates an "exploration bonus" that decreases as an arm gets more pulls, ensuring all arms get sufficient testing.
Theoretical guarantee: Logarithmic regret bound - UCB1 provably converges to optimal arm selection over time.
2. UCB1-Tuned (Variance-Aware UCB):
Formula: Select arm with max(Q_i + √(ln(t)/n_i × min(0.25, V_i + √(2·ln(t)/n_i))))
Where V_i = variance of rewards for arm i
Philosophy: Incorporates reward variance into exploration. Arms with high variance (unpredictable) get less exploration bonus, focusing effort on stable performers.
Better bounds than UCB1 in practice, slightly more conservative exploration.
3. Epsilon-Greedy (Simple Random):
Algorithm:
With probability ε: Select random arm (explore)
With probability 1-ε: Select highest Q-value arm (exploit)
Default ε = 0.10 (10% exploration, 90% exploitation)
Philosophy: Simplest algorithm, easy to understand. Random exploration ensures all arms stay updated but may waste time on clearly bad arms.
4. Thompson Sampling (Bayesian):
The most sophisticated selection algorithm, using true Bayesian probability.
Each arm maintains Beta distribution parameters:
• α (alpha) = successes + 1
• β (beta) = failures + 1
Selection Process:
1. Sample θ_i ~ Beta(α_i, β_i) for each arm using Marsaglia-Tsang Gamma sampler
2. Select arm with highest sample: argmax_i(θ_i)
3. After reward, update:
- If reward > 0: α += |reward| × 100 (increment successes)
- If reward < 0: β += |reward| × 100 (increment failures)
Why Thompson Sampling Works:
The Beta distribution naturally represents uncertainty about an arm's true win rate. Early on with few trials, the distribution is wide (high uncertainty), leading to more exploration. As evidence accumulates, it narrows around the true performance, naturally shifting toward exploitation.
Unlike UCB which uses deterministic confidence bounds, Thompson Sampling is probabilistic—it samples from the posterior distribution of each arm's success rate, providing automatic exploration/exploitation balance without tuning.
Comparison:
• UCB1: Deterministic, guaranteed regret bounds, requires tuning exploration constant
• Thompson: Probabilistic, natural exploration, no tuning required, best empirical performance
• Epsilon-Greedy: Simplest, consistent exploration %, less efficient
• UCB1-Tuned: UCB1 + variance awareness, best for risk-averse
Exploration Constant (c):
For UCB algorithms, this multiplies the exploration bonus:
• Low c (0.5-1.0): Strongly prefer proven arms, rare exploration
• Medium c (1.2-1.8): Balanced (default 1.5)
• High c (2.0-3.0): Frequent exploration, diverse arm usage
Higher exploration constant in volatile/unstable markets, lower in stable trending environments.
🔬 WALK-FORWARD OPTIMIZATION: PREVENTING OVERFITTING
The single biggest problem in algorithmic trading is overfitting—strategies that look amazing in backtest but fail in live trading because they learned noise instead of signal. KMD's Walk-Forward Optimization system addresses this head-on.
How WFO Works:
The system divides time into repeating cycles:
1. Training Window (default 500 bars): Learn arm Q-values on historical data
2. Testing Window (default 100 bars): Validate on unseen "future" data
Training Phase:
• All arms accumulate rewards and update Q-values normally
• Q_train tracks in-sample performance
• System learns which arms work on historical data
Testing Phase:
• System continues using arms but tracks separate Q_test metrics
• Counts trades per arm (N_test)
• Testing performance is "out-of-sample" relative to training
Validation Requirements:
An arm is only "validated" (approved for live use) if:
1. N_test ≥ Minimum Trades (default 10): Sufficient statistical sample
2. Q_test > 0: Positive out-of-sample performance
Arms that fail validation are blocked from generating signals, preventing the system from trading strategies that only worked on historical data.
Performance Decay:
At the end of each WFO cycle, all Q-values decay exponentially:
Q_new = Q_old × decay_rate (default 0.95)
This ensures old performance doesn't dominate forever. An arm that worked 10 cycles ago but fails recently will eventually lose influence.
Decay Math:
• 0.95 decay after 10 periods → 0.95^10 = 0.60 (40% forgotten)
• 0.90 decay after 10 periods → 0.90^10 = 0.35 (65% forgotten)
Fast decay (0.80-0.90): Quick adaptation, forgets old patterns rapidly
Slow decay (0.96-0.99): Stable, retains historical knowledge longer
WFO Efficiency Metric:
The key metric revealing overfitting:
Efficiency = (Q_test / Q_train) for each validated arm, averaged
• Efficiency > 0.8: Excellent - strategies generalize well (LOW overfit risk)
• Efficiency 0.5-0.8: Acceptable - moderate generalization (MODERATE risk)
• Efficiency < 0.5: Poor - strategies curve-fitted to history (HIGH risk)
If efficiency is low, the system has learned noise. Training performance was good but testing (forward) performance is weak—classic overfitting.
The dashboard displays real-time WFO efficiency, allowing users to gauge system robustness. Low efficiency should trigger parameter review or reduced position sizing.
Why WFO Matters:
Consider two scenarios:
Scenario A - No WFO:
• Arm 3 (RSI Reversion) shows Q-value of 0.15 on all historical data
• System trades it aggressively
• Reality: It only worked during one specific ranging period
• Live trading: Fails because market has trended since backtest
Scenario B - With WFO:
• Arm 3 shows Q_train = 0.15 (good in training)
• But Q_test = -0.05 (loses in testing) with 12 test trades
• N_test ≥ 10 but Q_test < 0 → Arm BLOCKED
• System refuses to trade it despite good backtest
• Live trading: Protected from false strategy
WFO ensures only strategies that work going forward get used, not just strategies that fit the past.
Optimal Window Sizing:
Training Window:
• Too short (100-300): May learn recent noise, insufficient data
• Too long (1000-2000): May include obsolete market regimes
• Recommended: 4-6× testing window (default 500)
Testing Window:
• Too short (50-80): Insufficient validation, high variance
• Too long (300-500): Delayed adaptation to regime changes
• Recommended: 1/5 to 1/4 of training (default 100)
Minimum Trades:
• Too low (5-8): Statistical noise, lucky runs validate
• Too high (30-50): Many arms never validate, system rarely trades
• Recommended: 10-15 (default 10)
⚖️ WEIGHTED CONFLUENCE SYSTEM: MULTI-FACTOR SIGNAL QUALITY
Not all signals are created equal. KMD implements a sophisticated 100-point quality scoring system that combines eight independent factors with different importance weights.
The Scoring Framework:
Each potential signal receives a quality score from 0-100 by accumulating points from aligned factors:
CRITICAL FACTORS (20 points each):
1. Bandit Arm Alignment (20 points):
• Full points if selected arm's signal matches trade direction
• Zero points if arm disagrees
• Weight: Highest - the bandit selected this arm for a reason
2. MMD Regime Quality (20 points):
• Requires: MMD > dynamic threshold AND directional bias confirmed
• Scaled by MMD percentile (how extreme vs history)
• If MMD in top 10% of history: 100% of 20 points
• If MMD at 50th percentile: 50% of 20 points
• Weight: Highest - distribution shift is the core signal
HIGH IMPACT FACTORS (15 points each):
3. Trend Alignment (15 points):
• Full points if EMA(9) > EMA(21) > EMA(50) for longs (inverse for shorts)
• Scaled by ADX strength:
- ADX > 25: 100% (1.0× multiplier) - strong trend
- ADX 20-25: 70% (0.7× multiplier) - moderate trend
- ADX < 20: 40% (0.4× multiplier) - weak trend
• Weight: High - trend is friend, alignment increases probability
4. Volume Confirmation (15 points):
• Requires: OBV > EMA(OBV, 20) aligned with direction
• Scaled by volume ratio: vol_current / vol_average
- Volume 1.5×+ average: 100% of points (institutional participation)
- Volume 1.0-1.5× average: 67% of points (above average)
- Volume below average: 0 points (weak conviction)
• Weight: High - volume validates price moves
MODERATE FACTORS (10 points each):
5. Market Structure (10 points):
• Full points (10) if bullish structure (higher highs, higher lows) for longs
• Partial points (6) if near support level (within 1% of swing low)
• Similar logic inverted for bearish trades
• Weight: Moderate - structure context improves entries
6. RSI Positioning (10 points):
• For long signals:
- RSI < 50: 100% of points (1.0× multiplier) - room to run
- RSI 50-60: 60% of points (0.6× multiplier) - neutral
- RSI 60-70: 30% of points (0.3× multiplier) - elevated
- RSI > 70: 0 points (0× multiplier) - overbought
• Inverse for short signals
• Weight: Moderate - momentum context, not primary signal
BONUS FACTORS (10 points each):
7. Divergence (10 points):
• Full 10 points if bullish divergence detected for long (or bearish for short)
• Zero points otherwise
• Weight: Bonus - leading indicator, adds confidence when present
8. Multi-Timeframe Confirmation (10 points):
• Full 10 points if higher timeframe aligned (HTF EMA trending same direction, RSI supportive)
• Zero points if MTF disabled or HTF opposes
• Weight: Bonus - macro context filter, prevents counter-trend disasters
Total Maximum: 110 points (20+20+15+15+10+10+10+10)
Signal Quality Calculation:
Quality Score = (Accumulated_Points / Maximum_Possible) × 100
Where Maximum_Possible = 110 points if all factors active, adjusts if MTF disabled.
Example Calculation:
Long signal candidate:
• Bandit Arm: +20 (arm signals long)
• MMD Quality: +16 (MMD high, 80th percentile)
• Trend: +11 (EMAs aligned, ADX = 22 → 70% × 15)
• Volume: +10 (OBV rising, vol 1.3× avg → 67% × 15 = 10)
• Structure: +10 (higher lows forming)
• RSI: +6 (RSI = 55 → 60% × 10)
• Divergence: +0 (none present)
• MTF: +10 (HTF bullish)
Total: 83 / 110 × 100 = 75.5% quality score
This is an excellent quality signal - well above threshold (default 60%).
Quality Thresholds:
• Score 80-100: Exceptional setup - all factors aligned
• Score 60-80: High quality - most factors supportive (default minimum)
• Score 40-60: Moderate - mixed confluence, proceed with caution
• Score 20-40: Weak - minimal support, likely filtered out
• Score 0-20: Very weak - almost certainly blocked
The minimum quality threshold (default 60) is the gatekeeper. Only signals scoring above this value can trigger trades.
Dynamic Threshold Adjustment:
The system optionally adjusts the threshold based on historical signal distribution:
If Dynamic Threshold enabled:
Recent_MMD_Mean = SMA(MMD, 50)
Recent_MMD_StdDev = StdDev(MMD, 50)
Dynamic_Threshold = max(Base_Threshold × 0.5,
min(Base_Threshold × 2.0,
MMD_Mean + MMD_StdDev × 0.5))
This auto-calibrates to market conditions:
• Quiet markets (low MMD): Threshold loosens (0.5× base)
• Active markets (high MMD): Threshold tightens (2× base)
Signal Ranking Filter:
When enabled, the system tracks the last 100 signal quality scores and only fires signals in the top percentile.
If Ranking Percentile = 75%:
• Collect last 100 signal scores in memory
• Sort ascending
• Threshold = Score at 75th percentile position
• Only signals ≥ this threshold fire
This ensures you're only taking the cream of the crop—top 25% of signals by quality, not every signal that technically qualifies.
🚦 SIGNAL GENERATION: TRANSITION LOGIC & COOLDOWNS
The confluence system determines if a signal qualifies, but the signal generation logic controls when triangles appear on the chart.
Core Qualification:
For a LONG signal to qualify:
1. Bull quality score ≥ signal threshold (default 60)
2. Selected arm signals +1 (long)
3. Cooldown satisfied (bars since last signal ≥ cooldown period)
4. Drawdown protection OK (current drawdown < pause threshold)
5. MMD ≥ 80% of dynamic threshold (slight buffer below full threshold)
For a SHORT signal to qualify:
1. Bear quality score ≥ signal threshold
2. Selected arm signals -1 (short)
3-5. Same as long
But qualification alone doesn't trigger a chart signal.
Three Signal Modes:
1. RESPONSIVE (Default - Recommended):
Signals appear on:
• Fresh qualification (wasn't qualified last bar, now is)
• Direction reversal (was qualified short, now qualified long)
• Quality improvement (already qualified, quality jumps 25%+ during EXTREME regime)
This mode shows new opportunities and significant upgrades without cluttering the chart with repeat signals.
2. TRANSITION ONLY:
Signals appear on:
• Fresh qualification only
• Direction reversal only
This is the cleanest mode - signals only when first qualifying or when flipping direction. Misses re-entries if quality improves mid-regime.
3. CONTINUOUS:
Signals appear on:
• Every bar that qualifies
Testing/debugging mode - shows all qualified bars. Very noisy but useful for understanding when system wants to trade.
Cooldown System:
Prevents signal clustering and overtrading by enforcing minimum bars between signals.
Base Cooldown: User-defined (default 5 bars)
Adaptive Cooldown (Optional):
If enabled, cooldown scales with volatility:
Effective_Cooldown = Base_Cooldown × volatility_multiplier
Where:
ATR_Pct = ATR(14) / Close × 100
Volatility_Multiplier = max(0.5, min(3.0, ATR_Pct / 2.0))
• Low volatility (ATR 1%): Multiplier ~0.5× → Cooldown = 2-3 bars (tight)
• Medium volatility (ATR 2%): Multiplier 1.0× → Cooldown = 5 bars (normal)
• High volatility (ATR 4%+): Multiplier 2.0-3.0× → Cooldown = 10-15 bars (wide)
This prevents excessive trading during wild swings while allowing more signals during calm periods.
Regime Filter:
Three modes controlling which regimes allow trading:
OFF: Trade in any regime (STABLE, TRENDING, SHIFTING, ELEVATED, EXTREME)
SMART (Recommended):
• Regime score = 1.0 for SHIFTING, ELEVATED (optimal)
• Regime score = 0.8 for TRENDING (acceptable)
• Regime score = 0.5 for EXTREME (too chaotic)
• Regime score = 0.2 for STABLE (too quiet)
Quality scores are multiplied by regime score. A 70% quality signal in STABLE regime becomes 70% × 0.2 = 14% → blocked.
STRICT:
• Regime score = 1.0 for SHIFTING, ELEVATED only
• Regime score = 0.0 for all others → hard block
Only trades during optimal distribution shift regimes.
Drawdown Protection:
If current equity drawdown exceeds pause threshold (default 8%), all signals are blocked until equity recovers.
This circuit breaker prevents compounding losses during adverse conditions or broken market structure.
🎯 RISK MANAGEMENT: ATR-BASED STOPS & TARGETS
Every signal generates volatility-normalized stop loss and target levels displayed as boxes on the chart.
Stop Loss Calculation:
Stop_Distance = ATR(14) × ATR_Multiplier (default 1.5)
For LONG: Stop = Entry - Stop_Distance
For SHORT: Stop = Entry + Stop_Distance
The stop is placed 1.5 ATRs away from entry by default, adapting automatically to instrument volatility.
Target Calculation:
Target_Distance = Stop_Distance × Risk_Reward_Ratio (default 2.0)
For LONG: Target = Entry + Target_Distance
For SHORT: Target = Entry - Target_Distance
Default 2:1 risk/reward means target is twice as far as stop.
Example:
• Price: $100
• ATR: $2
• ATR Multiplier: 1.5
• Risk/Reward: 2.0
LONG Signal:
• Entry: $100
• Stop: $100 - ($2 × 1.5) = $97.00 (-$3 risk)
• Target: $100 + ($3 × 2.0) = $106.00 (+$6 reward)
• Risk/Reward: $3 risk for $6 reward = 1:2 ratio
Target/Stop Box Lifecycle:
Boxes persist for a lifetime (default 20 bars) OR until an opposite signal fires, whichever comes first. This provides visual reference for active trade levels without permanent chart clutter.
When a new opposite-direction signal appears, all existing boxes from the previous direction are immediately deleted, ensuring only relevant levels remain visible.
Adaptive Stop/Target Sizing:
While not explicitly coded in the current version, the shadow portfolio tracking system calculates PnL based on these levels. Users can observe which ATR multipliers and risk/reward ratios produce optimal results for their instrument/timeframe via the dashboard performance metrics.
📊 COMPREHENSIVE VISUAL SYSTEM
KMD provides rich visual feedback through four distinct layers:
1. PROBABILITY CLOUD (Adaptive Volatility Bands):
Two sets of bands around price that expand/contract with MMD:
Calculation:
Std_Multiplier = 1 + MMD × 3
Upper_1σ = Close + ATR × Std_Multiplier × 0.5
Lower_1σ = Close - ATR × Std_Multiplier × 0.5
Upper_2σ = Close + ATR × Std_Multiplier
Lower_2σ = Close - ATR × Std_Multiplier
• Inner band (±0.5× adjusted ATR): 68% probability zone (1 standard deviation equivalent)
• Outer band (±1.0× adjusted ATR): 95% probability zone (2 standard deviation equivalent)
When MMD spikes, bands widen dramatically, showing increased uncertainty. When MMD calms, bands tighten, showing normal price action.
2. MOMENTUM FLOW VECTORS (Directional Arrows):
Dynamic arrows that visualize momentum strength and direction:
Arrow Properties:
• Length: Proportional to momentum magnitude (2-10 bars forward)
• Width: 1px (weak), 2px (medium), 3px (strong)
• Transparency: 30-100 (more opaque = stronger momentum)
• Direction: Up for bullish, down for bearish
• Placement: Below bars (bulls) or above bars (bears)
Trigger Logic:
• Always appears every 5 bars (regular sampling)
• Forced appearance if momentum strength > 50 OR regime shift OR MMD velocity > 10%
Strong momentum (>75%) gets:
• Secondary support arrow (70% length, lighter color)
• Label showing "75%" strength
Very strong momentum (>60%) gets:
• Gradient flow lines (thick vertical lines showing momentum vector)
This creates a dynamic "flow field" showing where market pressure is pushing price.
3. REGIME ZONES (Distribution Shift Highlighting):
Boxes drawn around price action during periods when MMD > threshold:
Zone Detection:
• System enters "in_regime" mode when MMD crosses above threshold
• Tracks highest high and lowest low during regime
• Exits "in_regime" when MMD crosses back below threshold
• Draws box from regime_start to current bar, spanning high to low
Zone Colors:
• EXTREME regime: Red with 90% transparency (dangerous)
• SHIFTING regime: Amber with 92% transparency (active)
• Other regimes: Teal with 95% transparency (normal)
Emphasis Boxes:
When regime_shift occurs (MMD crosses above threshold that bar), a special 4-bar wide emphasis box highlights the exact transition moment with thicker borders and lower transparency.
This visual immediately shows "the market just changed" moments.
4. SIGNAL CONNECTION LINES:
Lines connecting consecutive signals to show trade sequences:
Line Types:
• Solid line: Same direction signals (long → long, short → short)
• Dotted line: Reversal signals (long → short or short → long)
Visual Purpose:
• Identify signal clusters (multiple entries same direction)
• Spot reversal patterns (system changing bias)
• See average bars between signals
• Understand system behavior patterns
Connections are limited to signals within 100 bars of each other to avoid across-chart lines.
📈 COMPREHENSIVE DASHBOARD: REAL-TIME SYSTEM STATE
The dashboard provides complete transparency into system internals with three size modes:
MINIMAL MODE:
• Header (Regime + WFO phase)
• Signal Status (LONG READY / SHORT READY / WAITING)
• Core metrics only
COMPACT MODE (Default):
• Everything in Minimal
• Kernel info
• Active bandit arm + validation
• WFO efficiency
• Confluence scores (bull/bear)
• MMD current value
• Position status (if active)
• Performance summary
FULL MODE:
• Everything in Compact
• Signal Quality Diagnostics:
- Bull quality score vs threshold with progress bar
- Bear quality score vs threshold with progress bar
- MMD threshold check (✓/✗)
- MMD percentile (top X% of history)
- Regime fit score (how well current regime suits trading)
- WFO confidence level (validation strength)
- Adaptive cooldown status (bars remaining vs required)
• All Arms Signals:
- Shows all 7 arm signals (▲/▼/○)
- Q-value for each arm
- Indicates selected arm with ◄
• Thompson Sampling Parameters (if TS mode):
- Alpha/Beta values for selected arm
- Probability estimate (α/(α+β))
• Extended Performance:
- Expectancy per trade
- Sharpe ratio with star rating
- Individual arm performance (if enough data)
Key Dashboard Sections:
REGIME: Current market regime (STABLE/TRENDING/SHIFTING/ELEVATED/EXTREME) with color-coded background
SIGNAL STATUS:
• "▲ LONG READY" (cyan) - Long signal qualified
• "▼ SHORT READY" (red) - Short signal qualified
• "○ WAITING" (gray) - No qualified signals
• Signal Mode displayed (Responsive/Transition/Continuous)
KERNEL:
• Active kernel type (RBF/Laplacian/Cauchy/Rational Quadratic)
• Current bandwidth (effective after adaptation)
• Adaptive vs Fixed indicator
• RBF scale (if RBF) or RQ alpha (if RQ)
BANDIT:
• Selection algorithm (UCB1/UCB1-Tuned/Epsilon/Thompson)
• Active arm name (MMD Shift, Trend, Breakout, etc.)
• Validation status (✓ if validated, ? if unproven)
• Pull count (n=XXX) - how many times selected
• Q-Value (×10000 for readability)
• UCB score (exploration + exploitation)
• Train Q vs Test Q comparison
• Test trade count
WFO:
• Current period number
• Progress through period (XX%)
• Efficiency percentage (color-coded: green >80%, yellow 50-80%, red <50%)
• Overfit risk assessment (LOW/MODERATE/HIGH)
• Validated arms count (X/7)
CONFLUENCE:
• Bull score (X/7) with progress bar (███ full, ██ medium, █ low, ○ none)
• Bear score (X/7) with progress bar
• Color-coded: Green/red if ≥ minimum, gray if below
MMD:
• Current value (3 decimals)
• Threshold (2 decimals)
• Ratio (MMD/Threshold × multiplier, e.g. "1.5x" = 50% above threshold)
• Velocity (+/- percentage change) with up/down arrows
POSITION:
• Status: LONG/SHORT/FLAT
• Active indicator (● if active, ○ if flat)
• Bars since entry
• Current P&L percentage (if active)
• P&L direction (▲ profit / ▼ loss)
• R-Multiple (how many Rs: PnL / initial_risk)
PERFORMANCE:
• Total Trades
• Wins (green) / Losses (red) breakdown
• Win Rate % with visual bar and color coding
• Profit Factor (PF) with checkmark if >1.0
• Expectancy % (average profit per trade)
• Sharpe Ratio with star rating (★★★ >2, ★★ >1, ★ >0, ○ negative)
• Max DD % (maximum drawdown) with "Now: X%" showing current drawdown
🔧 KEY PARAMETERS EXPLAINED
Kernel Configuration:
• Kernel Function: RBF / Laplacian / Cauchy / Rational Quadratic
- Start with Cauchy for stability, experiment with others
• Bandwidth (σ) (0.5-10.0, default 2.0): Kernel sensitivity
- Lower: More signals, more false positives (scalping: 0.8-1.5)
- Medium: Balanced (swing: 1.5-3.0)
- Higher: Fewer signals, stronger quality (position: 3.0-8.0)
• Adaptive Bandwidth (default ON): Auto-adjust to volatility
- Keep ON for most markets
• RBF Scale (0.1-2.0, default 0.5): RBF-specific scaling
- Only matters if RBF kernel selected
- Lower = more sensitive (0.3 for scalping)
- Higher = less sensitive (1.0+ for position)
• RQ Alpha (0.5-5.0, default 2.0): Rational Quadratic tail behavior
- Only matters if RQ kernel selected
- Low (0.5-1.0): Heavy tails, robust to outliers (like Cauchy)
- High (3.0-5.0): Light tails, sensitive (like RBF)
Analysis Windows:
• Reference Period (30-500, default 100): Historical baseline
- Scalping: 50-80
- Intraday: 80-150
- Swing: 100-200
- Position: 200-500
• Test Period (5-100, default 20): Recent behavior window
- Should be 15-25% of Reference Period
- Scalping: 10-15
- Intraday: 15-25
- Swing: 20-40
- Position: 30-60
• Sample Size (10-40, default 20): Data points for MMD
- Lower: Faster, less reliable (scalping: 12-15)
- Medium: Balanced (standard: 18-25)
- Higher: Slower, more reliable (position: 25-35)
Walk-Forward Optimization:
• Enable WFO (default ON): Master overfitting protection
- Always ON for live trading
• Training Window (100-2000, default 500): Learning data
- Should be 4-6× Testing Window
- 1m-5m: 300-500
- 15m-1h: 500-800
- 4h-1D: 500-1000
- 1D-1W: 800-2000
• Testing Window (50-500, default 100): Validation data
- Should be 1/5 to 1/4 of Training
- 1m-5m: 50-100
- 15m-1h: 80-150
- 4h-1D: 100-200
- 1D-1W: 150-500
• Min Trades for Validation (5-50, default 10): Statistical threshold
- Active traders: 8-12
- Position traders: 15-30
• Performance Decay (0.8-0.99, default 0.95): Old data forgetting
- Aggressive: 0.85-0.90 (volatile markets)
- Moderate: 0.92-0.96 (most use cases)
- Conservative: 0.97-0.99 (stable markets)
Multi-Armed Bandit:
• Learning Rate (α) (0.01-0.3, default 0.08): Adaptation speed
- Low: 0.01-0.05 (position trading, stable)
- Medium: 0.06-0.12 (day/swing trading)
- High: 0.15-0.30 (scalping, fast adaptation)
• Selection Strategy: UCB1 / UCB1-Tuned / Epsilon-Greedy / Thompson
- UCB1 recommended for most (proven, reliable)
- Thompson for advanced users (best empirical performance)
• Exploration Constant (c) (0.5-3.0, default 1.5): Explore vs exploit
- Low: 0.5-1.0 (conservative, proven strategies)
- Medium: 1.2-1.8 (balanced)
- High: 2.0-3.0 (experimental, volatile markets)
• Epsilon (0.0-0.3, default 0.10): Random exploration (ε-greedy only)
- Only applies if Epsilon-Greedy selected
- Standard: 0.10 (10% random)
Signal Configuration:
• MMD Threshold (0.05-1.0, default 0.15): Distribution divergence trigger
- Low: 0.08-0.12 (scalping, sensitive)
- Medium: 0.12-0.20 (day/swing)
- High: 0.25-0.50 (position, strong signals)
- Stocks/indices: 0.12-0.18
- Forex: 0.15-0.25
- Crypto: 0.20-0.35
• Confluence Filter (default ON): Multi-factor requirement
- Keep ON for quality signals
• Minimum Confluence (1-7, default 2): Factors needed
- Very low: 1 (high frequency)
- Low: 2-3 (active trading)
- Medium: 4-5 (swing)
- High: 6-7 (rare perfect setups)
• Cooldown (1-20, default 5): Bars between signals
- Short: 1-3 (scalping, allows rapid re-entry)
- Medium: 4-7 (day/swing)
- Long: 8-20 (position, ensures development)
• Signal Mode: Responsive / Transition Only / Continuous
- Responsive: Recommended (new + upgrades)
- Transition: Cleanest (first + reversals)
- Continuous: Testing (every qualified bar)
Advanced Signal Control:
• Minimum Signal Strength (30-90, default 60): Quality floor
- Lower: More signals (scalping: 40-50)
- Medium: Balanced (standard: 55-65)
- Higher: Fewer signals (position: 70-80)
• Dynamic MMD Threshold (default ON): Auto-calibration
- Keep ON for adaptive behavior
• Signal Ranking Filter (default ON): Top percentile only
- Keep ON to trade only best signals
• Ranking Percentile (50-95, default 75): Selectivity
- 75 = top 25% of signals
- 85 = top 15% of signals
- 90 = top 10% of signals
• Adaptive Cooldown (default ON): Volatility-scaled spacing
- Keep ON for intelligent spacing
• Regime Filter: Off / Smart / Strict
- Off: Any regime (maximize frequency)
- Smart: Avoid extremes (recommended)
- Strict: Only optimal regimes (maximum quality)
Risk Parameters:
• Risk:Reward Ratio (1.0-5.0, default 2.0): Target distance multiplier
- Conservative: 1.0-1.5 (higher WR needed)
- Balanced: 2.0-2.5 (standard professional)
- Aggressive: 3.0-5.0 (lower WR acceptable)
• Stop Loss (ATR mult) (0.5-4.0, default 1.5): Stop distance
- Tight: 0.5-1.0 (scalping, low vol)
- Medium: 1.2-2.0 (day/swing)
- Wide: 2.5-4.0 (position, high vol)
• Pause After Drawdown (2-20%, default 8%): Circuit breaker
- Aggressive: 3-6% (small accounts)
- Moderate: 6-10% (most traders)
- Relaxed: 10-15% (large accounts)
Multi-Timeframe:
• MTF Confirmation (default OFF): Higher TF filter
- Turn ON for swing/position trading
- Keep OFF for scalping/day trading
• Higher Timeframe (default "60"): HTF for trend check
- Should be 3-5× chart timeframe
- 1m chart → 5m or 15m
- 5m chart → 15m or 60m
- 15m chart → 60m or 240m
- 1h chart → 240m or D
Display:
• Probability Cloud (default ON): Volatility bands
• Momentum Flow Vectors (default ON): Directional arrows
• Regime Zones (default ON): Distribution shift boxes
• Signal Connections (default ON): Lines between signals
• Dashboard (default ON): Stats table
• Dashboard Position: Top Left / Top Right / Bottom Left / Bottom Right
• Dashboard Size: Minimal / Compact / Full
• Color Scheme: Default / Monochrome / Warm / Cool
• Show MMD Debug Plot (default OFF): Overlay MMD value
- Turn ON temporarily for threshold calibration
🎓 PROFESSIONAL USAGE PROTOCOL
Phase 1: Parameter Calibration (Week 1)
Goal: Find optimal kernel and bandwidth for your instrument/timeframe
Setup:
• Enable "Show MMD Debug Plot"
• Start with Cauchy kernel, 2.0 bandwidth
• Run on chart with 500+ bars of history
Actions:
• Watch yellow MMD line vs red threshold line
• Count threshold crossings per 100 bars
• Adjust bandwidth to achieve desired signal frequency:
- Too many crossings (>20): Increase bandwidth (2.5-3.5)
- Too few crossings (<5): Decrease bandwidth (1.2-1.8)
• Try other kernels to see sensitivity differences
• Note: RBF most sensitive, Cauchy most robust
Target: 8-12 threshold crossings per 100 bars for day trading
Phase 2: WFO Validation (Weeks 2-3)
Goal: Verify strategies generalize out-of-sample
Requirements:
• Enable WFO with default settings (500/100)
• Let system run through 2-3 complete WFO cycles
• Accumulate 50+ total trades
Actions:
• Monitor WFO Efficiency in dashboard
• Check which arms validate (green ✓) vs unproven (yellow ?)
• Review Train Q vs Test Q for selected arm
• If efficiency < 0.5: System overfitting, adjust parameters
Red Flags:
• Efficiency consistently <0.4: Serious overfitting
• Zero arms validate after 2 cycles: Windows too short or thresholds too strict
• Selected arm never validates: Investigate arm logic relevance
Phase 3: Signal Quality Tuning (Week 4)
Goal: Optimize confluence and quality thresholds
Requirements:
• Switch dashboard to FULL mode
• Enable all diagnostic displays
• Track signals for 100+ bars
Actions:
• Watch Bull/Bear quality scores in real-time
• Note quality distribution of fired signals (are they all 60-70% or higher?)
• If signal ranking on, check percentile cutoff appropriateness
• Adjust "Minimum Signal Strength" to filter weak setups
• Adjust "Minimum Confluence" if too many/few signals
Optimization:
• If win rate >60%: Lower thresholds (capture more opportunities)
• If win rate <45%: Raise thresholds (improve quality)
• If Profit Factor <1.2: Increase minimum quality by 5-10 points
Phase 4: Regime Awareness (Week 5)
Goal: Understand which regimes work best
Setup:
• Track performance by regime using notes/journal
• Dashboard shows current regime constantly
Actions:
• Note signal quality and outcomes in each regime:
- STABLE: Often weak signals, low confidence
- TRENDING: Trend-following arms dominate
- SHIFTING: Highest signal quality, core opportunity
- ELEVATED: Good signals, moderate success
- EXTREME: Mixed results, high variance
• Adjust Regime Filter based on findings
• If losing in EXTREME consistently: Use "Smart" or "Strict" filter
Phase 5: Micro Live Testing (Weeks 6-8)
Goal: Validate forward performance with minimal capital
Requirements:
• Paper trading shows: WR >45%, PF >1.2, Efficiency >0.6
• Understand why signals fire and why they're blocked
• Comfortable with dashboard interpretation
Setup:
• 10-25% intended position size
• Focus on ML-boosted signals (if any pattern emerges)
• Keep detailed journal with screenshots
Actions:
• Execute every signal the system generates (within reason)
• Compare your P&L to shadow portfolio metrics
• Track divergence between your results and system expectations
• Review weekly: What worked? What failed? Any execution issues?
Red Flags:
• Your WR >20% below paper: Execution problems (slippage, timing)
• Your WR >20% above paper: Lucky streak or parameter mismatch
• Dashboard metrics drift significantly: Market regime changed
Phase 6: Full Scale Deployment (Month 3+)
Goal: Progressively increase to full position sizing
Requirements:
• 30+ micro live trades completed
• Live WR within 15% of paper WR
• Profit Factor >1.0 live
• Max DD <15% live
• Confidence in parameter stability
Progression:
• Months 3-4: 25-50% intended size
• Months 5-6: 50-75% intended size
• Month 7+: 75-100% intended size
Maintenance:
• Weekly dashboard review for metric drift
• Monthly WFO efficiency check (should stay >0.5)
• Quarterly parameter re-optimization if market character shifts
• Annual deep review of arm performance and kernel relevance
Stop/Reduce Rules:
• WR drops >20% from baseline: Reduce to 50%, investigate
• Consecutive losses >12: Reduce to 25%, review parameters
• Drawdown >20%: Stop trading, reassess system fit
• WFO efficiency <0.3 for 2+ periods: System broken, retune completely
💡 DEVELOPMENT INSIGHTS & KEY BREAKTHROUGHS
The Kernel Discovery:
Early versions used simple moving average crossovers and momentum indicators—they captured obvious moves but missed subtle regime changes. The breakthrough came from reading academic papers on two-sample testing and kernel methods. Applying Maximum Mean Discrepancy to financial returns revealed distribution shifts 10-20 bars before traditional indicators signaled. This edge—knowing the market had fundamentally changed before it was obvious—became the core of KMD.
Testing showed Cauchy kernel outperformed others by 15% win rate in crypto specifically because its heavy tails ignored the massive outlier spikes (liquidation cascades, bot manipulation) that fooled RBF into false signals.
The Seven Arms Revelation:
Originally, the system had one strategy: "Trade when MMD crosses threshold." Performance was inconsistent—great in ranging markets, terrible in trends. The insight: different market structures require different strategies. Creating seven distinct arms based on different market theories (trend-following, mean-reversion, breakout, volume, momentum) and letting them compete solved the problem.
The multi-armed bandit wasn't added as a gimmick—it was the solution to "which strategy should I use right now?" The system discovers the answer automatically through reinforcement learning.
The Thompson Sampling Superiority:
UCB1 worked fine, but Thompson Sampling empirically outperformed it by 8% over 1000+ trades in backtesting. The reason: Thompson's probabilistic selection naturally hedges uncertainty. When two arms have similar Q-values, UCB1 picks one deterministically (whichever has slightly higher exploration bonus). Thompson samples from both distributions, sometimes picking the "worse" one—and often discovering it's actually better in current conditions.
Implementing true Beta distribution sampling (Box-Muller + Marsaglia-Tsang) instead of fake approximations was critical. Fake Thompson (using random with bias) underperformed UCB1. Real Thompson with proper Bayesian updating dominated.
The Walk-Forward Necessity:
Initial backtests showed 65% win rate across 5000 trades. Live trading: 38% win rate over first 100 trades. Crushing disappointment. The problem: overfitting. The training data included the test data (look-ahead bias). Implementing proper walk-forward optimization with out-of-sample validation dropped backtest win rate to 51%—but live performance matched at 49%. That's a system you can trust.
WFO efficiency metric became the North Star. If efficiency >0.7, live results track paper. If efficiency <0.5, prepare for disappointment.
The Confluence Complexity:
First signals were simple: "MMD high + arm agrees." This generated 200+ signals on 1000 bars with 42% win rate—not tradeable. Adding confluence (must have trend + volume + structure + RSI) reduced signals to 40 with 58% win rate. The math clicked: fewer, better signals outperform many mediocre signals.
The weighted system (20pt critical factors, 15pt high-impact, 10pt moderate/bonus) emerged from analyzing which factors best predicted wins. Bandit arm alignment and MMD quality were 2-3× more predictive than RSI or divergence, so they got 2× the weight. This isn't arbitrary—it's data-driven.
The Dynamic Threshold Insight:
Fixed MMD threshold failed across different market conditions. 0.15 worked perfectly on ES but fired constantly on Bitcoin. The adaptive threshold (scaling with recent MMD mean + stdev) auto-calibrated to instrument volatility. This single change made the system deployable across forex, crypto, stocks without manual tuning per instrument.
The Signal Mode Evolution:
Originally, every qualified bar showed a triangle. Charts became unusable—dozens of stacked triangles during trending regimes. "Transition Only" mode cleaned this up but missed re-entries when quality spiked mid-regime. "Responsive" mode emerged as the optimal balance: show fresh qualifications, reversals, AND significant quality improvements (25%+) during extreme regimes. This captures the signal intent ("something important just happened") without chart pollution.
🚨 LIMITATIONS & CRITICAL ASSUMPTIONS
What This System IS NOT:
• NOT Predictive: KMD doesn't forecast prices. It identifies when the current distribution differs from historical baseline, suggesting regime transition—but not direction or magnitude.
• NOT Holy Grail: Typical performance is 48-56% win rate with 1.3-1.8 avg R-multiple. This is a probabilistic edge, not certainty. Expect losing streaks of 8-12 trades.
• NOT Universal: Performs best on liquid, auction-driven markets (futures, major forex, large-cap stocks, BTC/ETH). Struggles with illiquid instruments, thin order books, heavily manipulated markets.
• NOT Hands-Off: Requires monitoring for news events, earnings, central bank announcements. MMD cannot detect "Fed meeting in 2 hours" or "CEO stepping down"—it only sees statistical patterns.
• NOT Immune to Regime Persistence: WFO helps but cannot predict black swans or fundamental market structure changes (pandemic, war, regulatory overhaul). During these events, all historical patterns may break.
Core Assumptions:
1. Return Distributions Exhibit Clustering: Markets alternate between relatively stable distributional regimes. Violation: Permanent random walk, no regime structure.
2. Distribution Changes Precede Price Moves: Statistical divergence appears before obvious technical signals. Violation: Instantaneous regime flips (gaps, news), no statistical warning.
3. Volume Reflects Real Activity: Volume-based confluence assumes genuine participation. Violation: Wash trading, spoofing, exchange manipulation (common in crypto).
4. Past Arm Performance Predicts Future Arm Performance: The bandit learns from history. Violation: Fundamental strategy regime change (e.g., market transitions from mean-reverting to trending permanently).
5. ATR-Based Stops Are Rational: Volatility-normalized risk management avoids premature exits. Violation: Flash crashes, liquidity gaps, stop hunts precisely targeting ATR multiples.
6. Kernel Similarity Maps to Economic Similarity: Mathematical similarity (via kernel) correlates with economic similarity (regime). Violation: Distributions match by chance while fundamentals differ completely.
Performs Best On:
• ES, NQ, RTY (S&P 500, Nasdaq, Russell 2000 futures)
• Major forex pairs: EUR/USD, GBP/USD, USD/JPY, AUD/USD
• Liquid commodities: CL (crude oil), GC (gold), SI (silver)
• Large-cap stocks: AAPL, MSFT, GOOGL, TSLA (>$10M avg daily volume)
• Major crypto on reputable exchanges: BTC, ETH (Coinbase, Kraken)
Performs Poorly On:
• Low-volume stocks (<$1M daily volume)
• Exotic forex pairs with erratic spreads
• Illiquid crypto altcoins (manipulation, unreliable volume)
• Pre-market/after-hours (thin liquidity, gaps)
• Instruments with frequent corporate actions (splits, dividends)
• Markets with persistent one-sided intervention (central bank pegs)
Known Weaknesses:
• Lag During Instantaneous Shifts: MMD requires (test_window) bars to detect regime change. Fast-moving events (5-10 bar crashes) may bypass detection entirely.
• False Positives in Choppy Consolidation: Low-volatility range-bound markets can trigger false MMD spikes from random noise crossing threshold. Regime filter helps but doesn't eliminate.
• Parameter Sensitivity: Small bandwidth changes (2.0→2.5) can alter signal frequency by 30-50%. Requires careful calibration per instrument.
• Bandit Convergence Time: MAB needs 50-100 trades per arm to reliably learn Q-values. Early trades (first 200 bars) are essentially random exploration.
• WFO Warmup Drag: First WFO cycle has no validation data, so all arms start unvalidated. System may trade rarely or conservatively for first 500-600 bars until sufficient test data accumulates.
• Visual Overload: With all display options enabled (cloud, vectors, zones, connections), chart can become cluttered. Disable selectively for cleaner view.
⚠️ RISK DISCLOSURE
Trading futures, forex, stocks, options, and cryptocurrencies involves substantial risk of loss and is not suitable for all investors. Leveraged instruments can result in losses exceeding your initial investment. Past performance, whether backtested or live, is not indicative of future results.
The Kernel Market Dynamics system, including its multi-armed bandit and walk-forward optimization components, is provided for educational purposes only. It is not financial advice, investment advice, or a recommendation to buy or sell any security or instrument.
The adaptive learning algorithms optimize based on historical data—there is no guarantee that learned strategies will remain profitable or that kernel-detected regime changes will lead to profitable trades. Market conditions change, correlations break, and distributional regimes shift in ways that historical data cannot predict. Black swan events occur.
Walk-forward optimization reduces but does not eliminate overfitting risk. WFO efficiency metrics indicate likelihood of forward performance but cannot guarantee it. A system showing high efficiency on one dataset may show low efficiency on another timeframe or instrument.
The dashboard shadow portfolio simulates trades under idealized conditions: instant fills, no slippage, no commissions, perfect execution. Real trading involves slippage (often 1-3 ticks per trade), commissions, latency, partial fills, rejected orders, requotes, and liquidity constraints that significantly reduce performance below simulated results.
Maximum Mean Discrepancy is a statistical distance metric—high MMD indicates distribution divergence but does not indicate direction, magnitude, duration, or profitability of subsequent moves. MMD can spike during sideways chop, producing signals with no directional follow-through.
Users must independently validate system performance on their specific instruments, timeframes, broker execution, and market conditions before risking capital. Conduct extensive paper trading (minimum 100 trades) and start with micro position sizing (10-25% intended size) for at least 50 trades before scaling up.
Never risk more capital than you can afford to lose completely. Use proper position sizing (1-2% risk per trade maximum). Implement stop losses on every trade. Maintain adequate margin/capital reserves. Understand that most retail traders lose money. Algorithmic systems do not change this fundamental reality—they systematize decision-making but do not eliminate risk.
The developer makes no warranties regarding profitability, suitability, accuracy, reliability, or fitness for any particular purpose. Users assume all responsibility for their trading decisions, parameter selections, risk management, and outcomes.
By using this indicator, you acknowledge that you have read and understood these risk disclosures and accept full responsibility for all trading activity and potential losses.
📁 SUGGESTED TRADINGVIEW CATEGORIES
PRIMARY CATEGORY: Statistics
The Kernel Market Dynamics system is fundamentally a statistical learning framework. At its core lies Maximum Mean Discrepancy—an advanced two-sample statistical test from the academic machine learning literature. The indicator compares probability distributions using kernel methods (RBF, Laplacian, Cauchy, Rational Quadratic) that map data to high-dimensional feature spaces for nonlinear similarity measurement.
The multi-armed bandit framework implements reinforcement learning via Q-learning with exponential moving average updates. Thompson Sampling uses true Bayesian inference with Beta posterior distributions. Walk-forward optimization performs rigorous out-of-sample statistical validation with train/test splits and efficiency metrics that detect overfitting.
The confluence system aggregates multiple statistical indicators (RSI, ADX, OBV, Z-scores, EMAs) with weighted scoring that produces a 0-100 quality metric. Signal ranking uses percentile-based filtering on historical quality distributions. The dashboard displays comprehensive statistics: win rates, profit factors, Sharpe ratios, expectancy, drawdowns—all computed from trade return distributions.
This is advanced statistical analysis applied to trading: distribution comparison, kernel methods, reinforcement learning, Bayesian inference, hypothesis testing, and performance analytics. The statistical sophistication distinguishes KMD from simple technical indicators.
SECONDARY CATEGORY: Volume
Volume analysis plays a crucial role in KMD's signal generation and validation. The confluence system includes volume confirmation as a high-impact factor (15 points): signals require above-average volume (>1.2× mean) for full points, with scaling based on volume ratio. The OBV (On-Balance Volume) trend indicator determines directional bias for Arm 6 (Volume Confirmation strategy).
Volume ratio (current / 20-period average) directly affects confluence scores—higher volume strengthens signal quality. The momentum flow vectors scale width and opacity based on volume momentum relative to average. Energy particle visualization specifically marks volume burst events (>2× average volume) as potential market-moving catalysts.
Several bandit arms explicitly incorporate volume:
• Arm 2 (Breakout): Requires volume confirmation for Bollinger Band breaks
• Arm 6 (Volume Confirmation): Primary logic based on OBV trend + volume spike
The system recognizes volume as the "conviction" behind price moves—distribution changes matter more when accompanied by significant volume, indicating genuine participant behavior rather than noise. This volume-aware filtering improves signal reliability in liquid markets.
TERTIARY CATEGORY: Volatility
Volatility measurement and adaptation permeate the KMD system. ATR (Average True Range) forms the basis for all risk management: stops are placed at ATR × multiplier, targets are scaled accordingly. The adaptive bandwidth feature scales kernel bandwidth (0.5-2.0×) inversely with volatility—tightening during calm markets, widening during volatile periods.
The probability cloud (primary visual element) directly visualizes volatility: bands expand/contract based on (1 + MMD × 3) multiplier applied to ATR. Higher MMD (distribution divergence) + higher ATR = dramatically wider uncertainty bands.
Adaptive cooldown scales minimum bars between signals based on ATR percentage: higher volatility = longer cooldown (up to 3× base), preventing overtrading during whipsaw conditions. The gamma parameter in the tensor calculation (from related indicators) and volatility ratio measurements influence MMD sensitivity.
Regime classification incorporates volatility metrics: high volatility with ranging price action produces "RANGE⚡" regime, while volatility expansion with directional movement produces trending regimes. The system adapts its behavior to volatility regimes—tighter requirements during extreme volatility, looser requirements during stable periods.
ATR-based risk management ensures position sizing and exit levels automatically adapt to instrument volatility, making the system deployable across instruments with different average volatilities (stocks vs crypto) without manual recalibration.
══════════════════════════════════════════
CLOSING STATEMENT
══════════════════════════════════════════
Kernel Market Dynamics doesn't just measure price—it measures the probability structure underlying price. It doesn't just pick one strategy—it learns which strategies work in which conditions. It doesn't just optimize on history—it validates on the future.
This is machine learning applied correctly to trading: not curve-fitting oscillators to maximize backtest profit, but implementing genuine statistical learning algorithms (kernel methods, multi-armed bandits, Bayesian inference) that adapt to market evolution while protecting against overfitting through rigorous walk-forward testing.
The seven arms compete. The Thompson sampler selects. The kernel measures. The confluence scores. The walk-forward validates. The signals fire.
Most indicators tell you what happened. KMD tells you when the game changed.
"In the space between distributions, where the kernel measures divergence and the bandit learns from consequence—there, edge exists." — KMD-WFO-MAB v2
Taking you to school. — Dskyz, Trade with insight. Trade with anticipation.
⚛️ CORE INNOVATION: KERNEL-BASED DISTRIBUTION ANALYSIS
The Kernel Market Dynamics system represents a fundamental departure from traditional technical indicators. Rather than measuring price levels, momentum, or oscillator extremes, KMD analyzes the statistical distribution of market returns using advanced kernel methods from machine learning theory. This allows the system to detect when market behavior has fundamentally changed—not just when price has moved, but when the underlying probability structure has shifted.
The Distribution Hypothesis:
Traditional indicators assume markets move in predictable patterns. KMD assumes something more profound: markets exist in distinct distributional regimes, and profitable trading opportunities emerge during regime transitions. When the distribution of recent returns diverges significantly from the historical baseline, the market is restructuring—and that's when edge exists.
Maximum Mean Discrepancy (MMD):
At the heart of KMD lies a sophisticated statistical metric called Maximum Mean Discrepancy. MMD measures the distance between two probability distributions by comparing their representations in a high-dimensional feature space created by a kernel function.
The Mathematics:
Given two sets of normalized returns:
• Reference period (X): Historical baseline (default 100 bars)
• Test period (Y): Recent behavior (default 20 bars)
MMD is calculated as:
MMD² = E[k(X,X)] + E[k(Y,Y)] - 2·E[k(X,Y)]
Where:
• E[k(X,X)] = Expected kernel similarity within reference period
• E[k(Y,Y)] = Expected kernel similarity within test period
• E[k(X,Y)] = Expected cross-similarity between periods
When MMD is low: Test period behaves like reference (stable regime)
When MMD is high: Test period diverges from reference (regime shift)
The final MMD value is smoothed with EMA(5) to reduce single-bar noise while maintaining responsiveness to genuine distribution changes.
The Kernel Functions:
The kernel function defines how similarity is measured. KMD offers four mathematically distinct kernels, each with different properties:
1. RBF (Radial Basis Function / Gaussian):
• Formula: k(x,y) = exp(-d² / (2·σ²·scale))
• Properties: Most sensitive to distribution changes, smooth decision boundaries
• Best for: Clean data, clear regime shifts, low-noise markets
• Sensitivity: Highest - detects subtle changes
• Use case: Stock indices, major forex pairs, trending environments
2. Laplacian:
• Formula: k(x,y) = exp(-|d| / σ)
• Properties: Medium sensitivity, robust to moderate outliers
• Best for: Standard market conditions, balanced noise/signal
• Sensitivity: Medium - filters minor fluctuations
• Use case: Commodities, standard timeframes, general trading
3. Cauchy (Default - Most Robust):
• Formula: k(x,y) = 1 / (1 + d²/σ²)
• Properties: Heavy-tailed, highly robust to outliers and spikes
• Best for: Noisy markets, choppy conditions, crypto volatility
• Sensitivity: Lower - only major distribution shifts trigger
• Use case: Cryptocurrencies, illiquid markets, volatile instruments
4. Rational Quadratic:
• Formula: k(x,y) = (1 + d²/(2·α·σ²))^(-α)
• Properties: Tunable via alpha parameter, mixture of RBF kernels
• Alpha < 1.0: Heavy tails (like Cauchy)
• Alpha > 3.0: Light tails (like RBF)
• Best for: Adaptive use, mixed market conditions
• Use case: Experimental optimization, regime-specific tuning
Bandwidth (σ) Parameter:
The bandwidth controls the "width" of the kernel, determining sensitivity to return differences:
• Low bandwidth (0.5-1.5): Narrow kernel, very sensitive
- Treats small differences as significant
- More MMD spikes, more signals
- Use for: Scalping, fast markets
• Medium bandwidth (1.5-3.0): Balanced sensitivity (recommended)
- Filters noise while catching real shifts
- Professional-grade signal quality
- Use for: Day/swing trading
• High bandwidth (3.0-10.0): Wide kernel, less sensitive
- Only major distribution changes register
- Fewer, stronger signals
- Use for: Position trading, trend following
Adaptive Bandwidth:
When enabled (default ON), bandwidth automatically scales with market volatility:
Effective_BW = Base_BW × max(0.5, min(2.0, 1 / volatility_ratio))
• Low volatility → Tighter bandwidth (0.5× base) → More sensitive
• High volatility → Wider bandwidth (2.0× base) → Less sensitive
This prevents signal flooding during wild markets and avoids signal drought during calm periods.
Why Kernels Work:
Kernel methods implicitly map data to infinite-dimensional space where complex, nonlinear patterns become linearly separable. This allows MMD to detect distribution changes that simpler statistics (mean, variance) would miss. For example:
• Same mean, different shape: Traditional metrics see nothing, MMD detects shift
• Same volatility, different skew: Oscillators miss it, MMD catches it
• Regime rotation: Price unchanged, but return distribution restructured
The kernel captures the entire distributional signature—not just first and second moments.
🎰 MULTI-ARMED BANDIT FRAMEWORK: ADAPTIVE STRATEGY SELECTION
Rather than forcing one strategy on all market conditions, KMD implements a Multi-Armed Bandit (MAB) system that learns which of seven distinct strategies performs best and dynamically selects the optimal approach in real-time.
The Seven Arms (Strategies):
Each arm represents a fundamentally different trading logic:
ARM 0 - MMD Regime Shift:
• Logic: Distribution divergence with directional bias
• Triggers: MMD > threshold AND direction_bias confirmed AND velocity > 5%
• Philosophy: Trade the regime transition itself
• Best in: Volatile shifts, breakout moments, crisis periods
• Weakness: False alarms in choppy consolidation
ARM 1 - Trend Following:
• Logic: Aligned EMAs with strong ADX
• Triggers: EMA(9) > EMA(21) > EMA(50) AND ADX > 25
• Philosophy: Ride established momentum
• Best in: Strong trending regimes, directional markets
• Weakness: Late entries, whipsaws at reversals
ARM 2 - Breakout:
• Logic: Bollinger Band breakouts with volume
• Triggers: Price crosses BB outer band AND volume > 1.2× average
• Philosophy: Capture volatility expansion events
• Best in: Range breakouts, earnings, news events
• Weakness: False breakouts in ranging markets
ARM 3 - RSI Mean Reversion:
• Logic: RSI extremes with reversal confirmation
• Triggers: RSI < 30 with uptick OR RSI > 70 with downtick
• Philosophy: Fade overbought/oversold extremes
• Best in: Ranging markets, mean-reverting instruments
• Weakness: Fails in strong trends, catches falling knives
ARM 4 - Z-Score Statistical Reversion:
• Logic: Price deviation from 50-period mean
• Triggers: Z-score < -2 (oversold) OR > +2 (overbought) with reversal
• Philosophy: Statistical bounds reversion
• Best in: Stable volatility regimes, pairs trading
• Weakness: Trend continuation through extremes
ARM 5 - ADX Momentum:
• Logic: Strong directional movement with acceleration
• Triggers: ADX > 30 with DI+ or DI- strengthening
• Philosophy: Momentum begets momentum
• Best in: Trending with increasing velocity
• Weakness: Late exits, momentum exhaustion
ARM 6 - Volume Confirmation:
• Logic: OBV trend + volume spike + candle direction
• Triggers: OBV > EMA(20) AND volume > average AND bullish candle
• Philosophy: Follow institutional money flow
• Best in: Liquid markets with reliable volume
• Weakness: Manipulated volume, thin markets
Q-Learning with Rewards:
Each arm maintains a Q-value representing its expected reward. After every bar, the system calculates a reward based on the arm's signal and actual price movement:
Reward Calculation:
If arm signaled LONG:
reward = (close - close[1]) / close[1]
If arm signaled SHORT:
reward = -(close - close[1]) / close[1]
If arm signaled NEUTRAL:
reward = 0
Penalty multiplier: If loss > 0.5%, reward × 1.3 (punish big losses harder)
Q-Value Update (Exponential Moving Average):
Q_new = Q_old + α × (reward - Q_old)
Where α (learning rate, default 0.08) controls adaptation speed:
• Low α (0.01-0.05): Slow, stable learning
• Medium α (0.06-0.12): Balanced (recommended)
• High α (0.15-0.30): Fast, reactive learning
This gradually shifts Q-values toward arms that generate positive returns and away from losing arms.
Arm Selection Algorithms:
KMD offers four mathematically distinct selection strategies:
1. UCB1 (Upper Confidence Bound) - Recommended:
Formula: Select arm with max(Q_i + c·√(ln(t)/n_i))
Where:
• Q_i = Q-value of arm i
• c = exploration constant (default 1.5)
• t = total pulls across all arms
• n_i = pulls of arm i
Philosophy: Balance exploitation (use best arm) with exploration (try uncertain arms). The √(ln(t)/n_i) term creates an "exploration bonus" that decreases as an arm gets more pulls, ensuring all arms get sufficient testing.
Theoretical guarantee: Logarithmic regret bound - UCB1 provably converges to optimal arm selection over time.
2. UCB1-Tuned (Variance-Aware UCB):
Formula: Select arm with max(Q_i + √(ln(t)/n_i × min(0.25, V_i + √(2·ln(t)/n_i))))
Where V_i = variance of rewards for arm i
Philosophy: Incorporates reward variance into exploration. Arms with high variance (unpredictable) get less exploration bonus, focusing effort on stable performers.
Better bounds than UCB1 in practice, slightly more conservative exploration.
3. Epsilon-Greedy (Simple Random):
Algorithm:
With probability ε: Select random arm (explore)
With probability 1-ε: Select highest Q-value arm (exploit)
Default ε = 0.10 (10% exploration, 90% exploitation)
Philosophy: Simplest algorithm, easy to understand. Random exploration ensures all arms stay updated but may waste time on clearly bad arms.
4. Thompson Sampling (Bayesian):
The most sophisticated selection algorithm, using true Bayesian probability.
Each arm maintains Beta distribution parameters:
• α (alpha) = successes + 1
• β (beta) = failures + 1
Selection Process:
1. Sample θ_i ~ Beta(α_i, β_i) for each arm using Marsaglia-Tsang Gamma sampler
2. Select arm with highest sample: argmax_i(θ_i)
3. After reward, update:
- If reward > 0: α += |reward| × 100 (increment successes)
- If reward < 0: β += |reward| × 100 (increment failures)
Why Thompson Sampling Works:
The Beta distribution naturally represents uncertainty about an arm's true win rate. Early on with few trials, the distribution is wide (high uncertainty), leading to more exploration. As evidence accumulates, it narrows around the true performance, naturally shifting toward exploitation.
Unlike UCB which uses deterministic confidence bounds, Thompson Sampling is probabilistic—it samples from the posterior distribution of each arm's success rate, providing automatic exploration/exploitation balance without tuning.
Comparison:
• UCB1: Deterministic, guaranteed regret bounds, requires tuning exploration constant
• Thompson: Probabilistic, natural exploration, no tuning required, best empirical performance
• Epsilon-Greedy: Simplest, consistent exploration %, less efficient
• UCB1-Tuned: UCB1 + variance awareness, best for risk-averse
Exploration Constant (c):
For UCB algorithms, this multiplies the exploration bonus:
• Low c (0.5-1.0): Strongly prefer proven arms, rare exploration
• Medium c (1.2-1.8): Balanced (default 1.5)
• High c (2.0-3.0): Frequent exploration, diverse arm usage
Higher exploration constant in volatile/unstable markets, lower in stable trending environments.
🔬 WALK-FORWARD OPTIMIZATION: PREVENTING OVERFITTING
The single biggest problem in algorithmic trading is overfitting—strategies that look amazing in backtest but fail in live trading because they learned noise instead of signal. KMD's Walk-Forward Optimization system addresses this head-on.
How WFO Works:
The system divides time into repeating cycles:
1. Training Window (default 500 bars): Learn arm Q-values on historical data
2. Testing Window (default 100 bars): Validate on unseen "future" data
Training Phase:
• All arms accumulate rewards and update Q-values normally
• Q_train tracks in-sample performance
• System learns which arms work on historical data
Testing Phase:
• System continues using arms but tracks separate Q_test metrics
• Counts trades per arm (N_test)
• Testing performance is "out-of-sample" relative to training
Validation Requirements:
An arm is only "validated" (approved for live use) if:
1. N_test ≥ Minimum Trades (default 10): Sufficient statistical sample
2. Q_test > 0: Positive out-of-sample performance
Arms that fail validation are blocked from generating signals, preventing the system from trading strategies that only worked on historical data.
Performance Decay:
At the end of each WFO cycle, all Q-values decay exponentially:
Q_new = Q_old × decay_rate (default 0.95)
This ensures old performance doesn't dominate forever. An arm that worked 10 cycles ago but fails recently will eventually lose influence.
Decay Math:
• 0.95 decay after 10 periods → 0.95^10 = 0.60 (40% forgotten)
• 0.90 decay after 10 periods → 0.90^10 = 0.35 (65% forgotten)
Fast decay (0.80-0.90): Quick adaptation, forgets old patterns rapidly
Slow decay (0.96-0.99): Stable, retains historical knowledge longer
WFO Efficiency Metric:
The key metric revealing overfitting:
Efficiency = (Q_test / Q_train) for each validated arm, averaged
• Efficiency > 0.8: Excellent - strategies generalize well (LOW overfit risk)
• Efficiency 0.5-0.8: Acceptable - moderate generalization (MODERATE risk)
• Efficiency < 0.5: Poor - strategies curve-fitted to history (HIGH risk)
If efficiency is low, the system has learned noise. Training performance was good but testing (forward) performance is weak—classic overfitting.
The dashboard displays real-time WFO efficiency, allowing users to gauge system robustness. Low efficiency should trigger parameter review or reduced position sizing.
Why WFO Matters:
Consider two scenarios:
Scenario A - No WFO:
• Arm 3 (RSI Reversion) shows Q-value of 0.15 on all historical data
• System trades it aggressively
• Reality: It only worked during one specific ranging period
• Live trading: Fails because market has trended since backtest
Scenario B - With WFO:
• Arm 3 shows Q_train = 0.15 (good in training)
• But Q_test = -0.05 (loses in testing) with 12 test trades
• N_test ≥ 10 but Q_test < 0 → Arm BLOCKED
• System refuses to trade it despite good backtest
• Live trading: Protected from false strategy
WFO ensures only strategies that work going forward get used, not just strategies that fit the past.
Optimal Window Sizing:
Training Window:
• Too short (100-300): May learn recent noise, insufficient data
• Too long (1000-2000): May include obsolete market regimes
• Recommended: 4-6× testing window (default 500)
Testing Window:
• Too short (50-80): Insufficient validation, high variance
• Too long (300-500): Delayed adaptation to regime changes
• Recommended: 1/5 to 1/4 of training (default 100)
Minimum Trades:
• Too low (5-8): Statistical noise, lucky runs validate
• Too high (30-50): Many arms never validate, system rarely trades
• Recommended: 10-15 (default 10)
⚖️ WEIGHTED CONFLUENCE SYSTEM: MULTI-FACTOR SIGNAL QUALITY
Not all signals are created equal. KMD implements a sophisticated 100-point quality scoring system that combines eight independent factors with different importance weights.
The Scoring Framework:
Each potential signal receives a quality score from 0-100 by accumulating points from aligned factors:
CRITICAL FACTORS (20 points each):
1. Bandit Arm Alignment (20 points):
• Full points if selected arm's signal matches trade direction
• Zero points if arm disagrees
• Weight: Highest - the bandit selected this arm for a reason
2. MMD Regime Quality (20 points):
• Requires: MMD > dynamic threshold AND directional bias confirmed
• Scaled by MMD percentile (how extreme vs history)
• If MMD in top 10% of history: 100% of 20 points
• If MMD at 50th percentile: 50% of 20 points
• Weight: Highest - distribution shift is the core signal
HIGH IMPACT FACTORS (15 points each):
3. Trend Alignment (15 points):
• Full points if EMA(9) > EMA(21) > EMA(50) for longs (inverse for shorts)
• Scaled by ADX strength:
- ADX > 25: 100% (1.0× multiplier) - strong trend
- ADX 20-25: 70% (0.7× multiplier) - moderate trend
- ADX < 20: 40% (0.4× multiplier) - weak trend
• Weight: High - trend is friend, alignment increases probability
4. Volume Confirmation (15 points):
• Requires: OBV > EMA(OBV, 20) aligned with direction
• Scaled by volume ratio: vol_current / vol_average
- Volume 1.5×+ average: 100% of points (institutional participation)
- Volume 1.0-1.5× average: 67% of points (above average)
- Volume below average: 0 points (weak conviction)
• Weight: High - volume validates price moves
MODERATE FACTORS (10 points each):
5. Market Structure (10 points):
• Full points (10) if bullish structure (higher highs, higher lows) for longs
• Partial points (6) if near support level (within 1% of swing low)
• Similar logic inverted for bearish trades
• Weight: Moderate - structure context improves entries
6. RSI Positioning (10 points):
• For long signals:
- RSI < 50: 100% of points (1.0× multiplier) - room to run
- RSI 50-60: 60% of points (0.6× multiplier) - neutral
- RSI 60-70: 30% of points (0.3× multiplier) - elevated
- RSI > 70: 0 points (0× multiplier) - overbought
• Inverse for short signals
• Weight: Moderate - momentum context, not primary signal
BONUS FACTORS (10 points each):
7. Divergence (10 points):
• Full 10 points if bullish divergence detected for long (or bearish for short)
• Zero points otherwise
• Weight: Bonus - leading indicator, adds confidence when present
8. Multi-Timeframe Confirmation (10 points):
• Full 10 points if higher timeframe aligned (HTF EMA trending same direction, RSI supportive)
• Zero points if MTF disabled or HTF opposes
• Weight: Bonus - macro context filter, prevents counter-trend disasters
Total Maximum: 110 points (20+20+15+15+10+10+10+10)
Signal Quality Calculation:
Quality Score = (Accumulated_Points / Maximum_Possible) × 100
Where Maximum_Possible = 110 points if all factors active, adjusts if MTF disabled.
Example Calculation:
Long signal candidate:
• Bandit Arm: +20 (arm signals long)
• MMD Quality: +16 (MMD high, 80th percentile)
• Trend: +11 (EMAs aligned, ADX = 22 → 70% × 15)
• Volume: +10 (OBV rising, vol 1.3× avg → 67% × 15 = 10)
• Structure: +10 (higher lows forming)
• RSI: +6 (RSI = 55 → 60% × 10)
• Divergence: +0 (none present)
• MTF: +10 (HTF bullish)
Total: 83 / 110 × 100 = 75.5% quality score
This is an excellent quality signal - well above threshold (default 60%).
Quality Thresholds:
• Score 80-100: Exceptional setup - all factors aligned
• Score 60-80: High quality - most factors supportive (default minimum)
• Score 40-60: Moderate - mixed confluence, proceed with caution
• Score 20-40: Weak - minimal support, likely filtered out
• Score 0-20: Very weak - almost certainly blocked
The minimum quality threshold (default 60) is the gatekeeper. Only signals scoring above this value can trigger trades.
Dynamic Threshold Adjustment:
The system optionally adjusts the threshold based on historical signal distribution:
If Dynamic Threshold enabled:
Recent_MMD_Mean = SMA(MMD, 50)
Recent_MMD_StdDev = StdDev(MMD, 50)
Dynamic_Threshold = max(Base_Threshold × 0.5,
min(Base_Threshold × 2.0,
MMD_Mean + MMD_StdDev × 0.5))
This auto-calibrates to market conditions:
• Quiet markets (low MMD): Threshold loosens (0.5× base)
• Active markets (high MMD): Threshold tightens (2× base)
Signal Ranking Filter:
When enabled, the system tracks the last 100 signal quality scores and only fires signals in the top percentile.
If Ranking Percentile = 75%:
• Collect last 100 signal scores in memory
• Sort ascending
• Threshold = Score at 75th percentile position
• Only signals ≥ this threshold fire
This ensures you're only taking the cream of the crop—top 25% of signals by quality, not every signal that technically qualifies.
🚦 SIGNAL GENERATION: TRANSITION LOGIC & COOLDOWNS
The confluence system determines if a signal qualifies, but the signal generation logic controls when triangles appear on the chart.
Core Qualification:
For a LONG signal to qualify:
1. Bull quality score ≥ signal threshold (default 60)
2. Selected arm signals +1 (long)
3. Cooldown satisfied (bars since last signal ≥ cooldown period)
4. Drawdown protection OK (current drawdown < pause threshold)
5. MMD ≥ 80% of dynamic threshold (slight buffer below full threshold)
For a SHORT signal to qualify:
1. Bear quality score ≥ signal threshold
2. Selected arm signals -1 (short)
3-5. Same as long
But qualification alone doesn't trigger a chart signal.
Three Signal Modes:
1. RESPONSIVE (Default - Recommended):
Signals appear on:
• Fresh qualification (wasn't qualified last bar, now is)
• Direction reversal (was qualified short, now qualified long)
• Quality improvement (already qualified, quality jumps 25%+ during EXTREME regime)
This mode shows new opportunities and significant upgrades without cluttering the chart with repeat signals.
2. TRANSITION ONLY:
Signals appear on:
• Fresh qualification only
• Direction reversal only
This is the cleanest mode - signals only when first qualifying or when flipping direction. Misses re-entries if quality improves mid-regime.
3. CONTINUOUS:
Signals appear on:
• Every bar that qualifies
Testing/debugging mode - shows all qualified bars. Very noisy but useful for understanding when system wants to trade.
Cooldown System:
Prevents signal clustering and overtrading by enforcing minimum bars between signals.
Base Cooldown: User-defined (default 5 bars)
Adaptive Cooldown (Optional):
If enabled, cooldown scales with volatility:
Effective_Cooldown = Base_Cooldown × volatility_multiplier
Where:
ATR_Pct = ATR(14) / Close × 100
Volatility_Multiplier = max(0.5, min(3.0, ATR_Pct / 2.0))
• Low volatility (ATR 1%): Multiplier ~0.5× → Cooldown = 2-3 bars (tight)
• Medium volatility (ATR 2%): Multiplier 1.0× → Cooldown = 5 bars (normal)
• High volatility (ATR 4%+): Multiplier 2.0-3.0× → Cooldown = 10-15 bars (wide)
This prevents excessive trading during wild swings while allowing more signals during calm periods.
Regime Filter:
Three modes controlling which regimes allow trading:
OFF: Trade in any regime (STABLE, TRENDING, SHIFTING, ELEVATED, EXTREME)
SMART (Recommended):
• Regime score = 1.0 for SHIFTING, ELEVATED (optimal)
• Regime score = 0.8 for TRENDING (acceptable)
• Regime score = 0.5 for EXTREME (too chaotic)
• Regime score = 0.2 for STABLE (too quiet)
Quality scores are multiplied by regime score. A 70% quality signal in STABLE regime becomes 70% × 0.2 = 14% → blocked.
STRICT:
• Regime score = 1.0 for SHIFTING, ELEVATED only
• Regime score = 0.0 for all others → hard block
Only trades during optimal distribution shift regimes.
Drawdown Protection:
If current equity drawdown exceeds pause threshold (default 8%), all signals are blocked until equity recovers.
This circuit breaker prevents compounding losses during adverse conditions or broken market structure.
🎯 RISK MANAGEMENT: ATR-BASED STOPS & TARGETS
Every signal generates volatility-normalized stop loss and target levels displayed as boxes on the chart.
Stop Loss Calculation:
Stop_Distance = ATR(14) × ATR_Multiplier (default 1.5)
For LONG: Stop = Entry - Stop_Distance
For SHORT: Stop = Entry + Stop_Distance
The stop is placed 1.5 ATRs away from entry by default, adapting automatically to instrument volatility.
Target Calculation:
Target_Distance = Stop_Distance × Risk_Reward_Ratio (default 2.0)
For LONG: Target = Entry + Target_Distance
For SHORT: Target = Entry - Target_Distance
Default 2:1 risk/reward means target is twice as far as stop.
Example:
• Price: $100
• ATR: $2
• ATR Multiplier: 1.5
• Risk/Reward: 2.0
LONG Signal:
• Entry: $100
• Stop: $100 - ($2 × 1.5) = $97.00 (-$3 risk)
• Target: $100 + ($3 × 2.0) = $106.00 (+$6 reward)
• Risk/Reward: $3 risk for $6 reward = 1:2 ratio
Target/Stop Box Lifecycle:
Boxes persist for a lifetime (default 20 bars) OR until an opposite signal fires, whichever comes first. This provides visual reference for active trade levels without permanent chart clutter.
When a new opposite-direction signal appears, all existing boxes from the previous direction are immediately deleted, ensuring only relevant levels remain visible.
Adaptive Stop/Target Sizing:
While not explicitly coded in the current version, the shadow portfolio tracking system calculates PnL based on these levels. Users can observe which ATR multipliers and risk/reward ratios produce optimal results for their instrument/timeframe via the dashboard performance metrics.
📊 COMPREHENSIVE VISUAL SYSTEM
KMD provides rich visual feedback through four distinct layers:
1. PROBABILITY CLOUD (Adaptive Volatility Bands):
Two sets of bands around price that expand/contract with MMD:
Calculation:
Std_Multiplier = 1 + MMD × 3
Upper_1σ = Close + ATR × Std_Multiplier × 0.5
Lower_1σ = Close - ATR × Std_Multiplier × 0.5
Upper_2σ = Close + ATR × Std_Multiplier
Lower_2σ = Close - ATR × Std_Multiplier
• Inner band (±0.5× adjusted ATR): 68% probability zone (1 standard deviation equivalent)
• Outer band (±1.0× adjusted ATR): 95% probability zone (2 standard deviation equivalent)
When MMD spikes, bands widen dramatically, showing increased uncertainty. When MMD calms, bands tighten, showing normal price action.
2. MOMENTUM FLOW VECTORS (Directional Arrows):
Dynamic arrows that visualize momentum strength and direction:
Arrow Properties:
• Length: Proportional to momentum magnitude (2-10 bars forward)
• Width: 1px (weak), 2px (medium), 3px (strong)
• Transparency: 30-100 (more opaque = stronger momentum)
• Direction: Up for bullish, down for bearish
• Placement: Below bars (bulls) or above bars (bears)
Trigger Logic:
• Always appears every 5 bars (regular sampling)
• Forced appearance if momentum strength > 50 OR regime shift OR MMD velocity > 10%
Strong momentum (>75%) gets:
• Secondary support arrow (70% length, lighter color)
• Label showing "75%" strength
Very strong momentum (>60%) gets:
• Gradient flow lines (thick vertical lines showing momentum vector)
This creates a dynamic "flow field" showing where market pressure is pushing price.
3. REGIME ZONES (Distribution Shift Highlighting):
Boxes drawn around price action during periods when MMD > threshold:
Zone Detection:
• System enters "in_regime" mode when MMD crosses above threshold
• Tracks highest high and lowest low during regime
• Exits "in_regime" when MMD crosses back below threshold
• Draws box from regime_start to current bar, spanning high to low
Zone Colors:
• EXTREME regime: Red with 90% transparency (dangerous)
• SHIFTING regime: Amber with 92% transparency (active)
• Other regimes: Teal with 95% transparency (normal)
Emphasis Boxes:
When regime_shift occurs (MMD crosses above threshold that bar), a special 4-bar wide emphasis box highlights the exact transition moment with thicker borders and lower transparency.
This visual immediately shows "the market just changed" moments.
4. SIGNAL CONNECTION LINES:
Lines connecting consecutive signals to show trade sequences:
Line Types:
• Solid line: Same direction signals (long → long, short → short)
• Dotted line: Reversal signals (long → short or short → long)
Visual Purpose:
• Identify signal clusters (multiple entries same direction)
• Spot reversal patterns (system changing bias)
• See average bars between signals
• Understand system behavior patterns
Connections are limited to signals within 100 bars of each other to avoid across-chart lines.
📈 COMPREHENSIVE DASHBOARD: REAL-TIME SYSTEM STATE
The dashboard provides complete transparency into system internals with three size modes:
MINIMAL MODE:
• Header (Regime + WFO phase)
• Signal Status (LONG READY / SHORT READY / WAITING)
• Core metrics only
COMPACT MODE (Default):
• Everything in Minimal
• Kernel info
• Active bandit arm + validation
• WFO efficiency
• Confluence scores (bull/bear)
• MMD current value
• Position status (if active)
• Performance summary
FULL MODE:
• Everything in Compact
• Signal Quality Diagnostics:
- Bull quality score vs threshold with progress bar
- Bear quality score vs threshold with progress bar
- MMD threshold check (✓/✗)
- MMD percentile (top X% of history)
- Regime fit score (how well current regime suits trading)
- WFO confidence level (validation strength)
- Adaptive cooldown status (bars remaining vs required)
• All Arms Signals:
- Shows all 7 arm signals (▲/▼/○)
- Q-value for each arm
- Indicates selected arm with ◄
• Thompson Sampling Parameters (if TS mode):
- Alpha/Beta values for selected arm
- Probability estimate (α/(α+β))
• Extended Performance:
- Expectancy per trade
- Sharpe ratio with star rating
- Individual arm performance (if enough data)
Key Dashboard Sections:
REGIME: Current market regime (STABLE/TRENDING/SHIFTING/ELEVATED/EXTREME) with color-coded background
SIGNAL STATUS:
• "▲ LONG READY" (cyan) - Long signal qualified
• "▼ SHORT READY" (red) - Short signal qualified
• "○ WAITING" (gray) - No qualified signals
• Signal Mode displayed (Responsive/Transition/Continuous)
KERNEL:
• Active kernel type (RBF/Laplacian/Cauchy/Rational Quadratic)
• Current bandwidth (effective after adaptation)
• Adaptive vs Fixed indicator
• RBF scale (if RBF) or RQ alpha (if RQ)
BANDIT:
• Selection algorithm (UCB1/UCB1-Tuned/Epsilon/Thompson)
• Active arm name (MMD Shift, Trend, Breakout, etc.)
• Validation status (✓ if validated, ? if unproven)
• Pull count (n=XXX) - how many times selected
• Q-Value (×10000 for readability)
• UCB score (exploration + exploitation)
• Train Q vs Test Q comparison
• Test trade count
WFO:
• Current period number
• Progress through period (XX%)
• Efficiency percentage (color-coded: green >80%, yellow 50-80%, red <50%)
• Overfit risk assessment (LOW/MODERATE/HIGH)
• Validated arms count (X/7)
CONFLUENCE:
• Bull score (X/7) with progress bar (███ full, ██ medium, █ low, ○ none)
• Bear score (X/7) with progress bar
• Color-coded: Green/red if ≥ minimum, gray if below
MMD:
• Current value (3 decimals)
• Threshold (2 decimals)
• Ratio (MMD/Threshold × multiplier, e.g. "1.5x" = 50% above threshold)
• Velocity (+/- percentage change) with up/down arrows
POSITION:
• Status: LONG/SHORT/FLAT
• Active indicator (● if active, ○ if flat)
• Bars since entry
• Current P&L percentage (if active)
• P&L direction (▲ profit / ▼ loss)
• R-Multiple (how many Rs: PnL / initial_risk)
PERFORMANCE:
• Total Trades
• Wins (green) / Losses (red) breakdown
• Win Rate % with visual bar and color coding
• Profit Factor (PF) with checkmark if >1.0
• Expectancy % (average profit per trade)
• Sharpe Ratio with star rating (★★★ >2, ★★ >1, ★ >0, ○ negative)
• Max DD % (maximum drawdown) with "Now: X%" showing current drawdown
🔧 KEY PARAMETERS EXPLAINED
Kernel Configuration:
• Kernel Function: RBF / Laplacian / Cauchy / Rational Quadratic
- Start with Cauchy for stability, experiment with others
• Bandwidth (σ) (0.5-10.0, default 2.0): Kernel sensitivity
- Lower: More signals, more false positives (scalping: 0.8-1.5)
- Medium: Balanced (swing: 1.5-3.0)
- Higher: Fewer signals, stronger quality (position: 3.0-8.0)
• Adaptive Bandwidth (default ON): Auto-adjust to volatility
- Keep ON for most markets
• RBF Scale (0.1-2.0, default 0.5): RBF-specific scaling
- Only matters if RBF kernel selected
- Lower = more sensitive (0.3 for scalping)
- Higher = less sensitive (1.0+ for position)
• RQ Alpha (0.5-5.0, default 2.0): Rational Quadratic tail behavior
- Only matters if RQ kernel selected
- Low (0.5-1.0): Heavy tails, robust to outliers (like Cauchy)
- High (3.0-5.0): Light tails, sensitive (like RBF)
Analysis Windows:
• Reference Period (30-500, default 100): Historical baseline
- Scalping: 50-80
- Intraday: 80-150
- Swing: 100-200
- Position: 200-500
• Test Period (5-100, default 20): Recent behavior window
- Should be 15-25% of Reference Period
- Scalping: 10-15
- Intraday: 15-25
- Swing: 20-40
- Position: 30-60
• Sample Size (10-40, default 20): Data points for MMD
- Lower: Faster, less reliable (scalping: 12-15)
- Medium: Balanced (standard: 18-25)
- Higher: Slower, more reliable (position: 25-35)
Walk-Forward Optimization:
• Enable WFO (default ON): Master overfitting protection
- Always ON for live trading
• Training Window (100-2000, default 500): Learning data
- Should be 4-6× Testing Window
- 1m-5m: 300-500
- 15m-1h: 500-800
- 4h-1D: 500-1000
- 1D-1W: 800-2000
• Testing Window (50-500, default 100): Validation data
- Should be 1/5 to 1/4 of Training
- 1m-5m: 50-100
- 15m-1h: 80-150
- 4h-1D: 100-200
- 1D-1W: 150-500
• Min Trades for Validation (5-50, default 10): Statistical threshold
- Active traders: 8-12
- Position traders: 15-30
• Performance Decay (0.8-0.99, default 0.95): Old data forgetting
- Aggressive: 0.85-0.90 (volatile markets)
- Moderate: 0.92-0.96 (most use cases)
- Conservative: 0.97-0.99 (stable markets)
Multi-Armed Bandit:
• Learning Rate (α) (0.01-0.3, default 0.08): Adaptation speed
- Low: 0.01-0.05 (position trading, stable)
- Medium: 0.06-0.12 (day/swing trading)
- High: 0.15-0.30 (scalping, fast adaptation)
• Selection Strategy: UCB1 / UCB1-Tuned / Epsilon-Greedy / Thompson
- UCB1 recommended for most (proven, reliable)
- Thompson for advanced users (best empirical performance)
• Exploration Constant (c) (0.5-3.0, default 1.5): Explore vs exploit
- Low: 0.5-1.0 (conservative, proven strategies)
- Medium: 1.2-1.8 (balanced)
- High: 2.0-3.0 (experimental, volatile markets)
• Epsilon (0.0-0.3, default 0.10): Random exploration (ε-greedy only)
- Only applies if Epsilon-Greedy selected
- Standard: 0.10 (10% random)
Signal Configuration:
• MMD Threshold (0.05-1.0, default 0.15): Distribution divergence trigger
- Low: 0.08-0.12 (scalping, sensitive)
- Medium: 0.12-0.20 (day/swing)
- High: 0.25-0.50 (position, strong signals)
- Stocks/indices: 0.12-0.18
- Forex: 0.15-0.25
- Crypto: 0.20-0.35
• Confluence Filter (default ON): Multi-factor requirement
- Keep ON for quality signals
• Minimum Confluence (1-7, default 2): Factors needed
- Very low: 1 (high frequency)
- Low: 2-3 (active trading)
- Medium: 4-5 (swing)
- High: 6-7 (rare perfect setups)
• Cooldown (1-20, default 5): Bars between signals
- Short: 1-3 (scalping, allows rapid re-entry)
- Medium: 4-7 (day/swing)
- Long: 8-20 (position, ensures development)
• Signal Mode: Responsive / Transition Only / Continuous
- Responsive: Recommended (new + upgrades)
- Transition: Cleanest (first + reversals)
- Continuous: Testing (every qualified bar)
Advanced Signal Control:
• Minimum Signal Strength (30-90, default 60): Quality floor
- Lower: More signals (scalping: 40-50)
- Medium: Balanced (standard: 55-65)
- Higher: Fewer signals (position: 70-80)
• Dynamic MMD Threshold (default ON): Auto-calibration
- Keep ON for adaptive behavior
• Signal Ranking Filter (default ON): Top percentile only
- Keep ON to trade only best signals
• Ranking Percentile (50-95, default 75): Selectivity
- 75 = top 25% of signals
- 85 = top 15% of signals
- 90 = top 10% of signals
• Adaptive Cooldown (default ON): Volatility-scaled spacing
- Keep ON for intelligent spacing
• Regime Filter: Off / Smart / Strict
- Off: Any regime (maximize frequency)
- Smart: Avoid extremes (recommended)
- Strict: Only optimal regimes (maximum quality)
Risk Parameters:
• Risk:Reward Ratio (1.0-5.0, default 2.0): Target distance multiplier
- Conservative: 1.0-1.5 (higher WR needed)
- Balanced: 2.0-2.5 (standard professional)
- Aggressive: 3.0-5.0 (lower WR acceptable)
• Stop Loss (ATR mult) (0.5-4.0, default 1.5): Stop distance
- Tight: 0.5-1.0 (scalping, low vol)
- Medium: 1.2-2.0 (day/swing)
- Wide: 2.5-4.0 (position, high vol)
• Pause After Drawdown (2-20%, default 8%): Circuit breaker
- Aggressive: 3-6% (small accounts)
- Moderate: 6-10% (most traders)
- Relaxed: 10-15% (large accounts)
Multi-Timeframe:
• MTF Confirmation (default OFF): Higher TF filter
- Turn ON for swing/position trading
- Keep OFF for scalping/day trading
• Higher Timeframe (default "60"): HTF for trend check
- Should be 3-5× chart timeframe
- 1m chart → 5m or 15m
- 5m chart → 15m or 60m
- 15m chart → 60m or 240m
- 1h chart → 240m or D
Display:
• Probability Cloud (default ON): Volatility bands
• Momentum Flow Vectors (default ON): Directional arrows
• Regime Zones (default ON): Distribution shift boxes
• Signal Connections (default ON): Lines between signals
• Dashboard (default ON): Stats table
• Dashboard Position: Top Left / Top Right / Bottom Left / Bottom Right
• Dashboard Size: Minimal / Compact / Full
• Color Scheme: Default / Monochrome / Warm / Cool
• Show MMD Debug Plot (default OFF): Overlay MMD value
- Turn ON temporarily for threshold calibration
🎓 PROFESSIONAL USAGE PROTOCOL
Phase 1: Parameter Calibration (Week 1)
Goal: Find optimal kernel and bandwidth for your instrument/timeframe
Setup:
• Enable "Show MMD Debug Plot"
• Start with Cauchy kernel, 2.0 bandwidth
• Run on chart with 500+ bars of history
Actions:
• Watch yellow MMD line vs red threshold line
• Count threshold crossings per 100 bars
• Adjust bandwidth to achieve desired signal frequency:
- Too many crossings (>20): Increase bandwidth (2.5-3.5)
- Too few crossings (<5): Decrease bandwidth (1.2-1.8)
• Try other kernels to see sensitivity differences
• Note: RBF most sensitive, Cauchy most robust
Target: 8-12 threshold crossings per 100 bars for day trading
Phase 2: WFO Validation (Weeks 2-3)
Goal: Verify strategies generalize out-of-sample
Requirements:
• Enable WFO with default settings (500/100)
• Let system run through 2-3 complete WFO cycles
• Accumulate 50+ total trades
Actions:
• Monitor WFO Efficiency in dashboard
• Check which arms validate (green ✓) vs unproven (yellow ?)
• Review Train Q vs Test Q for selected arm
• If efficiency < 0.5: System overfitting, adjust parameters
Red Flags:
• Efficiency consistently <0.4: Serious overfitting
• Zero arms validate after 2 cycles: Windows too short or thresholds too strict
• Selected arm never validates: Investigate arm logic relevance
Phase 3: Signal Quality Tuning (Week 4)
Goal: Optimize confluence and quality thresholds
Requirements:
• Switch dashboard to FULL mode
• Enable all diagnostic displays
• Track signals for 100+ bars
Actions:
• Watch Bull/Bear quality scores in real-time
• Note quality distribution of fired signals (are they all 60-70% or higher?)
• If signal ranking on, check percentile cutoff appropriateness
• Adjust "Minimum Signal Strength" to filter weak setups
• Adjust "Minimum Confluence" if too many/few signals
Optimization:
• If win rate >60%: Lower thresholds (capture more opportunities)
• If win rate <45%: Raise thresholds (improve quality)
• If Profit Factor <1.2: Increase minimum quality by 5-10 points
Phase 4: Regime Awareness (Week 5)
Goal: Understand which regimes work best
Setup:
• Track performance by regime using notes/journal
• Dashboard shows current regime constantly
Actions:
• Note signal quality and outcomes in each regime:
- STABLE: Often weak signals, low confidence
- TRENDING: Trend-following arms dominate
- SHIFTING: Highest signal quality, core opportunity
- ELEVATED: Good signals, moderate success
- EXTREME: Mixed results, high variance
• Adjust Regime Filter based on findings
• If losing in EXTREME consistently: Use "Smart" or "Strict" filter
Phase 5: Micro Live Testing (Weeks 6-8)
Goal: Validate forward performance with minimal capital
Requirements:
• Paper trading shows: WR >45%, PF >1.2, Efficiency >0.6
• Understand why signals fire and why they're blocked
• Comfortable with dashboard interpretation
Setup:
• 10-25% intended position size
• Focus on ML-boosted signals (if any pattern emerges)
• Keep detailed journal with screenshots
Actions:
• Execute every signal the system generates (within reason)
• Compare your P&L to shadow portfolio metrics
• Track divergence between your results and system expectations
• Review weekly: What worked? What failed? Any execution issues?
Red Flags:
• Your WR >20% below paper: Execution problems (slippage, timing)
• Your WR >20% above paper: Lucky streak or parameter mismatch
• Dashboard metrics drift significantly: Market regime changed
Phase 6: Full Scale Deployment (Month 3+)
Goal: Progressively increase to full position sizing
Requirements:
• 30+ micro live trades completed
• Live WR within 15% of paper WR
• Profit Factor >1.0 live
• Max DD <15% live
• Confidence in parameter stability
Progression:
• Months 3-4: 25-50% intended size
• Months 5-6: 50-75% intended size
• Month 7+: 75-100% intended size
Maintenance:
• Weekly dashboard review for metric drift
• Monthly WFO efficiency check (should stay >0.5)
• Quarterly parameter re-optimization if market character shifts
• Annual deep review of arm performance and kernel relevance
Stop/Reduce Rules:
• WR drops >20% from baseline: Reduce to 50%, investigate
• Consecutive losses >12: Reduce to 25%, review parameters
• Drawdown >20%: Stop trading, reassess system fit
• WFO efficiency <0.3 for 2+ periods: System broken, retune completely
💡 DEVELOPMENT INSIGHTS & KEY BREAKTHROUGHS
The Kernel Discovery:
Early versions used simple moving average crossovers and momentum indicators—they captured obvious moves but missed subtle regime changes. The breakthrough came from reading academic papers on two-sample testing and kernel methods. Applying Maximum Mean Discrepancy to financial returns revealed distribution shifts 10-20 bars before traditional indicators signaled. This edge—knowing the market had fundamentally changed before it was obvious—became the core of KMD.
Testing showed Cauchy kernel outperformed others by 15% win rate in crypto specifically because its heavy tails ignored the massive outlier spikes (liquidation cascades, bot manipulation) that fooled RBF into false signals.
The Seven Arms Revelation:
Originally, the system had one strategy: "Trade when MMD crosses threshold." Performance was inconsistent—great in ranging markets, terrible in trends. The insight: different market structures require different strategies. Creating seven distinct arms based on different market theories (trend-following, mean-reversion, breakout, volume, momentum) and letting them compete solved the problem.
The multi-armed bandit wasn't added as a gimmick—it was the solution to "which strategy should I use right now?" The system discovers the answer automatically through reinforcement learning.
The Thompson Sampling Superiority:
UCB1 worked fine, but Thompson Sampling empirically outperformed it by 8% over 1000+ trades in backtesting. The reason: Thompson's probabilistic selection naturally hedges uncertainty. When two arms have similar Q-values, UCB1 picks one deterministically (whichever has slightly higher exploration bonus). Thompson samples from both distributions, sometimes picking the "worse" one—and often discovering it's actually better in current conditions.
Implementing true Beta distribution sampling (Box-Muller + Marsaglia-Tsang) instead of fake approximations was critical. Fake Thompson (using random with bias) underperformed UCB1. Real Thompson with proper Bayesian updating dominated.
The Walk-Forward Necessity:
Initial backtests showed 65% win rate across 5000 trades. Live trading: 38% win rate over first 100 trades. Crushing disappointment. The problem: overfitting. The training data included the test data (look-ahead bias). Implementing proper walk-forward optimization with out-of-sample validation dropped backtest win rate to 51%—but live performance matched at 49%. That's a system you can trust.
WFO efficiency metric became the North Star. If efficiency >0.7, live results track paper. If efficiency <0.5, prepare for disappointment.
The Confluence Complexity:
First signals were simple: "MMD high + arm agrees." This generated 200+ signals on 1000 bars with 42% win rate—not tradeable. Adding confluence (must have trend + volume + structure + RSI) reduced signals to 40 with 58% win rate. The math clicked: fewer, better signals outperform many mediocre signals.
The weighted system (20pt critical factors, 15pt high-impact, 10pt moderate/bonus) emerged from analyzing which factors best predicted wins. Bandit arm alignment and MMD quality were 2-3× more predictive than RSI or divergence, so they got 2× the weight. This isn't arbitrary—it's data-driven.
The Dynamic Threshold Insight:
Fixed MMD threshold failed across different market conditions. 0.15 worked perfectly on ES but fired constantly on Bitcoin. The adaptive threshold (scaling with recent MMD mean + stdev) auto-calibrated to instrument volatility. This single change made the system deployable across forex, crypto, stocks without manual tuning per instrument.
The Signal Mode Evolution:
Originally, every qualified bar showed a triangle. Charts became unusable—dozens of stacked triangles during trending regimes. "Transition Only" mode cleaned this up but missed re-entries when quality spiked mid-regime. "Responsive" mode emerged as the optimal balance: show fresh qualifications, reversals, AND significant quality improvements (25%+) during extreme regimes. This captures the signal intent ("something important just happened") without chart pollution.
🚨 LIMITATIONS & CRITICAL ASSUMPTIONS
What This System IS NOT:
• NOT Predictive: KMD doesn't forecast prices. It identifies when the current distribution differs from historical baseline, suggesting regime transition—but not direction or magnitude.
• NOT Holy Grail: Typical performance is 48-56% win rate with 1.3-1.8 avg R-multiple. This is a probabilistic edge, not certainty. Expect losing streaks of 8-12 trades.
• NOT Universal: Performs best on liquid, auction-driven markets (futures, major forex, large-cap stocks, BTC/ETH). Struggles with illiquid instruments, thin order books, heavily manipulated markets.
• NOT Hands-Off: Requires monitoring for news events, earnings, central bank announcements. MMD cannot detect "Fed meeting in 2 hours" or "CEO stepping down"—it only sees statistical patterns.
• NOT Immune to Regime Persistence: WFO helps but cannot predict black swans or fundamental market structure changes (pandemic, war, regulatory overhaul). During these events, all historical patterns may break.
Core Assumptions:
1. Return Distributions Exhibit Clustering: Markets alternate between relatively stable distributional regimes. Violation: Permanent random walk, no regime structure.
2. Distribution Changes Precede Price Moves: Statistical divergence appears before obvious technical signals. Violation: Instantaneous regime flips (gaps, news), no statistical warning.
3. Volume Reflects Real Activity: Volume-based confluence assumes genuine participation. Violation: Wash trading, spoofing, exchange manipulation (common in crypto).
4. Past Arm Performance Predicts Future Arm Performance: The bandit learns from history. Violation: Fundamental strategy regime change (e.g., market transitions from mean-reverting to trending permanently).
5. ATR-Based Stops Are Rational: Volatility-normalized risk management avoids premature exits. Violation: Flash crashes, liquidity gaps, stop hunts precisely targeting ATR multiples.
6. Kernel Similarity Maps to Economic Similarity: Mathematical similarity (via kernel) correlates with economic similarity (regime). Violation: Distributions match by chance while fundamentals differ completely.
Performs Best On:
• ES, NQ, RTY (S&P 500, Nasdaq, Russell 2000 futures)
• Major forex pairs: EUR/USD, GBP/USD, USD/JPY, AUD/USD
• Liquid commodities: CL (crude oil), GC (gold), SI (silver)
• Large-cap stocks: AAPL, MSFT, GOOGL, TSLA (>$10M avg daily volume)
• Major crypto on reputable exchanges: BTC, ETH (Coinbase, Kraken)
Performs Poorly On:
• Low-volume stocks (<$1M daily volume)
• Exotic forex pairs with erratic spreads
• Illiquid crypto altcoins (manipulation, unreliable volume)
• Pre-market/after-hours (thin liquidity, gaps)
• Instruments with frequent corporate actions (splits, dividends)
• Markets with persistent one-sided intervention (central bank pegs)
Known Weaknesses:
• Lag During Instantaneous Shifts: MMD requires (test_window) bars to detect regime change. Fast-moving events (5-10 bar crashes) may bypass detection entirely.
• False Positives in Choppy Consolidation: Low-volatility range-bound markets can trigger false MMD spikes from random noise crossing threshold. Regime filter helps but doesn't eliminate.
• Parameter Sensitivity: Small bandwidth changes (2.0→2.5) can alter signal frequency by 30-50%. Requires careful calibration per instrument.
• Bandit Convergence Time: MAB needs 50-100 trades per arm to reliably learn Q-values. Early trades (first 200 bars) are essentially random exploration.
• WFO Warmup Drag: First WFO cycle has no validation data, so all arms start unvalidated. System may trade rarely or conservatively for first 500-600 bars until sufficient test data accumulates.
• Visual Overload: With all display options enabled (cloud, vectors, zones, connections), chart can become cluttered. Disable selectively for cleaner view.
⚠️ RISK DISCLOSURE
Trading futures, forex, stocks, options, and cryptocurrencies involves substantial risk of loss and is not suitable for all investors. Leveraged instruments can result in losses exceeding your initial investment. Past performance, whether backtested or live, is not indicative of future results.
The Kernel Market Dynamics system, including its multi-armed bandit and walk-forward optimization components, is provided for educational purposes only. It is not financial advice, investment advice, or a recommendation to buy or sell any security or instrument.
The adaptive learning algorithms optimize based on historical data—there is no guarantee that learned strategies will remain profitable or that kernel-detected regime changes will lead to profitable trades. Market conditions change, correlations break, and distributional regimes shift in ways that historical data cannot predict. Black swan events occur.
Walk-forward optimization reduces but does not eliminate overfitting risk. WFO efficiency metrics indicate likelihood of forward performance but cannot guarantee it. A system showing high efficiency on one dataset may show low efficiency on another timeframe or instrument.
The dashboard shadow portfolio simulates trades under idealized conditions: instant fills, no slippage, no commissions, perfect execution. Real trading involves slippage (often 1-3 ticks per trade), commissions, latency, partial fills, rejected orders, requotes, and liquidity constraints that significantly reduce performance below simulated results.
Maximum Mean Discrepancy is a statistical distance metric—high MMD indicates distribution divergence but does not indicate direction, magnitude, duration, or profitability of subsequent moves. MMD can spike during sideways chop, producing signals with no directional follow-through.
Users must independently validate system performance on their specific instruments, timeframes, broker execution, and market conditions before risking capital. Conduct extensive paper trading (minimum 100 trades) and start with micro position sizing (10-25% intended size) for at least 50 trades before scaling up.
Never risk more capital than you can afford to lose completely. Use proper position sizing (1-2% risk per trade maximum). Implement stop losses on every trade. Maintain adequate margin/capital reserves. Understand that most retail traders lose money. Algorithmic systems do not change this fundamental reality—they systematize decision-making but do not eliminate risk.
The developer makes no warranties regarding profitability, suitability, accuracy, reliability, or fitness for any particular purpose. Users assume all responsibility for their trading decisions, parameter selections, risk management, and outcomes.
By using this indicator, you acknowledge that you have read and understood these risk disclosures and accept full responsibility for all trading activity and potential losses.
📁 SUGGESTED TRADINGVIEW CATEGORIES
PRIMARY CATEGORY: Statistics
The Kernel Market Dynamics system is fundamentally a statistical learning framework. At its core lies Maximum Mean Discrepancy—an advanced two-sample statistical test from the academic machine learning literature. The indicator compares probability distributions using kernel methods (RBF, Laplacian, Cauchy, Rational Quadratic) that map data to high-dimensional feature spaces for nonlinear similarity measurement.
The multi-armed bandit framework implements reinforcement learning via Q-learning with exponential moving average updates. Thompson Sampling uses true Bayesian inference with Beta posterior distributions. Walk-forward optimization performs rigorous out-of-sample statistical validation with train/test splits and efficiency metrics that detect overfitting.
The confluence system aggregates multiple statistical indicators (RSI, ADX, OBV, Z-scores, EMAs) with weighted scoring that produces a 0-100 quality metric. Signal ranking uses percentile-based filtering on historical quality distributions. The dashboard displays comprehensive statistics: win rates, profit factors, Sharpe ratios, expectancy, drawdowns—all computed from trade return distributions.
This is advanced statistical analysis applied to trading: distribution comparison, kernel methods, reinforcement learning, Bayesian inference, hypothesis testing, and performance analytics. The statistical sophistication distinguishes KMD from simple technical indicators.
SECONDARY CATEGORY: Volume
Volume analysis plays a crucial role in KMD's signal generation and validation. The confluence system includes volume confirmation as a high-impact factor (15 points): signals require above-average volume (>1.2× mean) for full points, with scaling based on volume ratio. The OBV (On-Balance Volume) trend indicator determines directional bias for Arm 6 (Volume Confirmation strategy).
Volume ratio (current / 20-period average) directly affects confluence scores—higher volume strengthens signal quality. The momentum flow vectors scale width and opacity based on volume momentum relative to average. Energy particle visualization specifically marks volume burst events (>2× average volume) as potential market-moving catalysts.
Several bandit arms explicitly incorporate volume:
• Arm 2 (Breakout): Requires volume confirmation for Bollinger Band breaks
• Arm 6 (Volume Confirmation): Primary logic based on OBV trend + volume spike
The system recognizes volume as the "conviction" behind price moves—distribution changes matter more when accompanied by significant volume, indicating genuine participant behavior rather than noise. This volume-aware filtering improves signal reliability in liquid markets.
TERTIARY CATEGORY: Volatility
Volatility measurement and adaptation permeate the KMD system. ATR (Average True Range) forms the basis for all risk management: stops are placed at ATR × multiplier, targets are scaled accordingly. The adaptive bandwidth feature scales kernel bandwidth (0.5-2.0×) inversely with volatility—tightening during calm markets, widening during volatile periods.
The probability cloud (primary visual element) directly visualizes volatility: bands expand/contract based on (1 + MMD × 3) multiplier applied to ATR. Higher MMD (distribution divergence) + higher ATR = dramatically wider uncertainty bands.
Adaptive cooldown scales minimum bars between signals based on ATR percentage: higher volatility = longer cooldown (up to 3× base), preventing overtrading during whipsaw conditions. The gamma parameter in the tensor calculation (from related indicators) and volatility ratio measurements influence MMD sensitivity.
Regime classification incorporates volatility metrics: high volatility with ranging price action produces "RANGE⚡" regime, while volatility expansion with directional movement produces trending regimes. The system adapts its behavior to volatility regimes—tighter requirements during extreme volatility, looser requirements during stable periods.
ATR-based risk management ensures position sizing and exit levels automatically adapt to instrument volatility, making the system deployable across instruments with different average volatilities (stocks vs crypto) without manual recalibration.
══════════════════════════════════════════
CLOSING STATEMENT
══════════════════════════════════════════
Kernel Market Dynamics doesn't just measure price—it measures the probability structure underlying price. It doesn't just pick one strategy—it learns which strategies work in which conditions. It doesn't just optimize on history—it validates on the future.
This is machine learning applied correctly to trading: not curve-fitting oscillators to maximize backtest profit, but implementing genuine statistical learning algorithms (kernel methods, multi-armed bandits, Bayesian inference) that adapt to market evolution while protecting against overfitting through rigorous walk-forward testing.
The seven arms compete. The Thompson sampler selects. The kernel measures. The confluence scores. The walk-forward validates. The signals fire.
Most indicators tell you what happened. KMD tells you when the game changed.
"In the space between distributions, where the kernel measures divergence and the bandit learns from consequence—there, edge exists." — KMD-WFO-MAB v2
Taking you to school. — Dskyz, Trade with insight. Trade with anticipation.
招待専用スクリプト
このスクリプトは作者が承認したユーザーのみアクセス可能です。使用するにはアクセス申請をして許可を得る必要があります。通常は支払い後に承認されます。詳細は下記の作者の指示に従うか、DskyzInvestmentsに直接お問い合わせください。
TradingViewは、作者を完全に信頼し、スクリプトの動作を理解していない限り、有料スクリプトの購入・使用を推奨しません。コミュニティスクリプトには無料のオープンソースの代替が多数あります。
作者の指示
This is a private, invite-only indicator. To request access, please follow the instructions on our official website: https://www.dafetradingsystems.com After completing the process on our site, send me a message
Empowering everyday traders and DAFE Trading Systems
DAFETradingSystems.com
DAFETradingSystems.com
免責事項
この情報および投稿は、TradingViewが提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。
招待専用スクリプト
このスクリプトは作者が承認したユーザーのみアクセス可能です。使用するにはアクセス申請をして許可を得る必要があります。通常は支払い後に承認されます。詳細は下記の作者の指示に従うか、DskyzInvestmentsに直接お問い合わせください。
TradingViewは、作者を完全に信頼し、スクリプトの動作を理解していない限り、有料スクリプトの購入・使用を推奨しません。コミュニティスクリプトには無料のオープンソースの代替が多数あります。
作者の指示
This is a private, invite-only indicator. To request access, please follow the instructions on our official website: https://www.dafetradingsystems.com After completing the process on our site, send me a message
Empowering everyday traders and DAFE Trading Systems
DAFETradingSystems.com
DAFETradingSystems.com
免責事項
この情報および投稿は、TradingViewが提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。