18 KiB
Institutional Chaos-Weighted Stochastic Pro (Enterprise Ultra Edition v1.10)
1. Executive Summary & The Fast vs. Slow Stochastic Dilemma
The Institutional Chaos-Weighted Stochastic Pro (ChaosWeightedStochastic_Pro) is an institutional-grade adaptive momentum oscillator developed for MetaTrader 5 (Year 2026 Enterprise Edition). It modernizes George C. Lane's classical Stochastic Oscillator (1950s) by modulating the internal slowing smoothing factor with Fractal Dimension (Chaos) Metrics.
+-------------------------------------------------------------------------------+
| THE EVOLUTION OF THE STOCHASTIC OSCILLATOR |
+-------------------------------------------------------------------------------+
1. George Lane's Fast Stochastic (Raw %K):
- Pure algebraic ratio: (Close - LL) / (HH - LL) * 100
- ADVANTAGE: Zero lag.
- CRITICAL FLAW: Extreme whipsaws and false boundary crosses in noisy chop.
2. George Lane's Slow Stochastic:
- Adds static 3-period SMA smoothing: Slow %K = SMA(Raw %K, 3)
- ADVANTAGE: Mutes noise.
- CRITICAL FLAW: Adds uniform lag, causing delayed entries during explosive breakouts.
3. Chaos-Weighted Stochastic (Enterprise v1.10):
- Dynamically modulates the slowing factor via Fractal Chaos (FDI):
- In Clean Trends (Chaos -> 0.0): Accelerates to FAST STOCHASTIC velocity (Zero lag!).
- In Choppy Whipsaw (Chaos -> 1.0): Decelerates to ULTRA-SLOW STOCHASTIC (Freezes false crosses!).
2. Mathematical & DSP Engine Specifications
The calculation engine CChaosWeightedStochastic_Calculator operates on chronological arrays (ArraySetAsSeries(..., false)) and unifies <MyIncludes\Fractal_Engine.mqh> with <MyIncludes\MovingAverage_Engine.mqh>.
+-------------------------------------------------------------------------------+
| CHAOS-WEIGHTED STOCHASTIC PIPELINE |
+-------------------------------------------------------------------------------+
Candle Stream: High_t, Low_t, Close_t (Standard or Heikin Ashi)
|
v
Step 1: Raw Fast %K over InpKPeriod (default: 14):
HH_t = Highest(High, 14), LL_t = Lowest(Low, 14)
Raw_%K_t = (Close_t - LL_t) / (HH_t - LL_t) *100.0
|
v
Step 2: Central CFractalEngine:
Evaluate Sevcik Fractal Dimension Index (FDI_t) over InpDisorderLength (20)
Chaos_t = Clamp( (FDI_t - 1.0) / 0.5, 0.0, 1.0 )
|
v
Step 3: Adaptive Slowing Modulation (alpha_adj):
alpha_base = 2.0 / (InpSlowingPeriod + 1.0)
alpha_adj = Clamp( alpha_base* (1.0 - Chaos_t)^Sensitivity, 0.005, 1.0 )
|
v
Step 4: Recursive Chaos-Weighted %K Filtering:
%K_t = %K_{t-1} + alpha_adj * ( Raw_%K_t - %K_{t-1} )
|
v
Step 5: %D Signal Line Calculation via MovingAverage_Engine.mqh:
%D_t = CalculateOnArray( %K, InpDPeriod, InpDMAType )
A. Raw Fast %K Formulation
For a lookback window of N_K bars (InpKPeriod):
HH_t = \max_{0 \le j < N_K}(H_{t-j}), \quad LL_t = \min_{0 \le j < N_K}(L_{t-j})
\text{Raw } \%K_t = \begin{cases} \left( \frac{C_t - LL_t}{HH_t - LL_t} \right) \cdot 100.0 & \text{if } (HH_t - LL_t) > 1.0 \times 10^{-9} \\ 50.0 & \text{otherwise} \end{cases}
B. Adaptive Chaos-Weighted Slowing Equation
The base smoothing alpha is derived from the slowing period:
\alpha_{\text{base}} = \frac{2}{\text{InpSlowingPeriod} + 1}
The non-linear modulation equation adjusts the responsiveness based on market entropy:
\alpha_{\text{adj}} = \max\Big( 0.005, \, \min\big( 1.0, \, \alpha_{\text{base}} \cdot (1.0 - Chaos_t)^{\text{InpSensitivity}} \big) \Big)
\%K_t = \%K_{t-1} + \alpha_{\text{adj}} \cdot (\text{Raw } \%K_t - \%K_{t-1})
- In a Strong Trend (
Chaos_t \to 0.0):(1.0 - 0.0)^{\text{Sens}} = 1.0 \implies \alpha_{\text{adj}} = \alpha_{\text{base}}(instantaneous tracking). - In Extreme Chaos (
Chaos_t \to 1.0):(1.0 - 1.0)^{\text{Sens}} = 0.0 \implies \alpha_{\text{adj}} = 0.005. The filter locks in place, acting as an automatic brake against choppy whipsaws.
C. Signal Line (%D) Smoothing via MovingAverage_Engine.mqh
The %D signal line is generated by passing %K through the unified CMovingAverageCalculator::CalculateOnArray() engine with exact offset alignment (actual_start = m_k_period - 1), supporting 7 institutional MA types:
SMA: Simple Moving Average (Classical Lane %D)EMA: Exponential Moving Average (Default, high responsiveness)SMMA: Smoothed Moving Average (Wilder's RMA equivalent)LWMA: Linear Weighted Moving Average (Front-weighted, zero lag)DEMA: Double Exponential Moving AverageTEMA: Triple Exponential Moving AverageVWMA: Volume-Weighted Moving Average
3. Range-Based Candle Source Architecture (ENUM_CANDLE_SOURCE)
Unlike single-price oscillators (such as RSI), a Stochastic oscillator is fundamentally a range-bound, three-coordinate geometric indicator requiring the full candle triplet (\text{High}, \text{Low}, \text{Close}).
ChaosWeightedStochastic_Pro aligns strictly with the suite's established candle-source standards:
enum ENUM_CANDLE_SOURCE
{
CANDLE_STANDARD, // Standard raw OHLC candles
CANDLE_HEIKIN_ASHI // Heikin Ashi smoothed candles
};
CANDLE_STANDARDMode: Evaluates authentic physical exchange highs, lows, and closes. Chaos FDI is computed on the standard close series.CANDLE_HEIKIN_ASHIMode: Evaluates direct in-place Heikin Ashi extremes (HA\_High, HA\_Low, HA\_Close). Micro-wicks are filtered out, generating pristine structural swing ranges and noise-free %K trajectories.
4. Non-Repainting Divergence Engine & Subwindow Trendlines
The indicator includes a strictly non-repainting Subwindow Divergence Engine that detects structural discrepancies between price extremes and the Chaos-Weighted %K line:
Regular Bullish Divergence (Subwindow Trendline: clrMediumSeaGreen, Dotted)
Price Action: Lower Low (P_2 < P_1)
Chaos %K: Higher Low (%K_2 > %K_1)
Interpretation: Selling momentum is exhausted despite lower price. Imminent reversal up.
Regular Bearish Divergence (Subwindow Trendline: clrCrimson, Dotted)
Price Action: Higher High (P_2 > P_1)
Chaos %K: Lower High (%K_2 < %K_1)
Interpretation: Buying momentum is exhausted despite higher price. Imminent reversal down.
The p + d Non-Repainting Protocol
-
A pivot at bar
prequiresdconfirmation bars to the left anddbars to the right (InpDivStrength). -
Therefore, a pivot is permanently confirmed and locked at bar
p + d. -
Once confirmed, a trendline is drawn connecting the confirmed pivot points in the subwindow (
OBJ_TREND, Style:STYLE_DOT). -
Zero Repaint Guarantee: The trendline coordinates are anchored to historical timestamps. They will never move or disappear on future ticks.
5. High-Performance 2026 MTF Fast-Path & Multi-Instance Architecture
A. True MTF Divergences (Eliminating the Stepped-Curve Paradox)
When viewing higher timeframe Stochastic on an execution chart (e.g., viewing H1 Stochastic on an M15 chart):
- Conventional indicators run divergence checks on the stepped lower timeframe curve, resulting in false triggers on flat steps.
ChaosWeightedStochastic_Proevaluates divergences strictly in the clean, unstepped HTF domain (h_time[],h_high[],h_low[],h_res_k[]).- Confirmed HTF divergence trendlines are anchored directly to the higher timeframe candle open timestamps (
h_time), projecting clean, mathematically pure macro divergence lines onto the lower timeframe chart.
B. Multi-Instance Namespace Isolation (InpInstanceID)
To enable multiple indicator instances on a single chart (e.g., H1 Stochastic in Subwindow 1 and H4 Stochastic in Subwindow 2):
-
Every graphical object is prefixed with a deterministic instance-isolated token:
g_prefix = StringFormat("CWSTOCH_%I64d_%s_%d_%d_%d_%d_", ChartID(), EnumToString(g_calc_timeframe), InpKPeriod, InpSlowingPeriod, InpDisorderLength, InpInstanceID); -
Different instances will never delete, overwrite, or collide with each other's graphical objects.
-
GetIndicatorSubwindow()automatically binds each instance's trendlines to its own designated subwindow.
6. Comprehensive Parameter Reference & Calibration Matrix
Input Settings
| Parameter | Type | Default | Description | Operational Profile |
|---|---|---|---|---|
InpTimeframe |
ENUM_TIMEFRAMES |
PERIOD_CURRENT |
Calculation timeframe (Current or HTF). | Native O(1) or Two-Pointer MTF. |
InpKPeriod |
int |
14 |
Raw %K lookback window length (N_K). |
Governs price extreme lookback. |
InpSlowingPeriod |
int |
3 |
Base slowing period (\alpha_{\text{base}}). |
Base smoothing factor. |
InpDPeriod |
int |
3 |
%D Signal Line period. | Signal Line depth. |
InpDMAType |
ENUM_MA_TYPE |
SMA |
%D Signal MA Method (SMA, EMA, etc.). | Unified Moving Average Engine. |
InpDisorderLength |
int |
20 |
Fractal Dimension (Chaos) lookback window. | Governs noise filter sensitivity. |
InpSensitivity |
double |
1.0 |
Chaos dampening exponent (0.1–5.0). | Higher = more aggressive freezing in chop. |
InpCandleSource |
ENUM_CANDLE_SOURCE |
CANDLE_STANDARD |
Candle source (Standard vs Heikin Ashi). | Full Heikin Ashi support. |
InpHistoryBars |
int |
1000 |
Historical lookback limit (0 = Full Chart). | Eliminates cold-start freezes. |
InpColorK |
color |
clrDodgerBlue |
%K main line color. | Primary indicator plot. |
InpWidthK |
int |
2 |
%K line thickness. | Visual width. |
InpShowSignal |
bool |
true |
Display %D Signal Line. | Toggles %D overlay. |
InpColorD |
color |
clrMagenta |
High-contrast %D Signal Line color. | Universal contrast on light/dark themes. |
InpStyleD |
ENUM_LINE_STYLE |
STYLE_SOLID |
%D Signal Line style. | Visual styling. |
InpWidthD |
int |
2 |
%D Signal Line thickness. | Visual width. |
InpShowDivLines |
bool |
true |
Display subwindow divergence trendlines. | Toggles graphical lines. |
InpDivStrength |
int |
15 |
Divergence pivot confirmation strength (d). |
Bars required left and right. |
InpBullDivColor |
color |
clrMediumSeaGreen |
Bullish divergence trendline color. | Visual trendline styling. |
InpBearDivColor |
color |
clrCrimson |
Bearish divergence trendline color. | Visual trendline styling. |
InpInstanceID |
int |
1 |
Unique instance identifier for multi-setups. | Prevents chart namespace collisions. |
Quantitative Calibration Matrix
| Trading Style | Asset Class | Base Chart | Target TF | %K / Slow / %D | FDI Length | Candle Source | Strategy Focus |
|---|---|---|---|---|---|---|---|
| Micro-Scalping | Crypto / Indices | M1 / M3 | PERIOD_CURRENT |
9 / 2 / 3 |
14 |
CANDLE_STANDARD |
Ultra-fast momentum with instant noise freezing during order book sweeps. |
| Day Trading | Majors FX / Metals | M5 / M15 | M15 / H1 | 14 / 3 / 3 |
20 |
CANDLE_STANDARD |
Standard institutional calibration for session momentum and divergence fades. |
| Swing Structure | Equities / Crude Oil | H1 / H4 | H4 / D1 | 14 / 3 / 5 |
24 |
CANDLE_HEIKIN_ASHI |
Macro trend surfing filtered by Heikin Ashi smoothing to eliminate daily wicks. |
7. Quantitative Synergy Playbooks
Playbook A: Chaos-Accelerated Momentum Crossover
Price Action
| [ACCELERATING TREND BREAKOUT] /=====> STRONG BUY ENTRY
| /
|-----------------------------------------------------/------------------------------ Resistance
CWStoch Subwindow
| ----------------------------------------------------------------------------------- Level 80.0 (Overbought)
| /======================> %K SURGES ABOVE %D
| ============================/====================================================== Level 50.0 (Centerline)
| ^
| |-- BULLISH CROSS (%K crosses %D during low chaos)
| ----------------------------------------------------------------------------------- Level 20.0 (Oversold)
- Setup:
- Market breaks out of a consolidation pattern.
Chaos %K(Blue) crosses aboveSignal %D(Magenta) and pierces the50.0median centerline.- Diagnosis: Because the indicator dynamically dampens in noise, a cross above 50 occurs only when the trend has sufficient directional efficiency.
- Execution Trigger:
- Enter Long on the bar close confirming
BufferK[1] > BufferD[1]andBufferK[1] > 50.0.
- Enter Long on the bar close confirming
- Exit: Hold trade while
%Kremains above%D. Exit upon bearish cross or when%Krolls over from the 80.0 overbought zone.
Playbook B: Non-Repainting Macro Divergence Reversal
- Setup:
- Load
ChaosWeightedStochastic_Proon an M15 chart withInpTimeframe = PERIOD_H1andInpShowDivLines = true. - Price prints a lower low on the chart, but a dashed green trendline (
clrMediumSeaGreen) appears in the subwindow connecting a higher low on the H1%K.
- Load
- Execution Trigger:
- Wait for an M15 reversal candle (e.g., Bullish Engulfing or rejection wick) confirming the H1 macro divergence.
- BUY: Enter Long targeting the opposing H1 pivot or the 80.0 overbought level.
- Risk Management:
- Stop Loss: 5 ticks below the H1 swing low.
Playbook C: The Quad-Suite Alignment Meta-Filter
Combine all four core suite engines for institutional execution:
- Regime State (
Entropy_Pro): SampEn< 0.80(Structural order confirmed). - Volatility Trigger (
VolatilityRegime_Pro): Ratio surges from Blue (< 0.75) into Lime (> 1.00). - Adaptive Momentum (
ChaosWeightedStochastic_Pro):%Kcrosses above%Dwith no opposing bearish divergence. - Trend Geometry (
KAMA_Bands_Pro): Price band-walks along+1.0\sigma.
- Trade Quality: Institutional Grade A+ Setup.
8. Developer Integration & Expert Advisor Guide
The indicator exposes its visual buffers directly to MetaTrader 5 Expert Advisors (EAs) via the native iCustom() API:
Buffer Index Map
| Buffer Index | Identifier | Description | Range / Output |
|---|---|---|---|
0 |
BufferK |
Chaos-Weighted %K value. | Continuous double (0.0 \dots 100.0). |
1 |
BufferD |
%D Signal Line (Unified Moving Average). | Continuous double (0.0 \dots 100.0) or EMPTY_VALUE. |
Example MQL5 EA Integration Snippet
//+------------------------------------------------------------------+
//| Using ChaosWeightedStochastic_Pro in an Automated EA |
//+------------------------------------------------------------------+
int h_cwstoch = INVALID_HANDLE;
int OnInit()
{
// Bind to ChaosWeightedStochastic_Pro via iCustom
h_cwstoch = iCustom(_Symbol, PERIOD_CURRENT, "ChaosWeightedStochastic_Pro",
PERIOD_CURRENT, // Timeframe
14, // %K Period
3, // Slowing Period
3, // %D Period
SMA, // %D MA Type (ENUM_MA_TYPE)
20, // Disorder Length (FDI)
1.0, // Sensitivity
CANDLE_STANDARD, // Candle Source (ENUM_CANDLE_SOURCE)
1000, // History Bars Limit
clrDodgerBlue, // %K Line Color
2, // %K Line Width
true, // Enable %D Signal Line
clrMagenta, // %D Signal Color
STYLE_SOLID, // %D Signal Style
2, // %D Signal Width
false, // Disable GUI Trendlines in EA for speed!
15, // Divergence Strength
clrMediumSeaGreen, // Bullish Div Color
clrCrimson, // Bearish Div Color
1); // Instance ID
if(h_cwstoch == INVALID_HANDLE)
{
Print("Critical Error: Failed to create handle for ChaosWeightedStochastic_Pro!");
return INIT_FAILED;
}
return INIT_SUCCEEDED;
}
void OnTick()
{
double k_val[2], d_val[2];
// Read bar 1 and bar 2 (completed closed bars) for non-repainting execution
if(CopyBuffer(h_cwstoch, 0, 1, 2, k_val) <= 0 ||
CopyBuffer(h_cwstoch, 1, 1, 2, d_val) <= 0)
return;
double k_curr = k_val[1];
double k_prev = k_val[0];
double d_curr = d_val[1];
double d_prev = d_val[0];
// RULE 1: MOMENTUM CROSSOVER FROM OVERSOLD TERRITORY
bool bull_cross = (k_prev <= d_prev && k_curr > d_curr && k_curr < 50.0);
bool bear_cross = (k_prev >= d_prev && k_curr < d_curr && k_curr > 50.0);
if(bull_cross)
{
// Chaos-filtered bullish momentum confirmed! Execute Long.
ExecuteOrder(ORDER_TYPE_BUY);
}
else if(bear_cross)
{
// Chaos-filtered bearish momentum confirmed! Execute Short.
ExecuteOrder(ORDER_TYPE_SELL);
}
}
*Enterprise Quantitative Software Suite — 2026 Ultra Edition