is an advanced, physics-inspired analytical tool that extracts market kinematics by measuring price path length and volatility energy. Unlike conventional momentum tools, KCI-DX employs a dynamic Z-Score normalization combined with a Sigmoid activation function. This ensures the output is flawlessly bounded between 0 and 100, providing hyper-responsive trend strength identification and directional bias without distortion from historical extremes. KCI Directional Matrix (KCI-DX) is a quantitative directional analysis indicator designed to measure market efficiency, directional pressure, and trend expansion through a proprietary Kinetic Compression Index framework.
Key Features:
Unlike conventional momentum oscillators, KCI-DX decomposes market movement into three independent dimensions:
The indicator combines:
The result is a stable 0–100 directional matrix capable of identifying:
KCI-DX can be used as a standalone trading tool or as a feature-engineering component for Expert Advisors, machine learning systems, market scanners, adaptive grids, dynamic stop management, and portfolio-level decision engines.
Input Parameters :

KCI-DX: VISUAL QUICK START GUIDE
| Visual Element | Color & Style | What It Means |
|---|---|---|
| KCI Main Line | Gold (Solid) | Trend Strength & Compression. Shows how much kinematic energy is in the market, regardless of direction. |
| +KDI Line | Blue (Dashed) | Bullish Energy. The strength of upward price movement. |
| -KDI Line | Red (Dashed) | Bearish Energy. The strength of downward price movement. |
| Level 80.0 | Gray (Dotted) | Extreme / Exhaustion Zone. The trend is at maximum capacity. |
| Level 20.0 | Gray (Dotted) | Compression / Sideways Zone. The market is accumulating energy. |
Look at where the Gold Line (KCI Main) is positioned to instantly understand the market environment:
Picture. 1

Visual Trade Setups (Step-by-Step)
Picture. 2

PRO TIP: Never trade if the Blue and Red lines are tangled together under the 20 level. Wait for a clear separation and a Gold line breakout!
KCI Directional Matrix Logic for Expert Advisors (EAs)
If this indicator is used within an EA, the following trading rules can be applied:
This is the most optimal and recommended method. The EA will call the KCI-Directional_X.ex5 file located in the Indicators folder.
Code snippet :
//+------------------------------------------------------------------+ //| EA_KCI_iCustom.mq5 | //+------------------------------------------------------------------+ #property copyright "Copyright 2026, Ritz" #property version "1.00" int kci_handle; double KCI_Main[], KDI_Plus[], KDI_Minus[]; int OnInit() { // Create the custom indicator handle. // Ensure that "KCI-Directional_X.ex5" is located // in the MQL5/Indicators directory. kci_handle = iCustom(_Symbol, _Period, "KCI-Directional_X", 9, 30, 1.5); if(kci_handle == INVALID_HANDLE) { Print("Failed to load the KCI-DX indicator."); return(INIT_FAILED); } // Configure indicator buffers as time series // (Index 0 = current bar). ArraySetAsSeries(KCI_Main, true); ArraySetAsSeries(KDI_Plus, true); ArraySetAsSeries(KDI_Minus, true); return(INIT_SUCCEEDED); } void OnTick() { // Retrieve the latest indicator values // (current bar and the most recently closed bar). if(CopyBuffer(kci_handle, 0, 0, 2, KCI_Main) <= 0) return; if(CopyBuffer(kci_handle, 1, 0, 2, KDI_Plus) <= 0) return; if(CopyBuffer(kci_handle, 2, 0, 2, KDI_Minus) <= 0) return; // ------------------------------------------------------------ // KCI-DX Trading Logic // All trading decisions are based on the last completed candle // (Index 1) to avoid signals from the still-forming candle. // ------------------------------------------------------------ // Detect whether the market is in a trending condition. bool isTrending = KCI_Main[1] > 20.0; // Detect a bullish directional crossover. bool buySignal = (KDI_Plus[1] > KDI_Minus[1]) && (KDI_Plus[2] <= KDI_Minus[2]); // Detect a bearish directional crossover. bool sellSignal = (KDI_Minus[1] > KDI_Plus[1]) && (KDI_Minus[2] <= KDI_Plus[2]); // Detect an extreme trend expansion. bool isExtreme = KCI_Main[1] >= 80.0; // Example trade execution logic. if(isTrending && buySignal) { Print("KCI-DX BUY signal detected."); // Place your BUY order execution // (OrderSend or CTrade::Buy) here. } else if(isTrending && sellSignal) { Print("KCI-DX SELL signal detected."); // Place your SELL order execution // (OrderSend or CTrade::Sell) here. } // Optional trade management for strong market trends. if(isExtreme) { Print("Extreme trend detected. Consider activating a trailing stop or managing existing positions."); } }
This method incorporates your mathematical algorithm directly into the EA without requiring external indicator files. Since the calculation requires historical data for the Z-Score, we use a special function within the EA to process the price array.
Code snippet:
//+------------------------------------------------------------------+ //| EA_KCI_Embedded.mq5 | //+------------------------------------------------------------------+ #property copyright "Copyright 2026, Ritz" #property version "1.00" input int InpBasePeriod = 9; input int InpZScorePeriod = 30; input double InpSensitivity = 1.5; // Structure used to return all three KCI-DX values // from a single calculation. struct KCI_Result { double main; double plus; double minus; }; // Calculate the internal Z-Score used for // dynamic normalization. double EmbeddedZScore(double &data_array[], int period) { if(period < 2) return 0.0; double sum = 0.0; double sum_sq = 0.0; for(int i = 0; i < period; i++) { sum += data_array[i]; sum_sq += data_array[i] * data_array[i]; } double mean = sum / period; double variance = (sum_sq / period) - (mean * mean); if(variance <= 1e-10) return 0.0; return (data_array[0] - mean) / MathSqrt(variance); } // Calculate the KCI-DX values for a specified // historical bar (shift). KCI_Result CalculateKCI(int shift) { KCI_Result res; res.main = 0.0; res.plus = 0.0; res.minus = 0.0; // Retrieve sufficient historical closing prices // for both the Base Period and Z-Score window. int required_bars = InpZScorePeriod + InpBasePeriod; double close[]; ArraySetAsSeries(close, true); if(CopyClose(_Symbol, _Period, shift, required_bars, close) < required_bars) return res; // Insufficient historical data. double raw_plus[]; double raw_minus[]; double raw_trend[]; ArrayResize(raw_plus, InpZScorePeriod); ArrayResize(raw_minus, InpZScorePeriod); ArrayResize(raw_trend, InpZScorePeriod); // ------------------------------------------------------------ // Phase 1: // Kinematic Directional Extraction // ------------------------------------------------------------ for(int i = 0; i < InpZScorePeriod; i++) { double path_len = 0.000001; double net_up = 0.0; double net_dn = 0.0; double mean_p = 0.0; for(int j = 0; j < InpBasePeriod; j++) { double diff = close[i + j] - close[i + j + 1]; path_len += MathAbs(diff); if(diff > 0) net_up += diff; else net_dn -= diff; mean_p += close[i + j]; } mean_p /= InpBasePeriod; double var_p = 0.0; for(int j = 0; j < InpBasePeriod; j++) var_p += MathPow(close[i + j] - mean_p, 2); double energy = MathSqrt(var_p / InpBasePeriod); raw_plus[i] = (net_up / path_len) * energy; raw_minus[i] = (net_dn / path_len) * energy; raw_trend[i] = (MathAbs(net_up - net_dn) / path_len) * energy; } // ------------------------------------------------------------ // Phase 2: // Dynamic Sigmoid Normalization // ------------------------------------------------------------ double z_plus = EmbeddedZScore(raw_plus, InpZScorePeriod); double z_minus = EmbeddedZScore(raw_minus, InpZScorePeriod); double z_trend = EmbeddedZScore(raw_trend, InpZScorePeriod); res.plus = 100.0 / (1.0 + MathExp(-InpSensitivity * z_plus)); res.minus = 100.0 / (1.0 + MathExp(-InpSensitivity * z_minus)); res.main = 100.0 / (1.0 + MathExp(-InpSensitivity * z_trend)); return res; } void OnTick() { // Calculate the KCI-DX values for the // two most recently completed candles. KCI_Result kci_current = CalculateKCI(1); KCI_Result kci_prev = CalculateKCI(2); // ------------------------------------------------------------ // Example Trading Logic // Detect a bullish directional crossover. // ------------------------------------------------------------ bool buySignal = (kci_current.plus > kci_current.minus) && (kci_prev.plus <= kci_prev.minus); // Execute trading logic only when the market // is in a valid trending condition. if(kci_current.main > 20.0 && buySignal) { Print("Embedded KCI-DX detected a BUY signal."); // Place your BUY order execution // (OrderSend or CTrade::Buy) here. } }
Before you compile and trade, keep these best practices in mind to get the most out of the KCI-Directional Matrix:
Asset Flexibility: The default parameters ( BasePeriod=9 , ZScorePeriod=30 ) are highly responsive and perform exceptionally well on major pairs. However, if you are applying this to highly volatile instruments like Gold (XAUUSD), Cryptocurrencies (BTC/ETH), or Indices, consider slightly increasing the ZScorePeriod (e.g., to 40 or 50) to filter out excessive noise.
Algorithmic Optimization: For EA developers building complex or multi-symbol systems, utilizing the Embedded Calculation method provided above is highly recommended. It keeps your CPU usage incredibly lightweight and ensures your Expert Advisor remains fully self-contained without needing external indicator calls.
Pairing for Confluence: KCI-DX is a dedicated kinematic and volatility engine. While it provides excellent standalone directional bias, it becomes truly formidable when combined with your favorite structural filters (like Support/Resistance zones) or volume anomaly detectors to validate the final entry.
Author's Note / Conclusion: Thank you for exploring the KCI-Directional Matrix. This codebase was engineered with a strict focus on providing the MQL5 community with a lightweight, mathematically rigorous, and highly adaptive analytical tool. Whether you are a manual trader looking for precise momentum exhaustion points, or a developer integrating machine-readable data into an Expert Advisor, I hope this indicator serves as a robust foundation for your projects.
If you find this code valuable for your trading systems, please feel free to leave a review, share your creative modifications, or drop a question in the discussion section below. Let’s continue pushing the boundaries of algorithmic trading together!
Happy Coding and Trade Safely, — Ritz
KCI Volatility Distance
The KCI Volatility Distance is an advanced, adaptive algorithm meticulously engineered to map market momentum and trend direction with pure precision. Utilizing a proprietary matrix-based calculation, this tool dynamically filters out market noise and provides a strictly quantitative perspective on directional strength. Built with a highly optimized Object-Oriented Programming (OOP) core, it is designed for both visual trading clarity and seamless integration into Expert Advisors or Machine Learning modules, ensuring ultra-light CPU performance across multiple assets.
Market Miner
A multi strategy EA gold mine :)
EA KCI N-Matrix engine
The Apex of Algorithmic Grid & Kinetic Momentum. Welcome to the KCI Native Matrix Engine—a merciless, mathematically driven algorithmic behemoth built natively for MetaTrader 5. Engineered for High-Frequency Trading (HFT) environments, this EA strips away bloated standard libraries and operates directly at the server routing level.
Double Enevlopes (Historical Gauged)
A babysitting trade management tool and system :D