Open-source Pine scripts that use machine learning ideas, such as nearest-neighbour classification, regression and adaptive filters, inside TradingView.
Pine Script runs on the chart's bars, so "AI" scripts here use compact methods, such as k-nearest neighbours, kernel regression or simple neural networks, coded directly in Pine.
A model that fits past data well can still fail on new data. Look for scripts that train only on past bars and test them on a period they never saw.
25 of these 145 scripts are marked Repaints, or read higher-timeframe data with lookahead on.
Before You Use One
Check that it trains only on bars before the one it predicts.
Test it on data outside the period its author showed.
Read the Risk Notes for repainting.
AI / machine learning: Indicators, Strategies and Libraries
AIActivationFunctionsBipolarSigmoid is a Pine Script library that provides mathematical implementations of the bipolar sigmoid activation function and its derivatives for machine learning algorithms. It calculates bipolar sigmoid values bounded between -1 and
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
This overlay indicator plots a SuperTrend-style band on the price chart using ATR length, a selectable source, and a base factor. Optional settings enable an adaptive factor driven by rate of change, a volatility filter, K-means clustering, and an LSTM layer w
This overlay indicator builds many SuperTrend trailing stops across a user-set ATR length, factor range, and step. Each factor is scored with an exponential performance memory. K-means clustering groups those results, and the user chooses the best, average, or
This overlay indicator scores a bull, bear, or neutral game state from an auditable decision-forest probability rather than a fitted machine-learning model or live API. It compares the smoothed probability with bull and bear thresholds, then shifts it when a s
This overlay strategy combines a Supertrend with a k-nearest-neighbors filter. It smooths price and the Supertrend with weighted moving averages, then uses neighbor count and lookback length to form an AI trend signal. Traders can allow long, short, or both di
Medallion Cipher is a separate-pane indicator that combines a four-state hidden Markov model (bull, bear, range, and crisis) with weighted confluence signals. It can include mean reversion, trend, session timing, pattern matching, Hurst exponent, Shannon entro
AI Debug Helper is a Pine Script indicator that provides AI-powered debugging suggestions for PineScript code. It loads a simulated database of common error patterns such as series index out of bounds, division by zero, Na propagation, infinite loops, and best
This indicator detects pivot highs and lows, evaluates how often levels are respected by price, and uses an internal logistic regression model to estimate the probability that a level will hold. Qualifying support and resistance lines are projected onto the pr
This indicator provides an econometric nowcasting framework to track transmission risks from Brent crude oil prices and USD/VND exchange rates to Vietnam Consumer Price Index (CPI). Operating on a monthly chart, it employs a rolling asymmetric Ridge ARDL regre
This indicator plots an optimal RSI in a separate pane and uses a k-nearest neighbour machine learning routine to adjust lookback and RSI count. It can mark RSI crossings, draw adaptive Bollinger bands around the RSI, and show tables of current settings. Users
This indicator tests a simple neural network for recognizing 2-bit numbers in Pine Script. It converts linear 1D arrays into 2D matrix structures for weights, biases, and activations using custom array functions. The network trains over a user-defined number o
The ANN MACD Future Forecast is an experimental indicator serving as a true deep learning sample on TradingView. It calculates Bollinger Bands and Squeeze Momentum using custom functions for SMA, EMA, standard deviation, highest and lowest values. The script p
An overlay that displays signals produced by an outside machine-learning server, delivered through a data repository read with request.seed. It treats the seeded close value as the direction, volume as confidence, and other fields as strength, anomaly score an
Prints manual long and short signal labels on the price chart using an adaptive scoring method trained on recent settled trade paths, with a warmup count before it starts. It uses the previous closed candles, enters at the current open, and applies a minimum d
A signal overlay that merges two entry sources: an Andean oscillator with clustered Money Flow Index levels, and a UT Bot ATR trailing stop. Signals pass through optional filters: a FRAMA trend channel, a choppiness index, an ATR percentage range, a higher-tim
The AI Dynamic Liquidity Engine indicator detects swing highs and lows on the price chart to identify potential liquidity zones. It tracks swing points in arrays and validates each zone by counting proximity tests based on recent price action. When a zone reac
Markov-HMM Regime v5 classifies each bar as Bull, Bear or Sideways using a hidden Markov model whose parameters were trained offline in Python and pasted into the script. It runs the forward algorithm on price and volume features and loads a parameter set matc
DST HMM v9 Mobile is a variant of a gold-focused hidden Markov model regime indicator, adjusted for mobile screens. It classifies the market into Sideways, Bull and Bear states using Baum-Welch retraining on a rolling window, draws a Kalman filter line with co
A machine-learning style indicator that classifies each bar using a decision matrix built from two chosen independent variables, such as Stochastic, RSI, Z-Score, MFI, volume or a moving-average distance. The target to predict can be red or green candle, bulli
This indicator scores seven approaches on every bar: RSI, volume, VWAP, EMA trend, MACD, Bollinger Bands and a volume-delta module. Each score is weighted by a rolling record of that approach's recent agreement with price, and the weighted total must pass an a
A chart-overlay trailing stop that adapts to market conditions. It uses Kaufman's adaptive moving average to measure how efficiently price is moving, scales an ATR-based stop distance accordingly, and optionally adds a k-nearest-neighbours pattern layer that n
This indicator combines a neural network signal grading engine with moving average and trading session filters directly on the price chart. It plots buy and sell signal labels based on momentum, volatility, and trend conditions evaluated across selectable cand
Kotegawa Pump Tracker is an overlay indicator aimed at volatile crypto markets. It combines an adaptive SuperTrend with a clustering step that sorts recent volatility into high, medium and low levels over an analysis window, and it also uses RSI. According to
A long-only style strategy aimed at finding relative lows in stocks. It checks recent and one-year lows, RSI, the lower Bollinger band, volume against its average, a 200-period moving average bear test, MACD histogram turns, consecutive down days and drop from
A strategy that applies a k-nearest-neighbours classifier to RSI, ROC, CCI or volume features to estimate the next move, then trades long and or short with an optional moving average filter and volatility filter. Each position uses an ATR-multiple stop loss, a
AIActivationFunctionsSigmoid is a utility library for Pine Script v5 that provides mathematical calculations for the sigmoid activation function, commonly used in artificial intelligence and machine learning algorithms. The library exports functions to evaluat
Prints manual long and short signal labels on the price chart using an adaptive method trained on recent settled trade paths. It works on standard time-based charts and scales stop limits with chart bar length. Positions exit only at the stop or target, stay o
A signal overlay that merges Andean oscillator with clustered Money Flow Index entries and UT Bot ATR trailing stop entries. Signals can be filtered by a FRAMA trend channel, a choppiness index, an ATR percentage range and, new in this version, an optional Hur
DST HMM v9 XAUUSD classifies the market into hidden regimes such as Sideways, Bull and Bear using a hidden Markov model retrained on a rolling window with Baum-Welch iterations. It adds a Kalman filter line with confidence bands and an optional multi-bar Kalma
A price-chart overlay that plots a Hull moving average with a set of EMAs, SuperTrend and Bollinger Bands, and scores the market by weighting trend, momentum, volatility, volume, support and resistance, and a k-nearest-neighbours estimate. The nearest-neighbou
An indicator that combines several normalised oscillators, namely RSI, CCI, Fisher, DMI, Z-Score and a moving-average ratio, into one composite, then groups values into clusters over a rolling lookback. Lower and upper percentile settings mark extreme zones, a
This Pine Script v5 library implements a threshold activation function for neural-network style calculations. The exported function returns 1.0 when the input is greater than or equal to zero and 0.0 otherwise. Two derivative exports, derivate and derivate2, a
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
Volume SuperTrend AI (Expo) combines SuperTrend trend filtering with a k-nearest neighbors machine learning classification algorithm. It computes a SuperTrend using customizable moving average types, including simple, exponential, weighted, smoothed, or volume
This strategy fits a binary logistic regression classification model bar by bar on the price chart to generate long trading signals. It computes model weights via iterative gradient descent based on user-defined learning rates, lookback windows, and normalizat
Prints manual long and short signal labels on the price chart using an adaptive method trained on recent settled trade paths, with a warmup count before signals begin. It uses the previous closed candles and enters at the current open, applying a minimum direc
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
This indicator overlays a weighted ensemble of three models on the price chart. It compares the current bar with historical bars using RSI, volume ratio, price change and range position, then blends that KNN vote with a linear-regression projection and an EMA-
This indicator projects future price trajectory directly on the price chart by searching historical price movements for matching patterns. It compares a recent reference window against historical evaluation segments using correlation to identify the most simil
A separate-pane indicator that computes the Money Flow Index and adapts its overbought, neutral and oversold levels using a clustering routine trained on recent data. Inputs set the MFI length, the number of training bars and the iterations per bar. An adjuste
This indicator estimates the next bar's price with a k-nearest neighbors model built from consecutive price samples. It ranks one-dimensional distances, averages the nearest neighbors, and can adjust that projection. Optional signals hint at the next bar's dir
MLExtensions is a Pine Script library providing utility and mathematical helper functions for machine learning indicators, specifically optimized for approximate nearest neighbors classification in Lorentzian space. It includes functions to normalize series de
Calculates MACD line and signal line differences, passing current and previous deltas through a two-layer neural network model with ReLU activation functions. User-configurable weights, biases, and threshold values determine output classification signals. The
The Expectation Maximization Gaussian Mixture Regime indicator clusters market states into two to five components using an online Expectation-Maximization Gaussian Mixture Model. It processes three input features: volatility-normalized momentum, relative volat
Prints manual long and short signal labels on the price chart using an adaptive method trained on recent settled trade paths. It works on standard time-based charts, scaling stop limits with the chart's bar length, and uses the previous closed candles. Options
An overlay that signals long and short setups when a Money Flow Index crosses adaptive levels found by k-means clustering and an Andean oscillator crosses its smoothed signal within a short confirmation window. A 200-period EMA trend filter and an ATR percenta
This indicator classifies the next market direction with a two-feature k-nearest neighbours model. It stores normalized historic indicator values and past directions, then compares the current point to the nearest neighbours using Euclidean or Chebyshev distan
Third-party code. ForexR lists open-source Pine scripts from GitHub; it did not write, test or endorse them, and their summaries are generated automatically from each script's code and README. Indicators describe the past, and a strategy's backtest can look better than live trading. Check a script on a demo account before you rely on it. CFDs and leveraged forex are complex instruments with a high risk of losing money rapidly.
Learn to Use Pine Scripts
Free, plain-English guides: add a script to TradingView, read what it does, test it and avoid the common traps.