Core Architecture & The Predictive Engine
At the heart of this indicator lies a non-parametric machine learning algorithm utilizing a K-Nearest Neighbors (KNN) approach, optimized via 'Lorentzian Distance'.
Unlike standard Euclidean measurements, the Lorentzian calculation is highly resilient to market outliers and extreme volatility spikes. The model constructs a multi-dimensional "Feature Space" by simultaneously evaluating up to five distinct technical variables (which can include RSI, WaveTrend, CCI, and ADX). For every new bar on the chart, the engine calculates the distance between current market conditions and thousands of historical data points (`Max Bars Back`). It identifies the most mathematically similar historical moments (`Neighbors Count`) and analyzes how the price behaved over the subsequent four bars. The aggregated result dictates whether the algorithm predicts a bullish, bearish, or neutral future.
To further refine these predictions, the system employs **Nadaraya-Watson Kernel Regression**. This advanced smoothing technique applies a Rational Quadratic Kernel to dynamically estimate the underlying trend, filtering out erratic price action and ensuring that machine learning signals align with the broader momentum flow.
Distinctive Capabilities
1. Precision Entry via Dynamic Retest Logic
Financial markets frequently exhibit false breakouts. To counter this, the indicator features a built-in Pullback/Retest mechanism. When the machine learning engine generates a primary signal, the system does not enter blindly. Instead, it marks the breakout level and waits for the price to retrace a user-defined distance (configured in either pure Ticks or Percentage). If the retest occurs within the maximum allowed wait time, the entry is validated, ensuring superior risk-to-reward ratios and avoiding trap entries.
2. The Integrated Trading Simulator
This is a defining feature for system calibration. The indicator renders an on-chart backtesting environment that projects visual Take Profit (TP) and Stop Loss (SL) boxes in real-time. Traders can toggle between calculation modes—Ticks for precise futures/forex scaling, or Percentage for crypto and equity markets. It also features a dynamic Trailing Stop mechanism that locks in profits once a designated activation threshold is crossed.
3. Institutional-Grade Risk Management
Capital preservation is hardcoded into the system via Daily Limits. By establishing strict numerical thresholds for maximum daily loss and daily profit targets, the indicator acts as an algorithmic circuit breaker. Once a limit is breached, all virtual trading ceases for the remainder of the day, protecting both financial capital and psychological bandwidth. Furthermore, the Session Filter allows the engine to strictly operate within specific regional liquidity windows (Asian, London, or New York sessions).
4. Real-Time Telemetry Dashboards
The UI generates persistent on-screen panels. The Performance Dashboard tracks vital telemetry, including total trades, win rate, profit factor, maximum drawdown, and consecutive streak data. Concurrently, the Daily PnL Tracker provides a day-by-day ledger of system performance, offering immediate clarity on recent efficacy.
Operational Blueprint: How to Use the Indicator
Step 1: Feature Engineering & Baseline Setup
Navigate to the 'Feature Engineering' section. Select the specific oscillators (RSI, WT, CCI, ADX) that best fit your target asset's behavior. Adjust the `Neighbors Count` (typically between 4 to 8) to control how many historical matches influence the prediction. A higher number yields smoother, more conservative signals, while a lower number reacts aggressively to recent shifts.
Step 2: Calibrating the Filters
Open the 'Filters' and 'Kernel Settings'. Enable the Volatility and Regime filters to prevent the machine learning model from signaling during tight, unpredictable consolidations. Adjust the Nadaraya-Watson `Lookback Window` (h) and `Relative Weighting` (r) to ensure the kernel ribbon accurately hugs the current timeframe's trend.
Step 3: Configuring the Retest Protocol
In the **Retest Settings**, dictate how the system handles breakouts. Choose your mode (Ticks or Percent) and set the `Retest Distance Value`. For highly volatile assets, a deeper pullback requirement may be necessary. Set the `Max Wait Bars` to define the expiration window for the setup; if the market trends without pulling back, the system will execute a force entry upon expiration to prevent missing a major macro move.
Step 4: Activating the Simulator and Risk Parameters
Scroll to the 'SIM: Backtest Simulator' module. Input your desired SL and TP values based on your asset's average true range. If desired, activate the Trailing Stop, defining exactly when it triggers and how closely it shadows the price. Finally, establish your Daily Stop Loss and Profit Targets in the **Daily Stop Logic** section to ensure the backtest accurately reflects prudent money management.
Step 5: Review and Deploy
Observe the visual boxes drawn on the chart and monitor the Performance Dashboard. Adjust the parameters iteratively until the win rate, drawdown, and recovery factor align with your quantitative goals. Once the visual simulation confirms the edge, the system’s dedicated alerts can be seamlessly mapped to an external webhook bridge for live execution.
-------------------------------------------------//-------------------------------------------------
Special credit goes to 'jdehorty' for his foundational work on the Lorentzian distance classifier and machine learning extensions in Pine Script. His highly innovative approach to non-parametric mathematical classification and outstanding open-source contributions directly empowered the powerful predictive engine at the core of this indicator. His brilliance is greatly appreciated.
