SMT Divergence - Time & Calendar Cycles

This indicator is a tool designed to detect SMT Divergences across multiple market structures.
It operates on a Dual-Layer Logic, which filters, ranks, and renders divergences based on specific, adjustable Time Cycles (e.g., 90-minute, or 30-minute rolling windows) and Calendar Cycles (e.g., Daily, or Weekly structure).
1. Core Concept: Automated SMT Detection
SMT Divergences occur when correlated instruments fail to confirm each other's price action at key structural pivots. For example, if the Nasdaq (NQ) makes a higher high while the S&P 500 (ES) fails to do so, that can be considered a SMT Divergence, this discrepancy in correlation could indicate a potential shift in structural momentum and a weakening of the prevailing trend.
This indicator automates this analysis by comparing the Main Chart against up to three user-defined Comparison Symbols. It supports:
- Direct Correlation: Identifies standard divergences between positively correlated assets where one fails to confirm the other's new high or low (e.g., NQ vs. ES).
- Inverse Correlation: Accounts for negative correlation to detect failures in symmetry, such as when the Main Chart makes a Higher High but the Inverse Symbol fails to make the expected Lower Low (e.g., EURUSD vs. DXY).
- Cross Symbol vs. Symbol: Logic that cross-verifies comparison symbols against each other to find internal market weakness, even if the main chart is currently neutral (e.g., Symbol 1 vs. Symbol 2).
2. How It Works: Technical Architecture
To accurately map market structure, the indicator uses a specific technical method to handle data synchronization and structure storage:
A. Data Synchronization
The tool utilizes 'request.security' targeting the current chart's resolution (native timeframe) to retrieve comparison data of the other symbol. This method enforces strict bar-by-bar alignment between the main symbol and the comparison symbol, preventing the access of future data (lookahead bias) and ensuring historical data integrity.
B. Pivot Arrays
The script identifies significant swing points and stores them in custom arrays. It iterates through these arrays to compare the current price structure against historical structures stored in memory.
The array storage and comparison logic operates in two distinct modes depending on the cycle type:
2.1 Time Cycles (Intraday Analysis)
Targeting specific, adjustable time windows like 90-minute or 30-minute cycles.
- Session Bound: These cycles are strictly bound to a user-defined trading session (e.g., 09:30 - 16:00).
- Continuous Roll: They repeat continuously throughout the window until the session ends.
- Session Reset: At the start of every new session, calculation data resets to ensure signals reflect only the current session, while preserving all historical lines on the chart.
2.2 Calendar Cycles (Macro Analysis)
Targeting Higher Timeframe (HTF) structural analysis (Daily, Weekly, Monthly, Quarterly, and Yearly).
- Persistent Data: Unlike Time Cycles, Calendar Cycles utilize persistent data arrays that survive session resets.
- Calculation Mode: "Exchange Session" prevents ghost lines on Futures, while "Input Timezone" enforces strict midnight resets for Crypto/CFDs.
3. The Unified SMT Visualization
The indicator provides a Composite Visualization, unifying micro (Intraday) and macro (Calendar) analysis by simultaneously projecting divergence signals onto a single chart view.
Live vs. Historical Logic:
The Live Feed (Dynamic State): This is the only component where repainting occurs. Signals within the current active cycle are temporary and self-correcting:
- Updates: If the price pushes to a new extreme within the open cycle, the SMT line automatically redraws to the new High/Low.
- Invalidation: If the Comparison Symbol eventually breaks its structure ("catches up") before the cycle closes, the divergence is no longer valid, and the signal is removed.
- Example: In a 90-minute Time Cycle, a signal might form at minute 30. If the Comparison Symbol confirms the move at minute 45, the signal is invalidated. If the divergence holds until minute 90, it becomes permanent.
The Historian (Permanent Record):
Once a cycle closes, the final state is locked. Validated signals are transferred to the historical array and will never change (non-repainting).
4. Key Features & Capabilities
4.1 Multi-Symbol & Correlation
- Triple-Check Logic: Capable of comparing the Main Chart against Symbol 1, Symbol 2, and Symbol 3 simultaneously.
- Cross-Symbol Check: The script can optionally validate Symbol 1 against Symbol 2 (e.g., checking ES vs. YM) and plot the result on your main chart, providing a broader market view.
4.2 Structural Range Validation
The script includes strict validation logic to ensure high-quality data. It automatically verifies that the detected highs and lows are the true extremes of the cycle range.
- Lookback Cycles: Users define the exact number of preceding historical cycles the current structure must be compared against (e.g., comparing against the last 9 cycles), allowing for customization of structural depth.
4.3 Professional Drawing & Chart Management
- Visual Collision Detection: The script uses Coordinate Tracking to store the start and end points of every rendered divergence. If a lower timeframe cycle attempts to draw over an existing higher-priority structure, the logic compares their coordinates and suppresses the lower-priority signal to prevent visual clutter.
- Data Integrity: The script automatically validates cycle duration to ensure signals do not span across abnormal time gaps or missing data.
- Memory Optimization: The script actively manages internal memory to prevent execution limits, allowing for deep backtesting history even on lower timeframes.
4.4 Structural Parameters
Furthest / Nearest Mode: Determines which specific pivot to target when multiple candidates exist within the same search window.
- Furthest: Targets the extreme point furthest back in time within the cycle range (captures the widest possible structure).
- Nearest: Targets the most recent valid pivot (captures the tightest, most immediate structure).
Anchor Mode: Controls exactly where the divergence line connects:
- Structural: Always connects to the Main Chart's pivot High/Low.
- Snap to Aggressor: The precision method. The line "snaps" to the exact candle where the structure was broken first, whether on the Main Chart or the Comparison Symbol.
Cycle Boundary Overlap: Controls how the transition candle is handled between time cycles (Overlap On vs. Clean Start).
4.5 Full Customization
- Adaptive & Custom Coloring: Labels automatically adjust to background brightness for optimal readability. Includes a manual override for user-defined color preferences.
- Visual Control: Fully customizable line styles, widths, and colors for every individual cycle.
5. How To Use This Tool
Configuration: Set your Timezone and Session Start/End times in the settings. This ensures "Time Cycles" align with your specific market.
Select Symbols: Input your comparison symbols (e.g., ES, YM, or inversely DXY). Crucial: Ensure the "Inverse" toggle is checked for negatively correlated assets.
Cycle Selection: Enable the specific cycles relevant to your strategy (e.g., Daily + 90-minutes).
Render History: Scroll the chart back to the beginning of your available price history after loading the indicator or changing timeframes to process maximum historical data.
Interpretation:
- Bearish SMT: Price makes a Higher High, but the correlated asset makes a Lower High. This divergence could indicate a potential shift in structural momentum and a weakening of the prevailing uptrend.
- Bullish SMT: Price makes a Lower Low, but the correlated asset makes a Higher Low. This divergence could indicate a potential shift in structural momentum and a weakening of the prevailing downtrend.
Disclaimer
This indicator is designed for educational purposes only. It does not constitute financial advice or a recommendation to trade. Trading involves risk, and past performance does not guarantee future results.
Invite-only script
Only users approved by the author can access this script. You'll need to request and get permission to use it. This is typically granted after payment. For more details, follow the author's instructions below or contact TimeLabsAlgo directly.
TradingView does NOT recommend paying for or using a script unless you fully trust its author and understand how it works. You may also find free, open-source alternatives in our community scripts.
Author's instructions
Disclaimer
Invite-only script
Only users approved by the author can access this script. You'll need to request and get permission to use it. This is typically granted after payment. For more details, follow the author's instructions below or contact TimeLabsAlgo directly.
TradingView does NOT recommend paying for or using a script unless you fully trust its author and understand how it works. You may also find free, open-source alternatives in our community scripts.