Indicator · Pine Script v6 · On the chart

LTF FractalsSweep + IFVG

by riegodavid-git

An overlay indicator for lower timeframes that tracks the latest fractal highs and lows and draws a dotted line when price sweeps one, with an alert on bar close.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code142
Settings9inputs
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

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

fsi.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=6
indicator("LTF (FractalsSweep + IFVG)", overlay=true, shorttitle="FSI")

// Inputs
leftBars  = input.int(2, "Left Bars", minval=1)
rightBars = input.int(2, "Right Bars", minval=1)
lookback  = input.int(5, "Fractals to Track", minval=1, tooltip="How many past fractals to check for sweeps")

// Detect fractals
fractHigh = ta.pivothigh(high, leftBars, rightBars)
fractLow  = ta.pivotlow(low, leftBars, rightBars)

// Arrays to store last X fractals
var highsArr   = array.new_float()
var highsIdx   = array.new_int()
var highsSwept = array.new_bool()
var lowsArr    = array.new_float()
var lowsIdx    = array.new_int()
var lowsSwept  = array.new_bool()

// When new fractal appears, push it into arrays
if not na(fractHigh)
    array.unshift(highsArr, fractHigh)
    array.unshift(highsIdx, bar_index - rightBars)
    array.unshift(highsSwept, false)
    if array.size(highsArr) > lookback
        array.pop(highsArr)
        array.pop(highsIdx)
        array.pop(highsSwept)

if not na(fractLow)
    array.unshift(lowsArr, fractLow)
    array.unshift(lowsIdx, bar_index - rightBars)
    array.unshift(lowsSwept, false)
    if array.size(lowsArr) > lookback
        array.pop(lowsArr)
        array.pop(lowsIdx)
        array.pop(lowsSwept)

// Check sweeps only if arrays are non-empty
if array.size(highsArr) > 0
    for i = 0 to array.size(highsArr) - 1
        val   = array.get(highsArr, i)
        idx   = array.get(highsIdx, i)
        swept = array.get(highsSwept, i)
        if not swept and high > val
            line.new(x1=idx, y1=val, x2=bar_index, y2=val,
                     color=color.rgb(0, 0, 0), style=line.style_dotted, width=1, extend=extend.none)
            alert("Sweep Detected", alert.freq_once_per_bar_close)
            array.set(highsSwept, i, true)  // mark as swept

if array.size(lowsArr) > 0
    for i = 0 to array.size(lowsArr) - 1
        val   = array.get(lowsArr, i)
        idx   = array.get(lowsIdx, i)
        swept = array.get(lowsSwept, i)
        if not swept and low < val
            line.new(x1=idx, y1=val, x2=bar_index, y2=val,
                     color=color.rgb(0, 0, 0), style=line.style_dotted, width=1, extend=extend.none)
            alert("Sweep Detected", alert.freq_once_per_bar_close)
            array.set(lowsSwept, i, true)  // mark as swept

// 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")

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())
//1m
[bfvg1m, sfvg1m] = f_fvgcontrol("1")

if barstate.isconfirmed and bfvg1m
    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
    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

candleUnderBullFVG = barstate.isconfirmed and not na(recentBullFVG_Low) and close < recentBullFVG_Low and not bullUsed
candleOverBearFVG = barstate.isconfirmed and not na(recentBearFVG_High) and close > recentBearFVG_High and not bearUsed

if candleUnderBullFVG and barstate.isconfirmed
    bullUsed := true
    alert("Sell Signal", alert.freq_once_per_bar_close)
    // Line under the Bullish FVG, ending at confirmation bar
    line.new(
         x1 = bullFVG_start, 
         y1 = recentBullFVG_Low, 
         x2 = bar_index, 
         y2 = recentBullFVG_Low, 
         extend = extend.none, 
         color = color.red, 
         style = line.style_solid, 
         width = 2
     )

if candleOverBearFVG and barstate.isconfirmed
    bearUsed := true 
    alert("Buy Signal", alert.freq_once_per_bar_close)
    // Line at the Bearish FVG high, ending at confirmation bar
    line.new(
         x1 = bearFVG_start, 
         y1 = recentBearFVG_High, 
         x2 = bar_index, 
         y2 = recentBearFVG_High, 
         extend = extend.none, 
         color = color.green, 
         style = line.style_solid, 
         width = 2
     )

Overview

LTF FractalsSweep + IFVG also detects fair value gaps, with optional filters for volume, ATR gap size and short-term trend, and settings for gap extension and colours. Fractal bar counts and the number of fractals tracked are adjustable. Fractals are confirmed only after the right-side bars, so sweep levels appear with a delay.

Details

Published by

riegodavid-git on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

SMC / ICT / price action, Support & resistance

Markets

Forex

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
Left Barsint2leftBars
Right Barsint2rightBars
Fractals to Trackint5lookback
Extend FVGsint0ext
Bullish colorcolor#000000upcolor
Bearish colorcolor#000000downcolor
Volume Filterboolfalseinp1
ATR Filterboolfalseinp2
Trend Filterboolfalseinp3
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
218 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 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