20 KiB
Slow Stochastic Suite Pro (v3.20)
George Lane's Classic Two-Stage Smoothed Stochastic Oscillator with In-Place Heikin Ashi & Zero-Lag MTF Fast-Path
1. Summary (Introduction)
Stochastic Slow Pro (v3.20) is an institutional-grade momentum oscillator implementing George Lane's complete Two-Stage Smoothed Slow Stochastic framework.
While standard Fast Stochastic oscillators measure price directly relative to the high-low range over a fixed lookback period—frequently generating errant noise, false whipsaws, and premature overbought/oversold extremes—Slow Stochastic introduces a sequential smoothing cascade:
- First, it computes the raw, un-smoothed Fast %K line across lookback window
K. - Second, it slows down Fast %K using a configurable moving average (SMA, EMA, or VWMA) to generate the primary Slow %K line.
- Third, it smooths Slow %K a second time to produce the Signal %D trigger line.
In high-density multi-chart workspaces—such as setups operating 14 active chart windows with multi-timeframe stochastic overlays—legacy implementations cause severe UI freezing due to repetitive iBarShift queries, redundant temporary memory arrays, and tick-by-tick buffer copying. Version 3.20 Enterprise Edition eliminates this latency via an In-Place Heikin Ashi Pipeline and Zero-Lag MTF Fast-Path.
┌────────────────────────────────────────────────────────────────────────┐
│ SLOW STOCHASTIC ARCHITECTURAL EVOLUTION │
├────────────────────────────────────────────────────────────────────────┤
│ │
│ LEGACY ENGINE (v3.10): │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ • 4 separate Copy API calls on every live MTF tick │ │
│ │ • Up to 500 iBarShift API calls per tick in forming blocks │ │
│ │ • 3 redundant dynamic temp arrays in Heikin Ashi calculator │ │
│ │ • UI Thread Saturation across multi-chart workspaces │ │
│ └──────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ OPTIMIZED │
│ ENTERPRISE ENGINE (v3.20): │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ • Direct In-Place Heikin Ashi calculation (0 temp arrays) │ │
│ │ • 1 Atomic CopyRates call per live MTF tick (-75.0% API) │ │
│ │ • 0 iBarShift calls on live ticks (ArrayBsearch Fast-Path) │ │
│ │ • Two Embedded Incremental Moving Average Engines in O(1) │ │
│ └──────────────────────────────────────────────────────────────┘ │
│ │
└────────────────────────────────────────────────────────────────────────┘
Key Capabilities
- Two-Stage Smoothing Cascade: Filters out high-frequency market microstructure noise while preserving turning-point responsiveness.
- Direct In-Place Heikin Ashi Math: Eliminates intermediate array allocations and copy loops, computing synthetic OHLC directly into destination buffers.
- Selectable Moving Average Engines: Independently select smoothing algorithms (SMA, EMA, SMMA, LWMA, TMA, DEMA, TEMA, VWMA) for both Slow %K and Signal %D.
- Zero-Lag MTF Fast-Path: Higher-timeframe curves project onto lower-timeframe execution charts as crisp, non-warping flat steps via
DataSync_Tools.mqhwith zeroiBarShiftoverhead on live ticks. - 100% Backwards Compatibility: Preserves public signatures across
CStochasticSlowCalculator, ensuring seamless interoperability with custom scripts and expert advisors.
2. Mathematical Foundations & Two-Stage Smoothing Cascade
Raw Price (OHLC) ──▶ Find Highest High & Lowest Low over K Period
│
▼
Raw Fast %K = (Close - LL) / (HH - LL) · 100
│
▼
Stage 1: Slowing MA ──▶ Slow %K = MovingAverage( Raw Fast %K, SlowingPeriod )
│
▼
Stage 2: Signal MA ──▶ Signal %D = MovingAverage( Slow %K, DPeriod )
2.1. Raw Fast %K Normalization Formulation
Given lookback window K = \text{InpKPeriod}:
\text{HH}_t = \max_{j=0 \dots K-1} (\text{High}_{t-j})
\text{LL}_t = \min_{j=0 \dots K-1} (\text{Low}_{t-j})
\text{Range}_t = \text{HH}_t - \text{LL}_t
\text{RawK}_t = \begin{cases} \frac{\text{Close}_t - \text{LL}_t}{\text{Range}_t} \cdot 100, & \text{if } \text{Range}_t > 10^{-9} \\ \text{RawK}_{t-1}, & \text{otherwise} \end{cases}
2.2. Stage 1 Smoothing: Slow %K (Main Line)
To eliminate erratic noise spikes, \text{RawK} is smoothed using the selected InpSlowingMAType across P_{\text{slow}} = \text{InpSlowingPeriod}:
\text{SlowK}_t = \text{MovingAverage}(\text{RawK}, P_{\text{slow}}, \text{InpSlowingMAType})_t
2.3. Stage 2 Smoothing: Signal %D (Trigger Line)
The signal line is computed by smoothing the primary \text{SlowK} series across P_{\text{signal}} = \text{InpDPeriod} using InpDMAType:
\text{SignalD}_t = \text{MovingAverage}(\text{SlowK}, P_{\text{signal}}, \text{InpDMAType})_t
2.4. Symmetrical 5-Zone Indicator Level Matrix
| Level Value | Level Name | Market Momentum State | Institutional Interpretation |
|---|---|---|---|
| 90.0 | Extreme Overbought | Parabolic buying climax; exhaustion imminent. | Tighten trailing stops; prepare for mean reversion. |
| 80.0 | Overbought Warning | Strong bullish trend momentum active. | Bullish expansion zone; trail stops below Slow %K. |
| 50.0 | Equilibrium Centerline | Symmetrical zero-bias inflection line (C \approx \text{Mid}). |
Directional pivot: >50 Bullish bias, <50 Bearish bias. |
| 20.0 | Oversold Warning | Strong bearish trend momentum active. | Bearish expansion zone; trail stops above Slow %K. |
| 10.0 | Extreme Oversold | Capitulation liquidation floor; short squeeze risk. | Prepare for mean-reversion bounce; cover short positions. |
3. MQL5 Architecture & Computational Benchmarking
┌────────────────────────────────────────────────────────┐
│ StochasticSlow_Calculator.mqh │
│ (In-Place Heikin Ashi Math: 2 Embedded MA Engines) │
└──────────────────────────┬─────────────────────────────┘
│ Delivers Slow %K & Signal %D in O(1)
▼
┌────────────────────────────────────────────────────────┐
│ StochasticSlow_Pro.mq5 │
│ (Unified Native & Zero-Lag MTF Fast-Path) │
├──────────────────────────┬─────────────────────────────┤
│ Buffer Layer (2) │ Centralized Framework │
│ • BufferK (Plot 1: %K) │ • DataSync_Tools.mqh │
│ • BufferD (Plot 2: %D) │ • Atomic CopyRates MTF │
│ │ • Binary Search Snapping │
└──────────────────────────┴─────────────────────────────┘
Engineering Benchmark: Legacy (v3.10) vs. Enterprise (v3.20)
| Metric | Legacy Implementation (v3.10) | Enterprise Refactor (v3.20) | Net Optimization |
|---|---|---|---|
| Heikin Ashi Temp Buffers | 3 dynamic temporary arrays | 0 temp arrays (Direct in-place) | -100% Memory Overhead |
| Heikin Ashi Memory Copying | Extra array copy loop per bar | 0 copy loops (Direct write) | Fused Execution |
MTF Live-Tick iBarShift |
Up to 500 calls per tick | 0 calls on live ticks (ArrayBsearch) |
Complete Zero-Lag |
| MTF Data Copy Calls | 4 separate calls per tick | 1 atomic CopyRates query |
-75.0% API Overhead |
| Pointer Safety | Slow CheckPointer() on ticks |
Fast if(!g_calculator) Guard |
Optimized Branching |
| Multi-Window Scalability | UI freeze on >10 charts | Silky-smooth execution on >14 charts | Enterprise Certified |
4. Parameters Reference
Timeframe Settings
InpTimeframe(default:PERIOD_CURRENT): Calculation timeframe. Set toPERIOD_CURRENTfor native zero-lag execution, or choose a higher timeframe (e.g.,PERIOD_M5,PERIOD_H1) to activate the synchronized MTF engine.
Stochastic Settings
InpKPeriod(default:5): Lookback period for finding the Highest High and Lowest Low (K).InpSlowingPeriod(default:3): Lookback period for smoothing Raw Fast %K into Slow %K.InpSlowingMAType(default:SMA): Moving average algorithm applied to %K (Supports SMA, EMA, VWMA, etc.).InpDPeriod(default:3): Lookback period for smoothing Slow %K into the Signal %D line.InpDMAType(default:SMA): Moving average algorithm applied to %D.InpCandleSource(default:CANDLE_STANDARD): Price input series (CANDLE_STANDARDorCANDLE_HEIKIN_ASHI).
Indicator Levels (0-100 Range)
InpLevel1(default:10.0): Extreme Oversold threshold (Capitulation floor).InpLevel2(default:20.0): Oversold Warning threshold.InpLevel3(default:50.0): Equilibrium Baseline.InpLevel4(default:80.0): Overbought Warning threshold.InpLevel5(default:90.0): Extreme Overbought threshold (Exhaustion ceiling).
Visual Settings
InpColorK(default:clrLightSeaGreen): Color of the primary Slow %K line (Width: 1, Solid).InpColorD(default:clrLightCoral): Color of the smoothed Signal %D line (Width: 1, Solid).
5. Quantitative Trading Playbooks
┌────────────────────────────────────────────────────────────────────────┐
│ SLOW STOCHASTIC QUANTITATIVE PLAYBOOKS │
├────────────────────────────────────────────────────────────────────────┤
│ 1. Trend Continuation Pullback: Buy pullbacks when %K bounces off the │
│ 20 or 50 level in an established trend.│
│ 2. Parabolic Climax Fade: Fade extreme climaxes when %K > 90 │
│ or < 10 and crosses %D. │
│ 3. Slow %K / Signal %D Cross: Enter momentum continuations in the │
│ direction of higher-timeframe bias. │
└────────────────────────────────────────────────────────────────────────┘
5.1. Trend Continuation Pullback (The Institutional Edge)
- Bullish Trend Setup:
- Market is in an established uptrend (price trading above SuperSmoother / VWAP).
- Slow Stochastic pulls back downward, dipping into the 50.0 equilibrium level or momentarily testing the 20.0 oversold level.
- Slow %K crosses strictly above Signal %D while holding above 20.0
\rightarrowEnter Long. This represents a high-probability continuation entry where pullbacks terminate.
- Bearish Trend Setup:
- Market is in a confirmed downtrend.
- Slow %K rallies upward to test the 50.0 or 80.0 resistance levels.
- Slow %K crosses strictly below Signal %D
\rightarrowEnter Short.
5.2. Parabolic Climax & Capitulation Reversal
- Extreme Bullish Exhaustion Fade:
- Slow %K expands beyond 90.0 (
InpLevel5), indicating extreme momentum overextension. - Slow %K rolls over and crosses below Signal %D while inside the
>80zone\rightarrowTake profit on longs; initiate mean-reversion counter-trend shorts targeting the 50.0 centerline.
- Slow %K expands beyond 90.0 (
- Extreme Bearish Capitulation Bounce:
- Slow %K flushes below 10.0 (
InpLevel1), signaling forced liquidation selling. - Slow %K hooks upward and crosses above Signal %D
\rightarrowCover short positions; enter long bounce trades targeting the 50.0 equilibrium.
- Slow %K flushes below 10.0 (
5.3. Multi-Timeframe Alignment (H1/M5 MTF on M1 Execution)
- Load
StochasticSlow_ProwithInpTimeframe = PERIOD_M5onto an M1 execution chart. - The non-warping flat staircase steps represent the 5-minute directional momentum:
- If M5 Slow %K is holding above 50.0: Focus exclusively on Long execution on M1.
- If M5 Slow %K is holding below 50.0: Focus exclusively on Short execution on M1.
6. Indicator Buffer Map (For Developers & EA Integration)
Buffer Allocation
| Buffer Index | Name | Type | Visual Plot | Description |
|---|---|---|---|---|
| 0 | BufferK |
INDICATOR_DATA |
Plot 1 (DRAW_LINE) |
Main Slow %K Stochastic curve (0.0 \dots 100.0). |
| 1 | BufferD |
INDICATOR_DATA |
Plot 2 (DRAW_LINE) |
Smoothed Signal %D line. |
All buffers strictly maintain non-series chronological order (ArraySetAsSeries = false), ensuring direct compatibility with automated Expert Advisors via iCustom().
MQL5 EA Integration Interface Template
//+------------------------------------------------------------------+
//| EA_Stochastic_Slow_Interface |
//| Copyright 2026, xxxxxxxx|
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, xxxxxxxx"
#property version "1.00"
#property strict
//--- Include Calculator Definitions
#include <MyIncludes\StochasticSlow_Calculator.mqh>
//--- EA Inputs
input group "=== Slow Stochastic Filter Parameters ==="
input ENUM_TIMEFRAMES InpStochTF = PERIOD_CURRENT; // Timeframe
input int InpKPeriod = 5; // %K Period
input int InpSlowingPeriod = 3; // Slowing Period
input ENUM_MA_TYPE InpSlowingMethod = SMA; // Slowing Method
input int InpDPeriod = 3; // %D Period
input ENUM_MA_TYPE InpDMethod = SMA; // %D Method
//--- Global Indicator Handle
int g_stoch_handle = INVALID_HANDLE;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if(g_stoch_handle != INVALID_HANDLE)
IndicatorRelease(g_stoch_handle);
// Instantiate handle to StochasticSlow_Pro via iCustom
g_stoch_handle = iCustom(_Symbol,
InpStochTF,
"StochasticSlow_Pro",
InpStochTF,
InpKPeriod,
InpSlowingPeriod,
InpSlowingMethod,
InpDPeriod,
InpDMethod,
0); // Standard Candle Source
if(g_stoch_handle == INVALID_HANDLE)
{
PrintFormat("EA Error: Failed to create handle for StochasticSlow_Pro. Error: %d", GetLastError());
return INIT_FAILED;
}
Print("EA Success: StochasticSlow_Pro handle initialized successfully.");
return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
if(g_stoch_handle != INVALID_HANDLE)
{
IndicatorRelease(g_stoch_handle);
g_stoch_handle = INVALID_HANDLE;
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// Query completed closed candle (Shift = 1) and previous candle (Shift = 2) for Slow %K and Signal %D
double k_vals[2], d_vals[2];
ArraySetAsSeries(k_vals, true); // Index 0 = Shift 1, Index 1 = Shift 2
ArraySetAsSeries(d_vals, true);
if(CopyBuffer(g_stoch_handle, 0, 1, 2, k_vals) < 2 ||
CopyBuffer(g_stoch_handle, 1, 1, 2, d_vals) < 2)
{
return; // Data synchronizing
}
double k_bar1 = k_vals[0];
double d_bar1 = d_vals[0];
// Quantitative State Analysis
bool is_climax_high = (k_bar1 >= 90.0);
bool is_climax_low = (k_bar1 <= 10.0);
bool is_overbought = (k_bar1 >= 80.0);
bool is_oversold = (k_bar1 <= 20.0);
bool is_bullish_bias = (k_bar1 > 50.0);
bool is_bearish_bias = (k_bar1 < 50.0);
// Momentum Crossover Signals
bool signal_crossed_up = (k_vals[1] <= d_vals[1] && k_vals[0] > d_vals[0]);
bool signal_crossed_down = (k_vals[1] >= d_vals[1] && k_vals[0] < d_vals[0]);
// Telemetry Output
Comment(StringFormat("Slow Stochastic Telemetry [Bar 1]:\n"
"%%K: %.2f | %%D: %.2f\n"
"Bias: %s | State: %s\n"
"Signals -> Buy: %s | Sell: %s",
k_bar1, d_bar1,
is_bullish_bias ? "BULLISH (> 50.0)" : (is_bearish_bias ? "BEARISH (< 50.0)" : "EQUILIBRIUM"),
is_climax_high ? "EXTREME CLIMAX (>= 90)" :
(is_climax_low ? "EXTREME CAPITULATION (<= 10)" :
(is_overbought ? "OVERBOUGHT (>= 80)" :
(is_oversold ? "OVERSOLD (<= 20)" : "NORMAL RANGE"))),
(signal_crossed_up && is_bullish_bias) ? "TRIGGERED (Bullish Cross)" : "NO",
(signal_crossed_down && is_bearish_bias) ? "TRIGGERED (Bearish Cross)" : "NO"));
}
//+------------------------------------------------------------------+