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
218 lines of Pine Script v4 from scripts/097-ML-kNN-based-Strategy-(mtf).pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.
Machine Learning: kNN-Based Strategy (MTF) evaluates combinations of fast and slow periods of RSI, Rate of Change (ROC), and Commodity Channel Index (CCI) within a designated training time window to signal potential buy, sell, or hold directions. Inputs permit selecting resolution, custom indicator combinations, training start/stop dates, and optional volatility filtering. Outputs are rendered directly on the price chart. Note that this multi-timeframe script repaints on historical and live data.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Dataset
source
close
ds
Resolution
timeframe
reso
Indicator
string
All
ind
Fast Period
int
14
fast
Slow Period
int
28
slow
To Filter Out Signals By Volatility?
bool
false
fltr
Training Start Year
int
2000
startYear
Training Start Month
int
1
startMonth
Training Start Day
int
1
startDay
Training Stop Year
int
2021
stopYear
Training Stop Month
int
12
stopMonth
Training Stop Day
int
31
stopDay
Show all 14 settings
Setting
Type
Default
Variable
Lot Size
float
0.01
lot_size
Show Information?
bool
true
Show Information?
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 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
An overlay indicator that applies a k-nearest-neighbors machine learning classifier using Lorentzian distance to predict price movement. It evaluates historical market features, such as RSI, WaveTrend, CCI, and ADX, to identify similar price-time patterns and
The Machine Learning Momentum Index uses a k-Nearest Neighbors classification algorithm to evaluate momentum and trend direction directly on the price chart. It records historical parameter pairs derived from weighted moving averages and smoothed RSI values, t
This indicator plots an oscillator in a separate pane. It builds several SuperTrend series across a user-defined factor range and step, using ATR as the band width. On each bar it measures the distance between the close and each SuperTrend output, then groups
Lorentzian Classification is a machine learning indicator that applies a k-nearest neighbors algorithm using Lorentzian distance to analyze market patterns. It processes configurable technical indicators, including RSI, WaveTrend, CCI, and ADX, as feature vect
The Adaptive RSI Moving Average (ARSIMA) is an overlay indicator that dynamically adjusts its smoothing factor based on the Relative Strength Index (RSI). When the RSI moves toward extreme overbought or oversold conditions, the smoothing factor increases to ma