This indicator calculates a trend direction and smoothed moving average using a k-nearest neighbours (k-NN) classification algorithm directly on the main price chart.
1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
126 lines of Pine Script v5 from AI Trend Navigator [K-Neighbor].pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
Users can select input price types, target values, neighborhood size, and smoothing periods. The script displays trend signals through moving average coloring and an optional background highlight showing positive or negative trend predictions. Plots dynamically adjust as new price bars develop.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
PriceValue
string
hl2
PriceValue
maLen
int
5
maLen
TargetValue
string
Price Action
TargetValue
maLen_
int
5
maLen_
Number of Closest Values
int
3
numberOfClosestValues
Smoothing Period
int
50
smoothingPeriod
Upknn_col
color
color.lime
Upknn_col
Dnknn_col
color
color.red
Dnknn_col
Neuknn_col
color
color.orange
Neuknn_col
Maknn_col
color
color.teal
Maknn_col
Trend Prediction Color
bool
false
bgcolor
Up_col
color
color.lime
Up_col
Show all 13 settings
Setting
Type
Default
Variable
Dn_col
color
color.red
Dn_col
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.
This indicator calculates a locally weighted regression curve alongside a standard linear regression line to detect directional price shifts. It identifies potential buy signals when the weighted line crosses below the linear regression while falling over a de
The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec
This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab
This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B
This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre
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