Nexus Fusion Engine ML [WillyAlgoTrader]🧠 Nexus Fusion Engine ML is a non-overlay oscillator that fuses three independent momentum measurements into a single adaptive line (0–100), enriched with a K-Nearest Neighbors directional bias engine, volatility-normalized volume flow, automatic divergence detection (regular + hidden), momentum fatigue warnings, higher-timeframe bias, and a weighted confluence meter — delivering a complete momentum analysis system in one pane.
The core insight: a single momentum reading is noisy. Two readings averaged together are still fragile. But three fundamentally different momentum perspectives — directional velocity, efficiency-weighted impulse, and stochastic range position — blended in proportion to current market regime, produce a reading that adapts to trend and range conditions without manual switching. Layer a KNN classifier trained on live features, volume confirmation, and multi-timeframe alignment on top, and every signal carries measurable confluence.
Works on any market (crypto, forex, stocks, futures, indices) and any timeframe.
🧩 WHY THESE COMPONENTS WORK TOGETHER
A standard RSI or stochastic tells you where price sits in its recent range — but it has no concept of trend quality, volume confirmation, or historical pattern similarity. You get overbought readings in strong trends that never reverse. You get crossover signals with zero volume support. You get divergences with no structural confirmation.
Nexus Fusion Engine ML solves this by chaining every subsystem into an integrated pipeline:
Adaptive Momentum Fusion (3 components) → Signal Line Crossover → Volume Flow Confirmation → Efficiency Ratio Regime Detection → KNN Pattern Matching → Higher-Timeframe Bias → Confluence Meter (weighted vote of all subsystems)
The AMF engine produces an adaptive oscillator that automatically shifts its blend toward trend-measuring components (NROC + EWI) when the Efficiency Ratio is high, and toward range-measuring components (SMP) when the market is choppy. The signal line catches crossovers. Volume Flow confirms whether real buying or selling pressure backs the move. The Efficiency Ratio classifies the regime (trending vs ranging). The KNN engine finds historically similar conditions and votes on the most likely next-bar direction. The HTF bias filters noise by confirming alignment with the higher timeframe. Finally, the Confluence Meter aggregates all six sources into a single 0–100 score — so you see at a glance how many independent systems agree.
Without adaptive blending, the oscillator would either lag in trends or whipsaw in ranges. Without volume flow, signals lack confirmation. Without KNN, you have no statistical context. Without confluence scoring, you must mentally juggle six independent readings. The integration chain converts raw momentum data into actionable, scored, confirmed intelligence.
🔍 WHAT MAKES IT ORIGINAL
1️⃣ Adaptive Momentum Fusion (AMF) — three-component blended oscillator.
The engine computes three independent momentum measurements on every bar:
— NROC (Normalized Rate of Change): measures directional price velocity. Formula: ROC = (source − source ) / source × 100, smoothed with the selected method, then min-max normalized over a 3×N window to 0–100.
— EWI (Efficiency-Weighted Impulse): measures bar-to-bar impulse scaled by trend quality. Formula: impulse = change(source) / ATR(N) × ER, smoothed and normalized over a 4×N window to 0–100. High ER amplifies the impulse; low ER suppresses it.
— SMP (Stochastic Momentum Position): maps price within its recent range. Formula: (source − lowest(N)) / (highest(N) − lowest(N)) × 100, smoothed with EMA(N/2).
The blend is adaptive:
— trendWeight = min(ER_smoothed × 1.5, 0.75)
— rangeWeight = 1.0 − trendWeight
— oscRaw = trendWeight × (NROC × 0.55 + EWI × 0.45) + rangeWeight × SMP
When the market is trending (high ER), the oscillator favors NROC and EWI (directional components). In ranging conditions (low ER), it leans on SMP (range-mapping component). The final value is clamped to 0–100 after a short smoothing pass (N/3 bars).
2️⃣ Candle Anatomy Volume Flow — continuous directional volume scoring.
Instead of binary close > open direction, the volume flow uses a candle anatomy model that scores each bar from −1.0 to +1.0:
— candleScore = bodyDirection × bodyRatio × 0.7 + wickBias × 0.3
— bodyRatio = |close − open| / (high − low)
— wickBias = (lowerWick − upperWick) / (high − low)
A full bullish candle with no upper wick scores +1.0. A doji scores near 0. A pin bar with a long lower wick and small body scores +0.3 to +0.6.
The signed volume (candleScore × volume) is normalized by ATR × average volume, producing a Volatility-Normalized Volume Flow (VNVF). A dual-EMA blend (fast = 0.6×N, slow = 1.4×N, weighted 60/40) is then rescaled to 0–100 via dynamic peak normalization. Values above 50 indicate net buying pressure; below 50, net selling pressure.
3️⃣ KNN Directional Bias — Manhattan distance + inverse-distance weighted voting.
A K-Nearest Neighbors classifier runs on four live features:
— M (Momentum): oscVal / 100
— V (Volume Flow): vfVal / 100
— X (Signal Cross State): (oscVal − sigVal + 50) / 100
— E (Efficiency): ER_smoothed, clamped 0–1
On each bar, the previous bar's features are stored with the current bar's outcome (up / down / flat, determined by ATR-threshold price change). To find the current bias, the engine computes Manhattan distance from the current feature vector to every historical sample in the training window (default 120 bars), applies a recency bonus (recent bars get a slight distance reduction), selects the K nearest neighbors (default K = 5), and takes an inverse-distance weighted vote.
Result: a KNN bias score 0–100. Above 58 = bullish bias. Below 42 = bearish bias. The KNN panel displays direction, confidence percentage, a visual bar, feature states (M+/M−, V+/V−, E+/E−, X+/X−), and current regime.
4️⃣ Regular + Hidden Divergence with Structural Filter.
The divergence detector identifies pivot highs and lows on the oscillator (lookback = N/2 bars each side), then compares consecutive pivots:
— Regular Bullish: price makes a lower low, oscillator makes a higher low → potential reversal up.
— Regular Bearish: price makes a higher high, oscillator makes a lower high → potential reversal down.
— Hidden Bullish: price makes a higher low, oscillator makes a lower low → uptrend continuation.
— Hidden Bearish: price makes a lower high, oscillator makes a higher high → downtrend continuation.
The optional Structural Filter suppresses weak divergences by requiring:
— Minimum oscillator swing between pivots (default 5.0 points)
— Minimum price swing as % of recent range (default 0.3%)
— Volume flow confirmation (volume flow must agree with divergence direction)
— Maximum pivot age (default 100 bars) — prevents stale pivots from triggering false signals
Divergence lines are drawn solid (regular) or dashed (hidden) with configurable opacity. Labels: D▲ D▼ for regular, H▲ H▼ for hidden.
5️⃣ Regime Detection — Efficiency Ratio + 4-factor composite score.
The regime module scores the current market state from 0 to 4:
— +1 if oscillator > signal line
— +1 if oscillator > 50 (bullish territory)
— +1 if volume flow > 50 (net buying)
— +1 if Efficiency Ratio > 0.3 (trending market)
Score 4 = strong bullish trend → full bull fill in the OB zone. Score 0 = strong bearish trend → full bear fill in the OS zone. Scores 1–3 = transitional states with reduced opacity. The Efficiency Ratio itself uses the Kaufman formula: ER = |price − price | / sum(|price − price |, N), measuring how much of total price movement is directional.
6️⃣ Confluence Meter — 6-source weighted composite score.
Six independent subsystems vote bullish (+1), bearish (−1), or neutral (0):
— Oscillator position (>55 bull, <45 bear)
— Signal cross direction (osc > sig = bull)
— Volume Flow (>55 bull, <45 bear)
— Efficiency-confirmed direction (ER > 0.3 + oscillator side)
— KNN Bias (bull/bear state)
— HTF Bias (bull/bear state)
Net votes mapped: confRaw = (bullVotes − bearVotes + 6) / 12 × 100, smoothed with EMA(3). Above 70 = strong bullish confluence. Below 30 = strong bearish confluence. Displayed as a thin step-line on the oscillator pane.
7️⃣ Higher-Timeframe Bias — non-repainting HTF confirmation.
Fetches the oscillator and signal values from a user-selected higher timeframe using request.security() with offset + lookahead_on = previous closed HTF bar. This guarantees zero repainting. HTF is considered bullish when HTF oscillator > 50 and HTF oscillator > HTF signal; bearish when the reverse.
8️⃣ Momentum Fatigue Detection — consecutive weakening in extreme zones.
When the oscillator is above the OB level and declining for N consecutive bars (default 3), a fatigue label (✦ OB) appears — signaling that buying momentum is weakening even though the oscillator remains overbought. Mirror logic applies in the oversold zone (✦ OS). This early warning often precedes crossover signals by several bars.
9️⃣ Six smoothing algorithms with preset system.
The smoothing engine supports EMA, SMA, DEMA (double-exponential), TEMA (triple-exponential), WMA (weighted), and VWMA (volume-weighted). Four presets instantly configure period, smoothing, and zone levels:
— Scalping: period 8, OB 75, OS 25
— Default: period 14, OB 80, OS 20
— Swing: period 21, OB 80, OS 20
— Position: period 34, OB 85, OS 15
🔟 Full alert suite with webhook JSON support.
12 alert conditions covering every subsystem: bull/bear cross, OB/OS zone exit, regular/hidden divergence, volume flow inflow/outflow, fatigue OB/OS, KNN bias flip, confluence threshold cross. Each alert includes ticker, timeframe, price, and oscillator value. Toggle webhook mode to send JSON payloads for bot integration.
⚙️ HOW IT WORKS — CALCULATION FLOW
Step 1 — Warmup guard: The indicator requires 3× the engine period (minimum 60 bars) before producing any signals, divergences, or KNN output. This prevents false signals from insufficient data.
Step 2 — AMF oscillator computation: Three momentum components (NROC, EWI, SMP) are computed independently, each normalized to 0–100. The Efficiency Ratio determines the blend weights. The raw blend is smoothed with the selected algorithm over N/3 bars and clamped to 0–100.
Step 3 — Signal line: The oscillator is smoothed again with a separate method and period (default EMA 7) to produce the signal/trigger line. Crossovers between oscillator and signal generate dots and alerts.
Step 4 — Volume Flow: Each candle is scored using candle anatomy (body ratio + wick bias). Signed volume is normalized by ATR × average volume. A dual-EMA blend is rescaled to 0–100 via dynamic peak normalization.
Step 5 — Regime scoring: Four binary conditions (osc > sig, osc > 50, VF > 50, ER > 0.3) produce a regime score 0–4. This score drives zone fills.
Step 6 — Divergence scan: Pivot highs and lows are detected on the oscillator. Consecutive pivots are compared for regular and hidden divergence patterns. The Structural Filter (optional) suppresses weak signals.
Step 7 — Fatigue check: Consecutive declining bars in the OB zone (or rising bars in the OS zone) are counted. After N bars (default 3), a fatigue label fires.
Step 8 — KNN classification: Four features from the current bar are compared to the training window via Manhattan distance. The K nearest neighbors vote with inverse-distance weighting. Result: KNN bias 0–100.
Step 9 — HTF bias fetch: Oscillator and signal are fetched from the higher timeframe using previous-bar lookahead to prevent repainting.
Step 10 — Confluence aggregation: Six subsystems cast bull/bear/neutral votes. Net votes are mapped to 0–100 and smoothed.
📖 HOW TO USE
🎯 Quick start:
1. Add the indicator to your chart. It appears as a separate oscillator pane below price.
2. Select a preset matching your trading style: Scalping (fast), Default (balanced), Swing, or Position (slow).
3. If you trade a higher timeframe, set the HTF Bias timeframe (e.g., for a 15min chart, set HTF to 60).
4. Watch for the oscillator line crossing the signal line inside the OB/OS zones — these are the primary signals.
5. Check the dashboard (top-left by default) and KNN panel for confluence confirmation before acting.
👁️ Reading the chart:
— 🟢 Green oscillator line = momentum is in bullish territory (above midline) or in the overbought zone.
— 🔴 Red oscillator line = momentum is in bearish territory (below midline) or in the oversold zone.
— Thin gray signal line = trigger line for crossover signals.
— 🟢 Green dot on signal line = bullish crossover (oscillator crossed above signal).
— 🔴 Red dot on signal line = bearish crossover (oscillator crossed below signal).
— 🟢 Green fill between oscillator and midline = bullish momentum with gradient intensity.
— 🔴 Red fill between oscillator and midline = bearish momentum with gradient intensity.
— 🟢 Green volume flow fill (above 50) = net buying pressure.
— 🔴 Red volume flow fill (below 50) = net selling pressure.
— D▲ / D▼ labels with solid lines = regular (reversal) divergence.
— H▲ / H▼ labels with dashed lines = hidden (continuation) divergence.
— ✦ OB / ✦ OS labels = momentum fatigue warning in extreme zones.
— Regime fills in OB/OS zones = colored fills when regime score reaches 3–4 (bull) or 0–1 (bear).
— Thin step-line = confluence meter (above 70 = strong bullish, below 30 = strong bearish).
📊 Dashboard fields:
— Trend: Bullish (osc > 60) / Bearish (osc < 40) / Neutral.
— Signal: Latest signal event — Bull Cross, Bear Cross, Overbought, Oversold, or none.
— Strength: Strong (osc ≥ 70 or ≤ 30) / Medium / Weak.
— Oscillator: Current numeric oscillator value.
— Momentum: Acceleration state — Accel ▲ (gaining speed) / Decel ▼ (losing speed) / Steady.
— HTF Bias: Higher-timeframe direction — Bullish / Bearish / Neutral / OFF.
— Vol Flow: Inflow (VF > 60) / Outflow (VF < 40) / Neutral / N/A (no volume data).
— Regime: Trending (ER > 0.3) / Ranging.
— KNN Bias: KNN directional output — Bullish / Bearish / Neutral.
— Confluence: Composite reading with label — Strong Bull / Lean Bull / Mixed / Lean Bear / Strong Bear.
— ER: Current Efficiency Ratio value.
— Score: Regime score (0–4).
— Consensus: Raw bull vs bear vote count (e.g., 5B / 1S).
🔧 Tuning guide:
— Too many signals / whipsaw: Increase Engine Period (try 21 or 34), or switch to the Swing / Position preset. Enable the Structural Filter for divergences.
— Too few signals / too slow: Decrease Engine Period (try 8–10), or use the Scalping preset. Lower the Confirmation Bars for fatigue to 1–2.
— Divergences feel noisy: Enable the Structural Filter. Increase Min Osc Swing (try 8–10). Enable Require Volume Confirmation. Lower Max Pivot Age to 50–60.
— KNN seems random: Increase K (try 8–10) for more conservative voting. Increase Training Window to 200–300 for more historical data. KNN works best on liquid instruments with sufficient bar history.
— Volume flow shows N/A: The instrument has no volume data (some forex pairs, indices). Volume Flow and its contribution to regime/confluence will be inactive.
— HTF Bias always neutral: Make sure the HTF timeframe is actually higher than your current chart timeframe. An empty field = same timeframe (no filtering).
💡 Trading ideas:
— Crossover in extreme zone: Wait for the oscillator to enter the oversold zone (below 20), then watch for a bullish cross of the signal line. Confirm with volume flow turning green and KNN showing bullish. The reverse applies for overbought bearish crosses.
— Divergence + fatigue combo: A regular bullish divergence (D▲) appearing near or shortly after a ✦ OS fatigue label is a strong reversal setup. Both systems independently detect weakening bearish momentum.
— Confluence filter: Only take trades when the Confluence Meter is above 70 (for longs) or below 30 (for shorts). This ensures at least 4–5 out of 6 subsystems agree.
— Regime-aware strategy: When the dashboard shows "Trending" and the regime score is 3–4, favor trend-following entries (hidden divergences, pullbacks to midline). When "Ranging" with score 1–2, favor mean-reversion entries (regular divergences, OB/OS zone fades).
— Multi-timeframe alignment: Set the HTF to 4× your chart timeframe (e.g., 1H chart → 4H HTF). Only take long entries when HTF Bias = Bullish, and shorts when HTF Bias = Bearish. This one filter alone can significantly reduce false signals.
⚙️ KEY SETTINGS REFERENCE
⚙️ Main Settings:
— Engine Period (default 14): Core lookback for the AMF engine. 8–12 = scalping, 14 = balanced, 20–50 = swing/position.
— Source (default close): Price input. Close = standard, HLC3 = smoother, OHLC4 = smoothest.
— Smoothing (default DEMA): Algorithm for oscillator core. DEMA recommended for fast and smooth response.
— Preset (default Default): Quick configuration — Scalping / Default / Swing / Position.
— Signal Period (default 7): Smoothing for the trigger line. Keep below Engine Period.
— Signal Smoothing (default EMA): Method for the signal line.
— Show Cross Dots (default ON): Dots at oscillator–signal crossover points.
📐 Zones & Fills:
— Overbought Level (default 80): Upper extreme threshold.
— Oversold Level (default 20): Lower extreme threshold.
— OB/OS Fill Opacity (default 20): Zone fill transparency.
📊 Volume Flow:
— Show Volume Flow (default ON): Toggle the VNVF overlay.
— Volume Flow Opacity (default 18): Fill transparency. Keep 10–25 so the oscillator stays visible.
🔬 Regime Detection:
— Show Regime State (default ON): Toggle regime zone fills.
— Regime OB/OS Opacity (default 35): Fill transparency for regime fills.
🔀 Divergence:
— Regular Divergence (default ON): Reversal divergence detection.
— Hidden Divergence (default ON): Continuation divergence detection.
— Structural Filter (default OFF): Suppresses weak divergences. When ON, uses Min Osc Swing (default 5.0), Min Price Swing % (default 0.3%), and Volume Confirmation.
— Max Pivot Age (default 100 bars): Maximum distance between divergence pivots.
💨 Momentum Fatigue:
— Show Fatigue Labels (default ON): Toggle fatigue warnings.
— Confirmation Bars (default 3): Consecutive weakening bars required. 1 = fast, 5 = strict.
🧠 KNN Bias:
— Show KNN Panel (default ON): Toggle the AI panel.
— Neighbors (K) (default 5): Voting neighbors. 3 = fast, 10+ = conservative.
— Training Window (default 120): Historical bars for learning. 50 = short memory, 300+ = long memory.
🔭 Higher Timeframe:
— Show HTF Bias (default ON): Toggle HTF filter.
— Higher Timeframe (default empty = current TF): Select a higher TF for meaningful bias.
🎯 Confluence:
— Show Confluence Meter (default ON): Toggle the composite score line.
— High Confluence (default 70): Threshold for strong bullish confluence.
— Low Confluence (default 30): Threshold for strong bearish confluence.
🎨 Visual:
— Theme (default Auto): Auto-detects chart background. Force Dark or Light as needed.
— Adaptive Line Color (default ON): Oscillator color shifts with momentum direction.
— Bull/Bear Colors : Customizable green/red palette.
🔔 ALERTS
— 🟢 Bull Cross — oscillator crosses above signal line below the midline. Payload: ticker, TF, price, osc value.
— 🔴 Bear Cross — oscillator crosses below signal line above the midline. Payload: ticker, TF, price, osc value.
— 🟢 Exit Oversold — oscillator crosses above OS level.
— 🔴 Exit Overbought — oscillator crosses below OB level.
— 🟢 Regular Bull Divergence — D▲ detected (passes structural filter if enabled).
— 🔴 Regular Bear Divergence — D▼ detected.
— 🟢 Hidden Bull Divergence — H▲ detected.
— 🔴 Hidden Bear Divergence — H▼ detected.
— 🟢 Volume Inflow — volume flow crosses above 50.
— 🔴 Volume Outflow — volume flow crosses below 50.
— ⚠️ OB Fatigue — buying momentum weakening in overbought zone.
— ⚠️ OS Fatigue — selling momentum weakening in oversold zone.
— 🧠 KNN → Bull — KNN bias flips to bullish.
— 🧠 KNN → Bear — KNN bias flips to bearish.
— 🎯 Confluence High — confluence meter crosses above high threshold (default 70).
— 🎯 Confluence Low — confluence meter crosses below low threshold (default 30).
All alerts support plain text and JSON webhook format (toggle in settings). Alerts fire once per bar.
⚠️ IMPORTANT NOTES
— 🚫 Divergence timing. Pivots are detected with equal left/right lookback (N/2 bars). This means the divergence line and label appear at the confirmed pivot bar, which is N/2 bars in the past. This is delayed confirmation, not repainting — the signal does not change once it appears.
— 🚫 HTF bias does not repaint. The higher-timeframe values use the previous closed HTF bar ( offset + barmerge.lookahead_on). The HTF reading updates only when a new HTF bar closes.
— 📐 KNN is not a crystal ball. The KNN classifier finds similar historical conditions and votes on direction. It does not predict the future — it provides statistical context based on the training window. In low-liquidity or unusual market conditions, historical patterns may not repeat.
— 📐 Volume Flow requires volume data. On instruments without volume (some forex feeds, certain index CFDs), Volume Flow displays N/A and its contribution to regime scoring and confluence voting is inactive.
— ⚖️ Warmup period. The indicator needs 3× Engine Period (minimum 60 bars) of data before producing output. On very low-timeframe charts with limited history, some subsystems may not activate.
— 🛠️ This is an analysis tool, not an automated trading bot. It provides momentum analysis, volume confirmation, pattern recognition, and confluence scoring — trade decisions remain yours.
— 🌐 Works on all markets and all timeframes. Optimized for liquid instruments with volume data.
Version: v1.2.1
Indicator





