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.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
How to get an access?
Telegram: t.me/MasterTrendPro
Website: master-trend.pro
Telegram: t.me/MasterTrendPro
Website: master-trend.pro
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
How to get an access?
Telegram: t.me/MasterTrendPro
Website: master-trend.pro
Telegram: t.me/MasterTrendPro
Website: master-trend.pro
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.