Indicator · Pine Script v6 · On the chart

TwoSweepsModel

by riegodavid-git· code credited to psyplo

An overlay indicator that looks for swing failure patterns, where price pokes beyond an earlier pivot and closes back, on the 30-minute and 1-hour timeframes, and combines them with fair value gap and inverse gap detection on the chart timeframe, intended for five-minute charts.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code162
Settings11inputs
LicenceNone statedfile: MPL-2.0
Last update4 months ago25 Jun 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

162 lines of Pine Script v6 from pinescript/two_sweeps_model.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

two_sweeps_model.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © psyplo

//@version=6
indicator(title = "TwoSweepsModel", shorttitle = "TSM", overlay = true, max_bars_back = 2000)

//timeframe flags
is5minChart = timeframe.isintraday and timeframe.multiplier == 5
//is1minChart = timeframe.isintraday and timeframe.multiplier == 1

// SFP DETECTION
sfp_lookback = 1999

//to detect pivot highs and lows
pivot_length = input.int(defval = 3, title = "Pivot Length", group = "SFP Settings")
pivot_high = ta.pivothigh(pivot_length, 0)
pivot_low = ta.pivotlow(pivot_length, 0)

//getting candle data
f_get_candle(_index) => [open[_index], high[_index], low[_index], close[_index], bar_index[_index]]

f_sfp() =>
    if not barstate.isconfirmed
        [false, na, na, false, na, na]
    [co, ch, cl, cc, ci] = f_get_candle(0)

//hsfp logic
    hc1 = not na(pivot_high) //is current candle pivot high?
    hc2 = false
    hx = 0
    hy = 0.0
    max_price = high[1]

    for i = 1 to sfp_lookback
        [o, h, l, c, bi] = f_get_candle(i)
        if h >= ch
            break
        if h < ch and h > math.max(co, cc) and not na(pivot_high[i]) and h > max_price
            hc2 := true
            hx := bar_index[i]
            hy := h
        if h > max_price
            max_price := h
    hsfp = hc1 and hc2

//lsfp logic
    lc1 = not na(pivot_low)
    min_price = low[1]
    lc2 = false
    lx = 0
    ly = 0.0
    for i = 2 to sfp_lookback
        [o, h, l, c, bi] = f_get_candle(i)
        if l < cl
            break
        if cl < l and math.min(co, cc) > l and not na(pivot_low[i]) and l < min_price
            lc2 := true
            lx := bar_index[i]
            ly := l
        if l < min_price
            min_price := l
    lsfp = lc1 and lc2

    [hsfp, hx, hy, lsfp, lx, ly]

//control logic
f_sfpcontrol(_tf) => request.security(syminfo.tickerid, _tf, f_sfp())

[hsfp1h, hx1h, hy1h, lsfp1h, lx1h, ly1h] = f_sfpcontrol("60")
[hsfp30m, hx30m, hy30m, lsfp30m, lx30m, ly30m] = f_sfpcontrol("30")

//bgcolor(is5minChart and (hsfp1h or hsfp30m) ? color.new(color.red, 85) : na, offset = 1)
//bgcolor(is5minChart and (lsfp1h or lsfp30m) ? color.new(color.green, 85) : na, offset = 1)

// FVG DETECTION
//user inputs
ext = input.int(defval = 0, title = "Extend FVGs", group = "FVG Settings")
upcolor = input.color(defval = #000000, title = "Bullish color", group = "FVG Style")
downcolor = input.color(defval = #000000, title = "Bearish color", group = "FVG Style")
inp1 = input.bool(false, "Volume Filter", group = "FVG Filters")
inp2 = input.bool(false, "ATR Filter", group = "FVG Filters")
inp3 = input.bool(false, "Trend Filter", group = "FVG Filters")

textSize = input.string("large", title="IFVG Detection Text Size", options=["tiny", "small", "normal", "large", "huge"], group="IFVG Settings")
textBuy = input.string("O", title="Bullish IFVG", group="IFVG Settings")
textSell = input.string("X", title="Bearish IFVG", group="IFVG Settings")
textOffset = input.int(40, title="Vertical Offset (ticks)", group="IFVG Settings")

var float recentBullFVG_Low = na
var float recentBearFVG_High = na
var int bullFVG_start = na
var int bearFVG_start = na
var bool bullUsed = false
var bool bearUsed = false

f_fvg() =>
    volfilt = inp1 ? volume[1] > ta.sma(volume, 9)*1.5 : true
    atr = ta.atr(20) / 1.5
    atrfilt = inp2 ? ((low - high[2] > atr) or (low[2] - high > atr)) : true
    loc = ta.sma(close, 54)
    loc2 = loc > loc[1]
    locfiltb = inp3 ? loc2 : true
    locfilts = inp3 ? not loc2 : true

    bfvg = low > high[2] and volfilt and atrfilt and locfiltb
    sfvg = high < low[2] and volfilt and atrfilt and locfilts

    [bfvg, sfvg]

//control logic
f_fvgcontrol(_tf) => request.security(syminfo.tickerid, _tf, f_fvg())
//5m
[bfvg5m, sfvg5m] = f_fvgcontrol("5")
//1m
//[bfvg1m, sfvg1m] = f_fvgcontrol("1")

//plotting FVGs
if barstate.isconfirmed and bfvg5m and is5minChart
    recentBullFVG_Low := high[2]
    bullFVG_start := bar_index
    box.new(left = bar_index-2, top = low, right = bar_index + ext, bottom = high[2], border_color = color.new(color.gray, 100), bgcolor = color.new(upcolor, 90))
    bullUsed := false

if barstate.isconfirmed and sfvg5m and is5minChart
    recentBearFVG_High := low[2]
    bearFVG_start := bar_index
    box.new(left = bar_index-2, top = high, right = bar_index + ext, bottom = low[2], border_color = color.new(color.gray, 100), bgcolor = color.new(downcolor, 90))
    bearUsed := false

//if barstate.isconfirmed and bfvg1m and is1minChart
    //recentBullFVG_Low := high[2]
    //bullFVG_start := bar_index
    //box.new(left = bar_index-2, top = low, right = bar_index + ext, bottom = high[2], border_color = color.new(color.gray, 100), bgcolor = color.new(upcolor, 90))
    //bullUsed := false

//if barstate.isconfirmed and sfvg1m and is1minChart
    //recentBearFVG_High := low[2]
    //bearFVG_start := bar_index
    //box.new(left = bar_index-2, top = high, right = bar_index + ext, bottom = low[2], border_color = color.new(color.gray, 100), bgcolor = color.new(downcolor, 90))
    //bearUsed := false

//5min IFVG confirmation logic
hsfpTrigger = hsfp1h or hsfp30m
lsfpTrigger = lsfp1h or lsfp30m

candleUnderBullFVG = barstate.isconfirmed and (hsfpTrigger or (hsfpTrigger[1] and hsfpTrigger)) and not na(recentBullFVG_Low) and close < recentBullFVG_Low and not bullUsed
candleOverBearFVG = barstate.isconfirmed and (lsfpTrigger or (lsfpTrigger[1] and lsfpTrigger)) and not na(recentBearFVG_High) and close > recentBearFVG_High and not bearUsed

if candleUnderBullFVG and is5minChart
    bullUsed := true
    var label sellText = na
    alert("Sell Signal", alert.freq_once_per_bar_close)
    sellText := label.new(bar_index, high + (textOffset * syminfo.mintick), textSell, style=label.style_none, textcolor=color.rgb(255, 255, 255, 40), size=textSize)
if candleOverBearFVG and is5minChart
    bearUsed := true 
    var label buyText = na
    alert("Buy Signal", alert.freq_once_per_bar_close)
    buyText := label.new(bar_index, low - (1.5*(textOffset * syminfo.mintick)), textBuy, style=label.style_none, textcolor=color.rgb(255, 255, 255, 40), size=textSize)


//plot (recentBearFVG_High, color = color.green, style = plot.style_linebr)
//plot (recentBullFVG_Low,  color = color.red, style = plot.style_linebr)

Overview

Inverse gaps are marked with an O for bullish or an X for bearish, with adjustable text size and offset. Optional volume, ATR and trend filters apply to gaps. Higher timeframe data is requested inside the script, so marks may not match live behaviour.

Details

Published by

riegodavid-git on GitHub

Code credit

psyplo, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

M1-M5

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
Pivot Lengthint3pivot_length
Extend FVGsint0ext
Bullish colorcolor#000000upcolor
Bearish colorcolor#000000downcolor
Volume Filterboolfalseinp1
ATR Filterboolfalseinp2
Trend Filterboolfalseinp3
IFVG Detection Text SizestringlargetextSize
Bullish IFVGstringOtextBuy
Bearish IFVGstringXtextSell
Vertical Offset (ticks)int40textOffset
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

ICT Equal Highs and Lows

by ArunKBhaskar
575 stars

This overlay indicator finds pivot highs and lows on the price chart and compares the last two highs and the last two lows. When the percentage difference between a pair is below the Equal HL threshold, it treats them as equal levels and draws a box. Left and

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows

DE-tracker

by Allen1212
303 stars

This indicator plots labels on the TradingView price chart to mark ARK Invest's buy and sell trades for the DE stock. Buy transactions appear in green with X1 or X2 multipliers showing the number of ARK ETFs involved on the same day; sells appear in red. The m

Indicator v4 Support & resistanceSMC / ICT / price action
Updated 2 years ago · None stated GitHub repository of DE-tracker

This Pine Script indicator plots a ZigZag on the price chart. It identifies reversal points when price moves more than a set percentage from the last pivot. The script calculates forecasts using zigzag data and labels detected geometric patterns including harm

Indicator v4 TrendSupport & resistance

Golden Bullet Strategy

by TradersPost
228 stars

The Golden Bullet Strategy is an overlay signal indicator based on Smart Money Concepts and time-based liquidity models. It identifies liquidity sweeps of a designated reference session range during a specified hunt window. It then confirms Market Structure Sh

Indicator v6 SMC / ICT / price actionSessions & time
Updated 3 months ago · None stated GitHub repository of Golden Bullet Strategy

Open Source Fractal

by cantolab
183 stars

This indicator implements the Fractal Model concept to plot market structure shifts, liquidity sweeps, and Change in State of Delivery (CISD) levels. It overlays custom higher-timeframe candle previews, open prices, and time markers directly on the price chart

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 months ago · MIT GitHub repository of Open Source Fractal

Swing Failure Signals

by Ganador1
154 stars

This indicator calculates pivot highs and pivot lows to detect liquidity sweeps and Swing Failure Patterns. It identifies when price breaks past recent key swing highs or lows within a configurable historical window, then looks for a quick reversal or change i

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 months ago · Apache-2.0 GitHub repository of Swing Failure Signals

More SMC / ICT scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers