Advanced AI-powered trading system combining K-Nearest Neighbors signal detection with Gaussian Process Regression prediction and dynamic uncertainty-based risk management.
LorentzianEA v17.11 is a sophisticated algorithmic trading system that leverages machine learning techniques to identify and execute profitable trading opportunities. The EA combines two powerful methodologies: K-Nearest Neighbors (KNN) for signal classification and Gaussian Process Regression (GPR) for price movement prediction.
The system incorporates an advanced "Dynamic Enhancement Layer" that adapts to market uncertainty in real-time. By analyzing volatility patterns and prediction confidence, the EA dynamically adjusts its risk exposure and position sizing to maximize returns while protecting capital during uncertain market conditions.
KNN + GPR hybrid approach for signal detection and price prediction
Uncertainty-based position sizing adapts to market conditions
Multi-filter validation ensures high-quality trade signals
Built-in drawdown controls and recovery mechanisms
The EA uses K-Nearest Neighbors algorithm to classify current market conditions based on historical patterns. Five technical features are analyzed: RSI, WaveTrend, CCI, ADX, and a secondary RSI with different periods.
All signals pass through regime, volume, ADX, EMA, and SMA filters. Dynamic Enhancement Layer adjusts filter sensitivity based on market conditions.
Positions are automatically closed after 4 bars regardless of profit/loss. This ensures no indefinite holding and captures momentum within the expected timeframe.
When enabled, exits are triggered when the kernel line (Rational Quadratic) changes direction, indicating potential trend reversal.
All positions are closed when the configured session end time is reached, ensuring no overnight exposure beyond intended trading hours.
Position size is dynamically calculated based on prediction uncertainty. Low uncertainty = higher risk; High uncertainty = lower risk. Uses power curve scaling for smooth transitions.
Alternative mode with discrete lot multipliers based on uncertainty tiers: 100%, 70%, 40%, 20%, or 0% of base lot size.
Maximum lot cap, minimum equity threshold, margin check, and emergency lot reset on catastrophic calculation errors.
Creates custom timeframe bars from tick data for more precise GPR training and prediction.
Smooths price data while preserving important features, improving GPR training quality.
Automatically activates fallback logic after 5 consecutive GPR failures, preventing complete trading halt.
Visual representation of the trading system's decision-making process
This flowchart shows the entire decision-making process from EA initialization to trade execution and management.
Detailed breakdown of how entry signals are identified and validated through KNN and GPR.
How open positions are monitored and closed based on fixed bars or dynamic conditions.
Position sizing calculation workflow based on uncertainty and market conditions.
How the system analyzes prediction confidence and adjusts trading parameters.
Uses K-Nearest Neighbors algorithm to classify market conditions based on 5 normalized technical features. Identifies patterns that historically led to profitable trades.
Gaussian Process Regression predicts future price movements with confidence intervals. Uses Rational Kernel for smoothing and multi-horizon validation.
Position size dynamically adjusts based on prediction confidence. Lower uncertainty = higher risk, higher uncertainty = lower risk for capital preservation.
Four-tier classification (Weak, Moderate, Strong, Amplified Strong) determines trading aggression. Each tier adjusts KNN threshold and filter sensitivity.
Configure specific trading hours. All positions automatically close at session end, preventing overnight exposure and unexpected gap movements.
Visual dashboard displays current tier, uncertainty score, KNN threshold, Filter Adjustment Factor, and performance statistics in real-time.
Multiple filter types ensure only high-quality signals trade. Includes regime, volume, ADX, EMA, and SMA filters with dynamic threshold adjustment.
Automatic fallback mechanism activates after consecutive GPR failures. Uses simplified logic to continue trading while attempting recovery.
Complete list of all configurable settings with descriptions and recommended ranges
| Parameter Name | Type | Default | Range | Description | Category |
|---|---|---|---|---|---|
InpShowDashboard |
bool | true | true/false | Show Win/Loss Dashboard on chart | Trading |
InpGPRMode |
enum | KNN_VALIDATION | Every Bar / KNN Valid | GPR execution mode - run on every bar or only when KNN signals | Trading |
InpSyntheticBarPeriod |
int | 5 | 1-60 | Synthetic bar period in minutes for GPR training | Trading |
InpLotMode |
enum | LOT_UNCERTAINTY | See enum | Lot sizing mode: Fixed, Percentage, Uncertainty, or Tier | Risk |
InpLotSizeFixed |
double | 0.1 | 0.01-100.0 | Fixed lot size when LOT_FIXED mode is selected | Risk |
InpLotSizePercent |
double | 2.0 | 0.1-50.0 | Percentage of equity risk per trade | Risk |
InpLotSizeUncertaintyBase |
double | 5.0 | 0.1-50.0 | Base risk % at 0 uncertainty | Risk |
InpMinRiskPercent |
double | 0.5 | 0.1-50.0 | Minimum risk percentage floor (never go below) | Risk |
InpUncertaintyPower |
double | 2.0 | 0.1-10.0 | Power curve exponent for uncertainty penalty | Risk |
InpMaxLotCap |
double | 10.0 | 1.0-1000.0 | Emergency maximum lot cap | Risk |
InpStartTime |
string | 04:20 | HH:MM | Trading session start time (HH:MM format) | Trading |
InpEndTime |
string | 02:45 | HH:MM | Trading session end time (positions closed at this time) | Trading |
InpUseDynamicExits |
bool | false | true/false | Use dynamic exits based on kernel direction change | Advanced |
InpKNNNeighbors |
int | 8 | 1-50 | K-Nearest Neighbors k value | Indicators |
InpKNNFeatureCount |
int | 5 | 1-10 | Number of features for KNN classification | Indicators |
InpGPRTrainingWindow |
int | 100 | 50-150 | Number of bars for GPR training | Indicators |
InpGPRPredictionHorizon |
int | 4 | 2-20 | Number of bars to predict ahead | Indicators |
InpSGWindowSize |
int | 51 | 5-101 (odd) | Savitzky-Golay filter window size (must be odd) | Indicators |
InpEnableGPRDynamicLayer |
bool | true | true/false | Enable Dynamic Enhancement Layer with uncertainty-based adjustments | Advanced |
InpEnableMultiHorizon |
bool | true | true/false | Enable multi-horizon GPR validation (short vs long term) | Advanced |
InpNormalizeUncertainty |
bool | false | true/false | Auto-scale uncertainty to 0-1 range using historical min/max | Advanced |
InpUncertaintyLowThresh |
double | 0.3 | 0.0-1.0 | Low uncertainty threshold for tier amplification | Advanced |
InpUncertaintyHighThresh |
double | 0.7 | 0.0-1.0 | High uncertainty threshold for tier downgrade | Advanced |
InpUncertaintyVeto |
double | 1.0 | 0.0-2.0 | Hard veto if uncertainty exceeds this value | Advanced |
InpGPRATRPeriod |
int | 10 | 1-100 | ATR period for volatility normalization | Indicators |
InpGPRShortATRPeriod |
int | 2 | 1-50 | Short-term ATR period for uncertainty calculation | Indicators |
InpUseVolFilter |
bool | true | true/false | Use volume filter - require short ATR > long ATR | Advanced |
InpUseRegimeFilter |
bool | true | true/false | Use regime filter for trend detection | Advanced |
InpUseADXFilter |
bool | false | true/false | Use ADX filter - require ADX above threshold | Advanced |
InpUseEMAFilter |
bool | false | true/false | Use EMA filter - price must be on correct side of EMA | Advanced |
InpUseSMAFilter |
bool | false | true/false | Use SMA filter - price must be on correct side of SMA | Advanced |
Comprehensive backtesting and live trading results
| Metric | Value |
|---|---|
| Total Trades | 247 |
| Win Rate | 68.4% |
| Profit Factor | 1.87 |
| Max Drawdown | -12.3% |
| Sharpe Ratio | 2.14 |
| Average Win | $450 |
| Average Loss | -$280 |
| Largest Win | $1,850 |
| Largest Loss | -$920 |
| Average Trade Duration | 60 Minutes |
Copy the EA file to your MetaTrader 5 installation directory:
C:\Users\[YourUsername]\AppData\Roaming\MetaQuotes\Terminal\[BrokerID]\MQL5\Experts\
Right-click in the Navigator window and select "Refresh" or restart MT5 to see the EA appear in the Expert Advisors list.
Click the "Algo Trading" button in the toolbar (or press Ctrl+E) to enable automated trading. The button should turn green.
A smiley face π in the top-right corner indicates the EA is running. If you see a sad face βΉοΈ, check the Expert logs for errors.
Double-click the EA name in the top-left corner of the chart to open the properties dialog.
| Parameter | Conservative | Moderate | Aggressive |
|---|---|---|---|
| Lot Mode | Percentage | Uncertainty | Uncertainty |
| Risk % | 1.0% | 2.0% | 3.0% |
| Base Risk (Unc) | 3.0% | 5.0% | 8.0% |
| Session | 4:20-23:00 | 04:20-02:45 | 04:20-02:45 |
| Platform | MetaTrader 5 |
| MQL Version | 17.11 |
| Build | Build 2600+ |
| Type | Expert Advisor |
| Timeframes | M1, M5, M15, M30, H1, H4 |
| Best Timeframe | M15, H1 |
| Symbols | Forex majors, minors, crypto |
| Execution Mode | OnTick |
| Min Balance | $500 (recommended $1000+) |
| Account Type | Standard, ECN compatible |
| Hedging | Supported |
| Leverage | 1:100 or higher |
| Lines of Code | ~2,800 |
| Custom Classes | 7 |
| Indicator Handles | 7+ |
| Complexity | Advanced |
Compatible with brokers using market execution
Works with ECN and STP account types
Auto-adapts to 4 or 5 digit broker quotes
For 24/7 operation, VPS hosting is recommended
Trading involves substantial risk of loss and may not be suitable for all investors.
Trading foreign exchange, stocks, futures, options, and cryptocurrencies on margin carries a high level of risk and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade, you should carefully consider your investment objectives, level of experience, and risk appetite. There is a possibility that you could sustain a loss of some or all of your initial investment. Therefore, you should not invest money that you cannot afford to lose.
This Expert Advisor is a software tool designed to assist in analyzing market conditions and executing trades based on predefined algorithms. It does not guarantee profits or success. Past performance results, whether from backtesting, demo trading, or live trading, do not guarantee future results. Different market conditions, broker execution, slippage, and other factors can significantly affect performance.
You are fully responsible for all trading decisions made using this EA, including:
KeyAlgos provides this Expert Advisor "as is" without any warranties, express or implied, including but not limited to warranties of merchantability, fitness for a particular purpose, or non-infringement. We do not guarantee that the EA will be error-free, uninterrupted, or that it will meet your requirements.
Have questions or need support? Reach out to us.