Indicator · Pine Script v5 · Own pane

SMT Divergence

by Ahmed1926· code credited to TFlab

An indicator in a separate pane that looks for smart money technique divergence between the chart symbol and a second symbol, which defaults to gold.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code119
Settings6inputs
LicenceNone statedfile: MPL-2.0
Last update9 months ago31 Jan 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

119 lines of Pine Script v5 from SMT Divergence.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

SMT Divergence.txt
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TFlab

//@version=5
indicator("SMT Divergence ICT 01 [TradingFinder] Smart Money Technique", shorttitle="TFlab SMT", overlay=false ,max_bars_back = 5000 , max_labels_count = 500, max_lines_count = 500)
ATR = ta.atr(55)
Sym = input.symbol('XAUUSD' , 'Second Symbol')
n = input.int(2, title  ="Divergence Fractal Periods", minval=1 , group = 'Logic Setting')
Bull_Line  = input.bool(true, 'Show SMT Divergence Line from the Bottom.') 
Bull_Label  = input.bool(true, 'Show SMT Divergence Label from the Bottom.') 
Bear_Line = input.bool(true, 'Show SMT Divergence Line from the Top.') 
Bear_Label = input.bool(true, 'Show SMT Divergence Label from the Top.') 

//Fractal////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[Open, High, Low, Close] = request.security(Sym, timeframe.period,[open, high, low, close])
// UpPivot
UpPivot = bool(ta.pivothigh(n,n))

// DownPivot
DownPivot = bool(ta.pivotlow(n,n))


// plotshape(DownPivot and Show_Fractal =='Yes', style=shape.triangleup, location=location.belowbar, offset=-n, color= color.rgb(57, 160, 60), size = size.tiny)
// plotshape(UpPivot and Show_Fractal =='Yes', style=shape.triangledown,   location=location.abovebar, offset=-n, color= color.rgb(236, 69, 69), size = size.tiny)

//Data//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Bearish Divergence Data

//price Data
High_Last_Price = ta.valuewhen(UpPivot,high[n],0)
High_Per_Price = ta.valuewhen(UpPivot,high[n],1)

//MACD hist Data
High_Last_Hist = ta.valuewhen(UpPivot, High[n],0)
High_Per_Hist = ta.valuewhen(UpPivot, High[n],1)

//Bar index Data
High_Last_Bar = ta.valuewhen(UpPivot, bar_index[n],0)
High_Per_Bar = ta.valuewhen(UpPivot, bar_index[n],1)

// Time Condition Bullish
Time_Condition_Bear = (High_Last_Bar + 30) > bar_index


//Bearish Divergenc Detector////////////////////////
Last_Bearish_Divergece = if High_Last_Hist > 0 and High_Per_Hist > 0 and Time_Condition_Bear and (High_Last_Bar - High_Per_Bar) < 30
    ((High_Last_Price > High_Per_Price) and (High_Last_Hist < High_Per_Hist)) or ((High_Last_Price < High_Per_Price) and (High_Last_Hist > High_Per_Hist)) 
else 
    false

// Bullish Divergennce Data

//price Data
Low_Last_Price = ta.valuewhen(DownPivot,low[n],0)
Low_Per_Price = ta.valuewhen(DownPivot,low[n],1)

//MACD hist Data
Low_Last_Hist = ta.valuewhen(DownPivot, Low[n],0)
Low_Per_Hist = ta.valuewhen(DownPivot, Low[n],1)

//Bar index Data
Low_Last_Bar = ta.valuewhen(DownPivot, bar_index[n],0)
Low_Per_Bar = ta.valuewhen(DownPivot, bar_index[n],1)



// Time Condition Bullish
Time_Condition_Bull = (Low_Last_Bar + 30) > bar_index 

//Bullish Divergenc Detector////////////////////////
Last_Bullish_Divergece = if Low_Last_Hist > 0 and Low_Per_Hist > 0 and Time_Condition_Bull and (Low_Last_Bar - Low_Per_Bar) < 30
    ((Low_Last_Price < Low_Per_Price) and (Low_Last_Hist > Low_Per_Hist)) or ((Low_Last_Price > Low_Per_Price) and (Low_Last_Hist < Low_Per_Hist))
else 
    false
//count_Bear_Divergence
var int CBullDive = 0 
  
if bool(ta.change(Low_Last_Price)) and Last_Bullish_Divergece == true
    CBullDive := CBullDive + 1
else if Last_Bullish_Divergece == false
    CBullDive := 0


// plot
//Divergence Line & Label

Drawing(Bull_Line, Bear_Line, Bull_Label, Bear_Label)=>
    var line BeLine = na
    var line BuLine = na 
    var label BeLabel = na
    var label BuLabel = na
    var line BeLine_OnChart = na
    var line BuLine_OnChart = na 
    var label BeLabel_OnChart = na
    var label BuLabel_OnChart = na
// 

    if Last_Bullish_Divergece
        if Bull_Line
            BuLine := line.new(Low_Per_Bar, Low_Per_Hist, Low_Last_Bar,Low_Last_Hist , color = color.black , width = 1, style = line.style_dashed)
            BuLine_OnChart := line.new(Low_Per_Bar, low[bar_index - Low_Per_Bar], Low_Last_Bar,low[bar_index - Low_Last_Bar] , color = color.black , width = 1 , force_overlay = true, style = line.style_dashed)
        if Bull_Label
            BuLabel := label.new(Low_Last_Bar,Low_Last_Hist , '+SMT', color = color.green, textcolor = color.white, size = size.tiny , style = label.style_label_up)
            BuLabel_OnChart := label.new(Low_Last_Bar,low[bar_index - Low_Last_Bar] , '+SMT', color = color.green, textcolor = color.white, size = size.tiny , style = label.style_label_up, force_overlay = true)
  
    if Last_Bearish_Divergece
        if Bear_Line
            BeLine := line.new(High_Per_Bar,High_Per_Hist, High_Last_Bar,High_Last_Hist , color = color.black, width = 1, style = line.style_dashed)
            BeLine_OnChart := line.new(High_Per_Bar,high[bar_index - High_Per_Bar], High_Last_Bar,high[bar_index - High_Last_Bar] , color = color.black, width = 1, force_overlay = true, style = line.style_dashed)
        if Bear_Label
            BeLabel := label.new(High_Last_Bar,High_Last_Hist ,'-SMT', color = color.red, textcolor = color.white, size = size.tiny, style = label.style_label_down)
            BeLabel_OnChart := label.new(High_Last_Bar,high[bar_index - High_Last_Bar] ,'-SMT', color = color.red, textcolor = color.white, size = size.tiny, style = label.style_label_down, force_overlay = true)


plotcandle(Open, High, Low, Close, color = Close >= Open ? #089981 : #f23645 ,wickcolor = Close >= Open ? #089981 : #f23645, bordercolor = Close >= Open ? #089981 : #f23645)
Drawing(Bull_Line, Bear_Line, Bull_Label, Bear_Label)

My Note: I'll definitely have to remove the Pane Labels.

Overview

SMT Divergence finds fractal pivot highs and lows on both, compares the latest two on each, and flags a bullish or bearish divergence when their directions disagree within about 30 bars. Lines and labels can be shown separately for bottom and top divergences. The fractal period is adjustable. Pivots confirm only after the fractal length, so marks appear late.

Details

Published by

Ahmed1926 on GitHub

Code credit

TFlab, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Divergence, SMC / ICT / price action

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Second SymbolsymbolXAUUSDSym
Divergence Fractal Periodsint2n
Show SMT Divergence Line from the Bottom.booltrueBull_Line
Show SMT Divergence Label from the Bottom.booltrueBull_Label
Show SMT Divergence Line from the Top.booltrueBear_Line
Show SMT Divergence Label from the Top.booltrueBear_Label
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

SMC HTF Confluence

by skipp-dev
1 stars

This indicator plots HTF SMC confluence signals in a separate pane. It visualizes ATR regime states from compression through expansion and exhaustion using custom colors. Squeeze markers indicate on or released states while reversal context displays scores for

Indicator v6 SMC / ICT / price actionVolatility & bands
Updated 3 days ago · None stated GitHub repository of SMC HTF Confluence

Bandz HTF

by samuelharting
18 stars

Bandz HTF projects higher-timeframe candle structures, ranges, and key levels directly onto the main price chart. It visualizes multiple configurable timeframe lanes from intraday to weekly alongside primary and macro range levels, including 25%, 50%, and 75%

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 weeks ago · MPL-2.0 GitHub repository of Bandz HTF

Nexural QWAP

by JasonTeixeira
9 stars

Nexural QWAP calculates a volume-weighted average price combined with a cumulative volume delta order flow engine directly on the main price chart. It analyzes market structure by detecting volume absorption, liquidity sweeps, price-CVD divergence, stacked imb

Indicator v6 SMC / ICT / price actionVolume
Updated 13 days ago · Custom licence GitHub repository of Nexural QWAP

Larper Suite

by DeolinNaidoo
8 stars

Larper Suite is an overlay indicator for ICT and quarterly-theory analysis. It plots true session, daily, weekly, monthly, and yearly opens plus prior and current high-low liquidity levels. It tracks multi-asset SMT, swing divergence, fair-value-gap fills, and

Indicator v6 SMC / ICT / price actionDivergence Repaints
Updated 3 months ago · GPL-3.0 GitHub repository of Larper Suite
6 stars

Apex Protocol v3.0 - The SMC Engine is an overlay indicator designed for Smart Money Concepts (SMC) trading strategies. It detects market structure shifts (MSS), breaks of structure (BOS), M5 Fair Value Gaps (FVG), Order Blocks (OB), and Asian session ranges.

Indicator v5 SMC / ICT / price actionSupport & resistance Repaints
Updated 7 months ago · None stated GitHub repository of Apex Protocol v3.0 - The SMC Engine
2 stars

MTF Divergence Scanner detects regular and hidden divergences in RSI or MACD oscillators across multiple timeframes. It scans up to three timeframes simultaneously using request.security with confirmed-bar logic to identify reversal or continuation signals. Th

Indicator v6 Oscillators & momentumDivergence Repaints
Updated 3 months ago · MPL-2.0 GitHub repository of MTF Divergence Scanner

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers