OPEN-SOURCE SCRIPT
SMT w Alerts

This script is a Smart Money Tool (SMT) Divergence Indicator written in TradingView's Pine Script v6. It automatically detects and visualizes instances where highly correlated assets (like NQ, ES, and YM) fall out of sync at major price swings.
Here is a breakdown of how the script works and its key features:
1. Core Logic (Pivot Tracking)
The script uses ta.pivothigh and ta.pivotlow to identify swing highs and swing lows on your main chart based on a window of bars (default 3 bars left and right). It remembers the most recent pivot and the one right before it so it can compare the two.
2. Dual-Symbol Comparison
When a pivot is confirmed on your main chart, the script immediately looks at the price action of two comparison symbols (e.g., MNQ and MES) at that exact same time.
Tolerance Window: Because assets like NQ and ES don't always peak on the exact same 1-minute or 5-minute candle, the script includes a "Comparison Tolerance" input. It looks a few bars before and after the pivot on the comparison symbols to find their true peak/valley.
3. Divergence Detection
The script compares the slope of the pivots on your chart against the comparison symbols:
Bearish SMT (Highs): If your chart makes a Higher High, but the comparison symbol makes a Lower High (or vice versa). This indicates underlying weakness in the buying pressure.
Bullish SMT (Lows): If your chart makes a Lower Low, but the comparison symbol makes a Higher Low (or vice versa). This indicates underlying strength in the selling absorption.
It checks both comparison symbols simultaneously — if an SMT forms against either of them, it triggers the signal.
4. Visuals & Aesthetics
The SMT Bracket: When an SMT is detected, it draws a clean bracket (or "bridge") connecting the two diverging pivots. It draws horizontal tick marks at the pivots, vertical lines extending outward, and a horizontal bridge connecting them with a small "SMT" label. The bracket dynamically sizes itself using ATR (Average True Range).
Unused Pivots: Pivots that do not result in an SMT divergence are optionally connected with subtle grey dashed lines so you can see the market structure.
Bar Coloring: The candle where the SMT is officially confirmed is highlighted with a subtle background color.
5. Dashboard & Alerts
Dashboard: A clean table in the top right corner tracks how many Bearish and Bullish SMTs have occurred on the chart, and how many bars ago the most recent one fired.
Alerts: The script exposes alert conditions (alertcondition) that you can hook into TradingView's alert system to receive notifications when a Bullish or Bearish SMT forms.
Here is a breakdown of how the script works and its key features:
1. Core Logic (Pivot Tracking)
The script uses ta.pivothigh and ta.pivotlow to identify swing highs and swing lows on your main chart based on a window of bars (default 3 bars left and right). It remembers the most recent pivot and the one right before it so it can compare the two.
2. Dual-Symbol Comparison
When a pivot is confirmed on your main chart, the script immediately looks at the price action of two comparison symbols (e.g., MNQ and MES) at that exact same time.
Tolerance Window: Because assets like NQ and ES don't always peak on the exact same 1-minute or 5-minute candle, the script includes a "Comparison Tolerance" input. It looks a few bars before and after the pivot on the comparison symbols to find their true peak/valley.
3. Divergence Detection
The script compares the slope of the pivots on your chart against the comparison symbols:
Bearish SMT (Highs): If your chart makes a Higher High, but the comparison symbol makes a Lower High (or vice versa). This indicates underlying weakness in the buying pressure.
Bullish SMT (Lows): If your chart makes a Lower Low, but the comparison symbol makes a Higher Low (or vice versa). This indicates underlying strength in the selling absorption.
It checks both comparison symbols simultaneously — if an SMT forms against either of them, it triggers the signal.
4. Visuals & Aesthetics
The SMT Bracket: When an SMT is detected, it draws a clean bracket (or "bridge") connecting the two diverging pivots. It draws horizontal tick marks at the pivots, vertical lines extending outward, and a horizontal bridge connecting them with a small "SMT" label. The bracket dynamically sizes itself using ATR (Average True Range).
Unused Pivots: Pivots that do not result in an SMT divergence are optionally connected with subtle grey dashed lines so you can see the market structure.
Bar Coloring: The candle where the SMT is officially confirmed is highlighted with a subtle background color.
5. Dashboard & Alerts
Dashboard: A clean table in the top right corner tracks how many Bearish and Bullish SMTs have occurred on the chart, and how many bars ago the most recent one fired.
Alerts: The script exposes alert conditions (alertcondition) that you can hook into TradingView's alert system to receive notifications when a Bullish or Bearish SMT forms.
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.
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.
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.