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.
1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Left Bars
int
2
leftBars
Right Bars
int
2
rightBars
Fractals to Track
int
5
lookback
Extend FVGs
int
0
ext
Bullish color
color
#000000
upcolor
Bearish color
color
#000000
downcolor
Volume Filter
bool
false
inp1
ATR Filter
bool
false
inp2
Trend Filter
bool
false
inp3
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.
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
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
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
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
Indicatorv6SMC / ICT / price actionSessions & time
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
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