Lorentzian Classification EA
Lorentzian-distance KNN plus kernel regression. A genuine ML classifier in MQL5.
A production-grade MT5 port of jdehorty's Machine Learning: Lorentzian Classification — over 2,700 lines of hand-written MQL5. The EA builds a feature vector from RSI, WT, CCI, and ADX across configurable lookbacks, finds the k nearest historical neighbors using Lorentzian distance (which respects the warped geometry of financial time series better than Euclidean), and fuses the neighbor vote with a Nadaraya-Watson kernel regression for a confidence-scored entry signal. Ships with seven tuned .set profiles from M15 scalping to D1 long-term plus a dedicated XAUUSD gold specialist and a conservative H4 prop-account profile.
What makes it different.
- Lorentzian distance KNN — the warped metric used in jdehorty's original TradingView indicator, ported faithfully into MQL5 with five engineered features
- Nadaraya-Watson kernel regression — rational-quadratic or Gaussian kernels filter the neighbor vote into a smooth, confidence-scored signal
- Five engineered features — RSI, WT (Wave Trend), CCI, ADX, and a second RSI at a different lookback for multi-timeframe momentum fusion
- Seven ready-to-trade .set profiles — M15 Scalping, M30 Intraday, H1 Swing, H4 Position (recommended), D1 Long-Term, XAUUSD Gold Specialist, H4 Conservative / Prop Account
- Non-repainting by construction — all distances computed on closed bars, decisions locked at bar close, signals never revise once printed
- Advanced filter stack — volatility, regime, ADX strength, EMA, SMA, and optional Kalman smoother can each gate entries independently
- Full trade management — ATR-based stops, dynamic take-profit from the kernel slope, break-even, multi-stage trailing, and partial close at 1R/2R
- Session filter with broker-offset correction — trade only London, NY, the overlap, or your own custom window
- On-chart dashboard — shows current neighbor vote, distance distribution, kernel value, feature snapshot, and live signal confidence
- Multi-symbol safe — per-instance magic numbers, concurrent operation on unlimited charts with isolated statistics
Simulated on $10k starting equity at the stated CAGR. Past performance does not guarantee future results. See risk disclosure.
Every input, documented.
| Parameter | Default | What it controls |
|---|---|---|
| NeighborsCount | 8 | Number of nearest neighbors (k) used in the Lorentzian KNN vote. Higher = smoother, slower; lower = sharper, noisier. |
| MaxBarsBack | 2000 | How many historical bars form the training window. 2000 is the jdehorty default and balances memory against sample size. |
| UseRSI | true | Include RSI as a feature in the distance calculation. |
| RSIPeriod | 14 | Lookback for the primary RSI feature. |
| RSI2Period | 9 | Lookback for the secondary RSI feature — captures shorter-horizon momentum. |
| WTChannelLen | 10 | Wave Trend channel length — core momentum-oscillator feature. |
| WTAverageLen | 11 | Wave Trend averaging length. |
| CCIPeriod | 20 | CCI lookback — mean-reversion feature in the vector. |
| ADXPeriod | 20 | ADX lookback — regime-strength feature. |
| UseKernelFilter | true | Enable the Nadaraya-Watson kernel regression filter layered on top of the KNN vote. |
| KernelType | RationalQuadratic | Rational-Quadratic (default, jdehorty-style) or Gaussian kernel. |
| KernelLookback | 8 | Kernel regression window. Lower = more reactive. |
| KernelRelativeWeight | 8.0 | Relative weighting exponent for the rational-quadratic kernel. |
| UseVolatilityFilter | true | Blocks entries during ATR-collapse regimes where the classifier loses edge. |
| UseRegimeFilter | true | Normalized-slope regime detector — only trades when trend strength exceeds threshold. |
| UseADXFilter | false | Hard ADX floor for entries. Off by default; useful on range-prone crosses. |
| RiskPerTradePct | 1.0 | Equity fraction risked per trade. 0.5 recommended for prop-firm evaluation accounts. |
| ATRStopMult | 1.8 | Stop distance expressed as a multiple of ATR. |
| RRRatio | 2.0 | Take-profit as a multiple of the stop. The kernel slope dynamically extends winners past the static TP. |
| MagicNumber | 20260420 | Unique identifier for this instance. Change per chart for multi-symbol deployment. |
Full parameter reference in the PDF user guide included with your license.
Frequently asked.
Is this a real ML algorithm or just a marketing label?
It is real. Every closed bar, the EA computes the Lorentzian distance d(x,y) = sum(log(1 + |x_i - y_i|)) between the live feature vector and every vector in the training window, sorts for the k smallest, and takes a vote. The kernel regression is a true Nadaraya-Watson estimator with a rational-quadratic kernel. All 2,735 lines are hand-written MQL5 — no black box.
Why Lorentzian distance instead of Euclidean?
Financial time series are not Euclidean. Price-warping events (news, gaps, volatility regime shifts) distort nearby points in ways that Euclidean distance overweights. The Lorentzian metric — a log-transformed L1 — is gentler on these distortions, so the nearest neighbors are genuinely similar market states rather than flukes that happen to be close in raw feature space.
Which profile should I start with?
H4 Position is the recommended default — it is the profile with the strongest walk-forward metrics and the lowest whip rate. If you are on XAUUSD specifically, use the XAUUSD Gold Specialist. For a prop-firm evaluation account, the H4 Conservative profile is tuned to the 3% / 6% daily / total loss caps most challenges use.
Does it repaint?
No. The classifier operates exclusively on closed-bar feature vectors, neighbor distances are never recomputed once a bar closes, and orders are placed on the following tick. The kernel line can refit as new bars form, but the trade decision itself is latched at close and does not revise.
Is it prop-firm safe?
Yes, with the H4 Conservative profile. It caps daily risk at 0.5%, hard-enforces a 3% daily loss circuit-breaker, closes all positions 30 minutes before daily-loss reset, and disables the ADX filter (which can spike trade count on some accounts).
How much compute does it need?
At MaxBarsBack=2000 with five features it computes ~10,000 Lorentzian distances per bar-close event — roughly 2-4 ms on a typical VPS. No GPU required; runs comfortably on the cheapest Forex VPS tier.
What is the difference between this EA and the Lorentzian Classification Indicator?
The indicator is the analysis engine; the EA is the execution engine. The indicator plots signals; the EA also handles sizing, SL/TP, break-even, partial close, trailing, session filtering, and multi-symbol concurrency. If you want to trade it automatically, you want the EA.
Does it work on MT4?
No — MT5 only. The feature indicators, order APIs, and distance-math performance characteristics required for real-time operation make MT4 impractical.
Ready to run Lorentzian Classification EA?
Lifetime license. All presets included. Direct developer support.