Indicator · Pine Script v5 · On the chart

KNN Machine Learning Momentum Indicator

by Focal-QuantAI

An indicator on the price chart that applies a k-nearest neighbours classifier to short-period RSI and moving average deviation features.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code200
Settings16inputs
LicenceNone stated
Last update6 months ago11 Apr 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above. It reads the file straight from GitHub.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

The code stays on GitHub. The author has not published this script under an open licence, so ForexR does not show its code. Copy script reads the file straight from GitHub into your clipboard, so you can still try it on your own chart. Ask the author before reusing the code anywhere else.

Overview

Features are z-score normalised, optionally compressed with principal component analysis, and compared with a rolling training window using a Minkowski distance. Past bars are labelled bullish, bearish or neutral by what happened over a momentum window, and a signal needs a probability above a set threshold. It also offers bar coloring, a trend EMA and a performance table.

Details

Published by

Focal-QuantAI on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

AI / machine learning, Oscillators & momentum

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
K-Neighbors (K)int5k_neighbors
Learning Window Sizeint400window_size
Prediction Thresholdfloat0.9prob_threshold
Momentum Windowint4momentum_window
Short RSI Periodint2rsi_short_len
Mid RSI Periodint3rsi_mid_len
Long RSI Periodint4rsi_long_len
Short MA Periodint2ma_short_len
Medium MA Periodint3ma_medium_len
Long MA Periodint4ma_long_len
Signal Line Periodint4signal_len
Minkowski Parameter (p)float2.0p_param
Show all 16 settings
SettingTypeDefaultVariable
Enable PCA Compressionbooltrueuse_pca
Dynamic Bar Coloringbooltrueuse_bar_color
Show Model Performance Tablebooltrueshow_table
Trend Filter (EMA)int20ema_len
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

257 stars

This indicator uses a Lorentzian distance k-nearest neighbors classification algorithm to predict market direction based on up to five technical features, such as RSI, WaveTrend, CCI, and ADX. It compares current feature values against historical bar patterns

Indicator v5 AI / machine learningOscillators & momentum
Updated 6 weeks ago · None stated GitHub repository of Donald - Machine Learning Options

This indicator applies a k-nearest neighbours (kNN) classification algorithm using Aroon indicator lags and momentum as feature inputs to forecast market direction. It compares current values against historical feature sets to classify bars into buy, hold, or

Indicator v4 AI / machine learningTrend Repaints
Updated 1 year ago · None stated GitHub repository of Machine Learning: kNN-based Strategy (aroon)

Machine Learning: Lorentzian Classification

by artificial-intelligence-edge
75 stars

This indicator classifies the current bar by comparing its feature vector with historical bars using Lorentzian distance and a k-nearest-neighbors vote. Configurable features include RSI, WaveTrend, CCI, and ADX. Optional volatility, regime, ADX, and EMA filte

Indicator v5 AI / machine learningOscillators & momentum
Updated 3 days ago · MIT GitHub repository of Machine Learning: Lorentzian Classification
3 stars

Farid Makram Custom Levels is a multi-signal indicator for TradingView that combines RSI momentum analysis with MOBO oscillator signals based on the DPO. It generates buy and sell signals when RSI crosses its moving average or when DPO crosses zero, with confi

Indicator v5 Oscillators & momentumMoving averages
Updated 5 months ago · None stated GitHub repository of Farid Makram Custom Levels
1 stars

An overlay that marks long and short signals by combining a Money Flow Index with k-means derived overbought and oversold levels, and an Andean oscillator crossing its signal line, both within a confirmation window. Optional trend and ATR percentage filters ca

Indicator v5 Oscillators & momentumAI / machine learning
Updated 7 weeks ago · None stated GitHub repository of AI MFI + Andean ETH 15min

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers