PROTECTED SOURCE SCRIPT
Eccodax Advanced kNN Lorentziano Matrix

1. What this code is
It is a predictive indicator based on classic Machine Learning (k-Nearest Neighbors), fully implemented in PineScript v6, designed to:
Learn historical market patterns
Compare the current state with similar past states
Estimate the expected future price movement
Reconstruct a projected price consistent with the current level
It is not an oscillator, it is not a traditional technical indicator, and it does not react only to the immediate past.
2. What the Model Learns (Supervised Learning)
2.1 Features (Input Variables)
The model uses three dimensions of information, all normalized by Z-score:
Return
Measures the percentage change in price
Captures the immediate momentum of the market
Momentum (ROC)
Measures acceleration or deceleration of the movement
Differentiates trends from consolidations
Volatility
Measures the degree of market uncertainty
Adjusts the weight of strong movements vs. noise
These three variables form a market state vector.
2.2 Normalization (Z-Score)
Each feature is converted to:
Mean ≈ 0
Standard deviation ≈ 1
This ensures that:
No variable dominates the distance
The statistical comparison is valid
The model is stable in different price regimes
2.3 Target (Predicted Variable)
The model does not predict absolute price. It learns:
Observed future return after forecastBars
That is:
Learns movement, not level
Eliminates historical bias
Avoids predictions inconsistent with the current price
3. How the model makes the prediction
3.1 Search for similar patterns (k-NN)
For each current candle, the model:
Analyzes the last lookback candles
Calculates the Euclidean distance between the current state and each past state
Selects the k most similar states
Observes what happened after them
3.2 Inference
The predicted return is calculated as:
Weighted average of the future returns of the neighbors
Weights inversely proportional to the distance
More similar states → greater influence.
4. Price Reconstruction (Key Information)
From the predicted return, the model reconstructs:
Predicted Price = Current Close × (1 + Predicted Return)
Predicted Price = Current Close × (1 + Predicted Return)
This ensures that:
The forecast respects the current market level
The output is visually interpretable
There is no regression to past regimes
5. Relevant Information the Indicator Delivers
5.1 Predicted Price (Green Line)
What it is: Estimated price after forecastBars.
How to use:
Above the current price → bullish bias
Below → bearish bias
Large distance → expectation of strong movement
5.2 Predicted Return (Implicit)
Even though not plotted directly, it is the most important information in the model.
Positive → expectation of appreciation
Negative → expectation of decline
Negative → expectation of decline
Near zero → sideways market
5.3 Directional Classification (optional)
The model also acts as a binary classifier:
High if expected return > 0
Low if expected return < 0
This is used as:
Noise filter
Trend confirmation
False signal reduction
5.4 Implicit statistical context
The indicator carries information that is not visual, but is fundamental:
Market regime (trending vs. sideways)
Statistical similarity with the past
Relative confidence (via distance from neighbors)
6. What this indicator does NOT do
It is important to align expectations:
❌ Does not predict exogenous events
❌ Does not anticipate gaps
❌ Does not work well on illiquid assets
❌ Does not extrapolate long trends
k-NN replicates patterns, does not create scenarios Unprecedented.
7. Where this model works best
Markets with repetitive structure
Medium timeframes (5m – 1D)
Liquid assets
Environments with alternating regimes
8. How to use it in practice (professional recommendation)
Ideal use:
k-NN direction → bias
Technical indicator → timing
Risk management → execution
Never use it in isolation for entry.
9. Executive summary
This code delivers:
A functional supervised ML model in Pine
Prediction consistent with the current price
Statistical market direction
Reduction of historical bias
Solid foundation for quantitative strategies
Relevant information provided by this code
1. Forecasted price (line)
Statistical projection consistent with the current level
Based on similar historical patterns
2. Implicit direction
Return > 0 → bullish bias
Return < 0 → bearish bias
3. Structural robustness
Lower sensitivity to outliers
Lower scale bias
Better adaptation to different regimes
This refactored version introduces significant improvements based on modern quantitative Machine Learning practices (similar to those found in jdehorty's "Lorentzian Classification" indicator):
Lorentzian Distance: Replaces the Euclidean distance (which is affected by noise and outliers) with Lorentzian Distance, which is much more robust for financial markets.
Matrix Structure: Uses the matrix object in Pine V6 to manage training data more efficiently and cleanly than loose arrays.
Feature Engineering (WaveTrend & RSI): Replaces simple Momentum with normalized indicators (RSI, WaveTrend, CCI, ADX), better capturing market dynamics.
Min-Max Normalization: Features are normalized on a 0-100 scale so that indicators with different magnitudes do not distort the distance calculation.
Inverse Distance Weighting: Instead of a simple average, the nearest neighbors (most similar) have greater weight in the prediction.
It is a predictive indicator based on classic Machine Learning (k-Nearest Neighbors), fully implemented in PineScript v6, designed to:
Learn historical market patterns
Compare the current state with similar past states
Estimate the expected future price movement
Reconstruct a projected price consistent with the current level
It is not an oscillator, it is not a traditional technical indicator, and it does not react only to the immediate past.
2. What the Model Learns (Supervised Learning)
2.1 Features (Input Variables)
The model uses three dimensions of information, all normalized by Z-score:
Return
Measures the percentage change in price
Captures the immediate momentum of the market
Momentum (ROC)
Measures acceleration or deceleration of the movement
Differentiates trends from consolidations
Volatility
Measures the degree of market uncertainty
Adjusts the weight of strong movements vs. noise
These three variables form a market state vector.
2.2 Normalization (Z-Score)
Each feature is converted to:
Mean ≈ 0
Standard deviation ≈ 1
This ensures that:
No variable dominates the distance
The statistical comparison is valid
The model is stable in different price regimes
2.3 Target (Predicted Variable)
The model does not predict absolute price. It learns:
Observed future return after forecastBars
That is:
Learns movement, not level
Eliminates historical bias
Avoids predictions inconsistent with the current price
3. How the model makes the prediction
3.1 Search for similar patterns (k-NN)
For each current candle, the model:
Analyzes the last lookback candles
Calculates the Euclidean distance between the current state and each past state
Selects the k most similar states
Observes what happened after them
3.2 Inference
The predicted return is calculated as:
Weighted average of the future returns of the neighbors
Weights inversely proportional to the distance
More similar states → greater influence.
4. Price Reconstruction (Key Information)
From the predicted return, the model reconstructs:
Predicted Price = Current Close × (1 + Predicted Return)
Predicted Price = Current Close × (1 + Predicted Return)
This ensures that:
The forecast respects the current market level
The output is visually interpretable
There is no regression to past regimes
5. Relevant Information the Indicator Delivers
5.1 Predicted Price (Green Line)
What it is: Estimated price after forecastBars.
How to use:
Above the current price → bullish bias
Below → bearish bias
Large distance → expectation of strong movement
5.2 Predicted Return (Implicit)
Even though not plotted directly, it is the most important information in the model.
Positive → expectation of appreciation
Negative → expectation of decline
Negative → expectation of decline
Near zero → sideways market
5.3 Directional Classification (optional)
The model also acts as a binary classifier:
High if expected return > 0
Low if expected return < 0
This is used as:
Noise filter
Trend confirmation
False signal reduction
5.4 Implicit statistical context
The indicator carries information that is not visual, but is fundamental:
Market regime (trending vs. sideways)
Statistical similarity with the past
Relative confidence (via distance from neighbors)
6. What this indicator does NOT do
It is important to align expectations:
❌ Does not predict exogenous events
❌ Does not anticipate gaps
❌ Does not work well on illiquid assets
❌ Does not extrapolate long trends
k-NN replicates patterns, does not create scenarios Unprecedented.
7. Where this model works best
Markets with repetitive structure
Medium timeframes (5m – 1D)
Liquid assets
Environments with alternating regimes
8. How to use it in practice (professional recommendation)
Ideal use:
k-NN direction → bias
Technical indicator → timing
Risk management → execution
Never use it in isolation for entry.
9. Executive summary
This code delivers:
A functional supervised ML model in Pine
Prediction consistent with the current price
Statistical market direction
Reduction of historical bias
Solid foundation for quantitative strategies
Relevant information provided by this code
1. Forecasted price (line)
Statistical projection consistent with the current level
Based on similar historical patterns
2. Implicit direction
Return > 0 → bullish bias
Return < 0 → bearish bias
3. Structural robustness
Lower sensitivity to outliers
Lower scale bias
Better adaptation to different regimes
This refactored version introduces significant improvements based on modern quantitative Machine Learning practices (similar to those found in jdehorty's "Lorentzian Classification" indicator):
Lorentzian Distance: Replaces the Euclidean distance (which is affected by noise and outliers) with Lorentzian Distance, which is much more robust for financial markets.
Matrix Structure: Uses the matrix object in Pine V6 to manage training data more efficiently and cleanly than loose arrays.
Feature Engineering (WaveTrend & RSI): Replaces simple Momentum with normalized indicators (RSI, WaveTrend, CCI, ADX), better capturing market dynamics.
Min-Max Normalization: Features are normalized on a 0-100 scale so that indicators with different magnitudes do not distort the distance calculation.
Inverse Distance Weighting: Instead of a simple average, the nearest neighbors (most similar) have greater weight in the prediction.
보호된 스크립트입니다
이 스크립트는 비공개 소스로 게시됩니다. 하지만 이를 자유롭게 제한 없이 사용할 수 있습니다 – 자세한 내용은 여기에서 확인하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
보호된 스크립트입니다
이 스크립트는 비공개 소스로 게시됩니다. 하지만 이를 자유롭게 제한 없이 사용할 수 있습니다 – 자세한 내용은 여기에서 확인하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.