OPEN-SOURCE SCRIPT
Aggiornato

Multi-Timeframe SFP + SMT

856
Important: Please Read First
This indicator is not a "one size fits all" solution. It is a professional and complex tool that requires you to learn how to use it, in addition to backtesting different settings to discover what works best for your specific trading style and the assets you trade. The default settings provided are my personal preferences for trading higher-timeframe setups, but you are encouraged to experiment and find your own optimal configuration.

Please note that while this initial version is solid, it may still contain small errors or bugs. I will be actively working on improving the indicator over time. Also, be aware that the script is not written for maximum efficiency and may be resource-intensive, but this should not pose a problem for most users.

The source code for this indicator is open. If you truly want to understand precisely how all the logic works, you can copy and paste the code into an AI assistant like Gemini or ChatGPT and ask it to explain any part of the script to you.

Author's Preferred Settings (Guideline)
As a starting point, here are the settings I personally use for my trading:

SFP Timeframe: 4-Hour (Strength: 5-5)

Max Lookback: 35 Bars

Raid Expiration: 1 Bar

SFP Lines Limit: 1

SMT Timeframe 1: 30-Minute (Strength: 2-2) with 3-Minute LTF Detection.

SMT Timeframe 2: 15-Minute (Strength: 3-3) with 3-Minute LTF Detection.

SMT Timeframe 3: 1-Hour (Strength: 1-1) with 3-Minute LTF Detection.

SMT Timeframe 4: 15-Minute (Strength: 1-1) with 3-Minute LTF Detection.

Multi-Timeframe SMT: An Overview
This indicator is a powerful tool designed to identify high-probability trading setups by combining two key institutional concepts: Swing Failure Patterns (SFP) on a higher timeframe and Smart Money Technique (SMT) divergences on a lower timeframe. A key feature is the ability to configure and run up to four independent SMT analyses simultaneously, allowing you to monitor for divergences across multiple timeframes (e.g., 15m, 1H, 4H) from a single indicator.

Its primary purpose is to generate automated signals through TradingView's alert system. By setting up alerts, the script runs server-side, monitoring the market for you. When a setup presents itself, it will send a push notification to your device, allowing you to personally evaluate the trade without being tied to your screen.

The Strategy: HTF Liquidity Sweeps into LTF SMT
The core strategy is built on a classic institutional trading model:

Wait for a liquidity sweep on a significant high timeframe (e.g., 4-hour, Daily).

Once liquidity is taken, look for a confirmation of a shift in market structure on a lower timeframe.

This indicator uses an SMT divergence as that confirmation signal, indicating that smart money may be stepping in to reverse the price.

How It Works: The Two-Step Process
The indicator's logic follows a precise two-step process to generate a signal:

Step 1: The Swing Failure Pattern (SFP)

First, the indicator identifies a high-timeframe liquidity sweep. This is configured in the "Swing Failure Pattern (SFP) Timeframe" settings.

It looks for a candle that wicks above a previous high (or below a previous low) but then closes back within the range of that pivot. This action is known as a "raid" or a "swing failure," suggesting the move failed to find genuine momentum.

Step 2: The SMT Divergence

The moment a valid SFP is confirmed, the indicator's multiple SMT engines activate.

Each engine begins monitoring the specific SMT timeframe you have configured (e.g., "SMT Timeframe 1," "SMT Timeframe 2," etc.) for a Smart Money Technique (SMT) divergence.

An SMT divergence occurs when two closely correlated assets fail to move in sync. For example, after a raid on a high, Asset A makes a new high, but Asset B fails to do so. This disagreement suggests weakness and a potential reversal.

When the script finds this divergence, it plots the SMT line and triggers an alert.

The Power of Alerts
The true strength of this indicator lies in its alert capabilities. You can create alerts for both unconfirmed and confirmed SMTs.

Enable Alerts LTF Detection: These alerts trigger when an unconfirmed, potential SMT is spotted on the lower "LTF Detection" timeframe. While not yet confirmed, these early alerts can notify you of a potential move before it fully happens, allowing you to be ahead of the curve and find the best possible trade entries.

Enable Alerts Confirmed SMT: These alerts trigger only when a permanent, confirmed SMT line is plotted on your chosen SMT timeframe. These signals are more reliable but occur later than the early detection alerts.

Key Concepts Explained
What is Pivot Strength?

Pivot Strength determines how significant a high or low needs to be to qualify as a valid structural point. A setting of 5-5, for example, means that for a candle's high to be considered a valid pivot high, its high must be higher than the highs of the 5 candles to its left and the 5 candles to its right.

Higher Strength (e.g., 5-5, 8-8): Creates fewer, but more significant, pivots. This is ideal for identifying major structural highs and lows on higher timeframes.

Lower Strength (e.g., 2-2, 3-3): Creates more pivots, making it suitable for identifying the smaller shifts in momentum on lower timeframes.

Raid Expiration & Validity

An SFP signal is not valid forever. The "Raid Expiration" setting determines how many SFP timeframe bars can pass after a raid before that signal is considered "stale" and can no longer be used to validate an SMT. This ensures your SMT divergences are always in response to recent liquidity sweeps.

Why You Must Be on the Right Chart Timeframe to See SMT Lines

Pine Script™ has a fundamental rule: an indicator running on a chart can only "see" the bars of that chart's timeframe or higher.

When the SMT logic is set to the 15-minute timeframe, it calculates its pivots based on 15-minute data. To accurately plot lines connecting these pivots, you must be on a 15-minute chart or lower (e.g., 5-minute, 1-minute).

If you are on a higher timeframe chart, like the 1-hour, the 15-minute bars do not exist on that chart, so the indicator has no bars to draw the lines on.

This is precisely why the alert system is so powerful. You can set your alert to run on the 15-minute timeframe, and TradingView's servers will monitor that timeframe for you, sending a notification regardless of what chart you are currently viewing.
Note di rilascio
IMPORTANT NOTE ON USAGE
To see SMT signals visually on your chart, your chart's timeframe must be the same as or lower than the SMT timeframe setting. However, this indicator is designed to be used with TradingView's server-side alerts. The intended workflow is to set up alerts that run in the background. The script will then monitor your chosen SMT timeframes and send you a push notification when a signal is found, allowing you to go to your chart and analyze the setup for a potential trade.

Summary of Changes
The new version of the script is now much smarter about how it finds trading signals. The detection of the initial raid, or Swing Failure Pattern (SFP), has been completely redesigned for more reliability. The old version confirmed an SFP based on a single candle's action, while the new version now requires a two-candle pattern for higher confidence.

Most importantly, the old version would only show you one SMT divergence after a raid. The new version will now show you all SMT divergences that occur within a specific time window after a raid, giving you more opportunities. Finally, the script is visually cleaner with a standard red and green color scheme, new alerts for both unconfirmed (early) and confirmed SFP lines, and more informative labels that explicitly state if a signal is "SMT Bearish" or "SMT Bullish."

## Simplified Changelog: Key Differences
1. Smarter SFP Detection (Two-Candle Confirmation)
The method for identifying the initial price raid has been upgraded from a one-candle pattern to a more robust two-candle confirmation model.

Old Way (One-Candle Logic): An SFP was confirmed instantly if a single candle both broke above a prior high and also closed below it. This was fast but could catch false moves.

New Way (Two-Candle Logic): The script is now more patient and requires two steps for a higher-quality signal:

Candle 1 (The Raid): When the first candle breaks a prior high, the script flags it as a potential raid by drawing a temporary dashed line.

Candle 2 (The Confirmation): The script then waits for the very next candle to close. The SFP is only confirmed (and the line becomes solid) if this second candle also closes below the price level that was raided. This ensures the price is showing genuine weakness after the raid.

2. Finding Multiple SMTs from a Single Raid
This is a major functional upgrade that gives you more potential signals.

Old Way: After an SFP raid occurred, an SMT timeframe was only allowed to find and draw one SMT divergence. To find another one, it had to wait for a completely new SFP raid.

New Way (More Opportunities): After a confirmed SFP raid, a time window opens (you set this with the Raid Expiration input). During this entire window, the script will continuously look for and draw every SMT divergence it finds. This allows you to see multiple signals that may form as a result of the same initial liquidity grab.

3. Cleaner Visuals and Better Information
The on-chart display has been improved for clarity and provides more direct information.

Standard Colors: Instead of a "rainbow" of different colors for each timeframe, all signals now use a simple and clean red (for bearish) and green (for bullish) system. This makes the chart much easier to read at a glance.

More Detailed Labels: The pop-up labels for each signal are now much more informative. They explicitly state "SMT Bearish" or "SMT Bullish" and tell you the exact settings used for both the SMT divergence and the SFP raid that validated it, so you have full context directly on your chart.
Note di rilascio
Core Pivot Engine Rework (Most Significant Change)

Old Version: The engine was built around the bar_index. It stored the bar index of pivots and required a complex helper function (getPrecisionData) to find them on the chart. This method was not only less reliable across different chart sessions, but it could also fail when looking too far back in historical data, causing a runtime error that would stop the script from functioning.

New Version: The engine is now time-based. It directly tracks and stores the exact timestamp of the high and low within each higher-timeframe period. This eliminates the need for the getPrecisionData function entirely and makes plotting pivots with xloc.bar_time far more accurate. This new efficiency allows for more sensitive default pivot strength settings, causing more pivots to be plotted on the chart. Furthermore, it introduces a visual 'Pivot A' label, clearly indicating which pivot is currently being monitored for a potential SMT divergence. Most importantly, this time-based approach prevents the runtime errors seen in the old version, ensuring the script runs smoothly over deep historical data.

LTF Early Detection Engine Rework

Old Version: Early SMT detection worked by identifying pivots on the lower timeframe. A key weakness was that it required these LTF pivots to form simultaneously on both assets. Since LTF pivots rarely align perfectly in time, this frequently led to missed signals.

New Version: The engine is now far more reliable. Instead of waiting for simultaneous LTF pivots, it now compares the high or low of each single closing LTF bar against the established HTF 'Pivot A'. This change ensures that any potential divergence is caught immediately, preventing missed signals caused by timing discrepancies. To further enhance reliability, a robust fallback system has been added. If data for the user-selected LTF is unavailable (which is often the case far back in history), the script automatically tries to find a signal on the '15min' and then the '60min' timeframes.

History Collection and Logic

Old Version: Used separate logic paths and arrays for plotting simple pivot crosses versus finding SMT pivots, making it more complex.

New Version: The logic is unified. The same historical arrays that are built for plotting pivot crosses are now used for SMT detection. This makes the code much more direct, efficient, and easier to understand.
Note di rilascio
Added more timeframes.
Note di rilascio
This indicator is best used by setting alerts on tradingview and using the script as it's trigger. This will run the script server side and give push notifications for the setups.
Note di rilascio
New Features & Advanced Controls
Advanced SFP Timeframe Controls: The SFP (Swing Failure Pattern) module is now much more powerful.

Separate SFP Confirmation Timeframe: You can now identify SFP pivots on one timeframe (e.g., 4H) and use a different, lower timeframe (e.g., 1H) to confirm the raid. This allows for more nuanced and potentially faster signal validation. Look for "Use Separate Confirmation TF" in the settings.

Custom SMT Timeout Timeframe: Previously, the SMT validity window (Raid Expiration) was tied to the SFP pivot timeframe. You can now set a custom timeframe for this expiration counter. For example, you can now validate an SMT if it occurs within 2 bars on the 60-minute chart after a 4-hour SFP, giving you granular control over how long an SFP remains valid. Look for "Use Custom Timeout TF".

Toggle Pivot 'A' Visibility: To help declutter the chart, you can now hide the "A" label that marks the initial pivot of an SMT setup.

⚙️ Improvements & Refinements
Major Code Refactoring & Performance Boost:

The previous five separate SMT modules have been consolidated and reduced to four. This significantly streamlines the code, reduces the script's load on your chart, and improves overall performance and stability.

Internal variable names and logic have been standardized, making the code much cleaner and easier to maintain.

Revamped User Interface & Settings:

The script settings have been reorganized into more logical groups.

Descriptive Tooltips have been added to every single input, clearly explaining what each setting does and how it affects the indicator's logic.

Input labels have been clarified for better understanding (e.g., "SFP Timeframe" is now "Pivot Timeframe" to be more specific).

Simplified Alert System:

The separate SFP alert toggles for "Unconfirmed Raid" and "Confirmed SFP" have been merged into a single "Enable SFP Alerts" checkbox.

SMT alert messages have been made more generic for consistency across the different modules.

❌ Removed
SMT Timeframe 5: To optimize performance and reduce redundancy, the fifth SMT detection module has been removed. The four remaining modules provide ample multi-timeframe analysis capabilities with improved efficiency.

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.