OPEN-SOURCE SCRIPT
Master Trend AI

Master Trend · AI is a standalone overlay companion to the Master Trend indicator. It runs three independent machine-learning algorithms on the same channel features and consolidates their signals into a single on-chart table.
─── How it works ───
KNN Lorentzian Classifier
Searches the last N bars for the k historical states most similar to the current market (RSI, smoothed RSI, ATR ratio, position inside the Master Trend channel). Each matched bar is labelled bullish or bearish based on its 4-bar forward return. The majority vote determines the prediction and confidence score.
Linear Regression Forecast
Fits a least-squares line to the last N closing prices and projects it forward. A dashed line on the chart shows the projected price target. The table shows the expected percentage change from the current close.
Naive Bayes Classifier
Estimates Gaussian probability distributions of RSI and volatility features, separately for bull and bear historical bars. Applies Bayes' theorem via log-likelihood to produce a calibrated probability P(bull) / P(bear).
─── Table (top-right corner) ───
Three columns — KNN · LinReg · Bayes — with three rows:
─── Setup ───
─── Alerts ───
─── Notes ───
─── How it works ───
KNN Lorentzian Classifier
Searches the last N bars for the k historical states most similar to the current market (RSI, smoothed RSI, ATR ratio, position inside the Master Trend channel). Each matched bar is labelled bullish or bearish based on its 4-bar forward return. The majority vote determines the prediction and confidence score.
Linear Regression Forecast
Fits a least-squares line to the last N closing prices and projects it forward. A dashed line on the chart shows the projected price target. The table shows the expected percentage change from the current close.
Naive Bayes Classifier
Estimates Gaussian probability distributions of RSI and volatility features, separately for bull and bear historical bars. Applies Bayes' theorem via log-likelihood to produce a calibrated probability P(bull) / P(bear).
─── Table (top-right corner) ───
Three columns — KNN · LinReg · Bayes — with three rows:
- Signal — ▲ BULL / ▼ BEAR / ● NEUT (LinReg shows ▲ UP / ▼ DOWN)
- Strength — KNN: vote confidence %; LinReg: projected Δ%; Bayes: class probability %
- Detail — KNN: votes / k; LinReg: target price; Bayes: raw p-value
─── Setup ───
- Add Master Trend to the chart.
- Add Master Trend · AI as a second overlay on the same chart.
- Open the "Trend (sync with Master Trend)" group and match Length and Multiplier to your Master Trend settings. The AI channel feature depends on these values being identical.
─── Alerts ───
- AI+Trend LONG — KNN predicts bullish and Master Trend fires a long signal simultaneously.
- AI+Trend SHORT — KNN predicts bearish and Master Trend fires a short signal simultaneously.
─── Notes ───
- All three models are recalculated on every bar from scratch — no external data, no repainting from lookahead.
- KNN and Naive Bayes share the same Lookback / Step parameters for consistency; LinReg has its own length.
- Signals become active after Lookback bars have elapsed from the chart's first bar.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
How to get an access?
Telegram: t.me/MasterTrendPro
Website: master-trend.pro
Telegram: t.me/MasterTrendPro
Website: master-trend.pro
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
How to get an access?
Telegram: t.me/MasterTrendPro
Website: master-trend.pro
Telegram: t.me/MasterTrendPro
Website: master-trend.pro
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.