Indicator · Pine Script v6 · On the chart

FVG Zones with Signals

by alvinng214· code credited to Uncle_the_shooter

The FVG Zones with Signals indicator detects Fair Value Gaps on the price chart by comparing high-low ranges against average candle body size over a user-defined length.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code218
Settings17inputs
LicenceNone statedfile: MPL-2.0
Last update2 months ago5 Aug 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

218 lines of Pine Script v6 from S1_Silver_Bullet/FVG Zones with Signals.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

FVG Zones with Signals.txt
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Uncle_the_shooter

//@version=6
indicator('FVG Zones with Signals', overlay = true, max_boxes_count = 500)

// General Settings
length = input.int(20, 'Candle Size Period', minval = 1, group = 'FVG Size Filter')
fvgSizeMultiplier = input.float(1, 'FVG Size Multiplier', minval = 0.1, step = 0.1, group = 'FVG Size Filter')
transpPct = input.int(80, 'Transparency (0 = opaque, 100 = invisible)', minval = 0, maxval = 100, group = 'Box Style')
midLineTranspPct = input.int(50, 'Middle Line Transparency (0 = opaque, 100 = invisible)', minval = 0, maxval = 100, group = 'Box Style')

// Box Colors and Styles
bullBoxBorderColor = input.color(color.rgb(22, 193, 67), title = 'Bull Box Border Color', group = 'Bull Box Style')
bullBoxBgColor = input.color(color.green, title = 'Bull Box Gradient Color', group = 'Bull Box Style')
bullBoxBorderWidth = input.int(1, minval = 1, maxval = 5, title = 'Bull Box Border Width', group = 'Bull Box Style')
bullBoxBorderStyle = input.string('Solid', title = 'Bull Box Border Style', options = ['Solid', 'Dashed', 'Dotted'], group = 'Bull Box Style')
bearBoxBorderColor = input.color(color.rgb(229, 11, 11), title = 'Bear Box Border Color', group = 'Bear Box Style')
bearBoxBgColor = input.color(color.red, title = 'Bear Box Gradient Color', group = 'Bear Box Style')
bearBoxBorderWidth = input.int(1, minval = 1, maxval = 5, title = 'Bear Box Border Width', group = 'Bear Box Style')
bearBoxBorderStyle = input.string('Solid', title = 'Bear Box Border Style', options = ['Solid', 'Dashed', 'Dotted'], group = 'Bear Box Style')

// Signal Colors
breakUpSignalColor = input.color(color.green, title = 'Break Up Signal Color', group = 'Signal Style')
breakDownSignalColor = input.color(color.red, title = 'Break Down Signal Color', group = 'Signal Style')
exitUpSignalColor = input.color(color.green, title = 'Exit Up Signal Color', group = 'Signal Style')
exitDownSignalColor = input.color(color.red, title = 'Exit Down Signal Color', group = 'Signal Style')

// Signal Settings
signalType = input.string('Break', title = 'Signal Type', options = ['Break', 'Exit', 'Both'], group = 'Signal Settings')
showBreakSignals = signalType == 'Break' or signalType == 'Both'
showExitSignals = signalType == 'Exit' or signalType == 'Both'

// Line Style Mapping
getLineStyle(style) =>
    style == 'Solid' ? line.style_solid : style == 'Dashed' ? line.style_dashed : line.style_dotted

// Arrays to Store FVG Data
var array<float> fvgTops = array.new_float(0)
var array<float> fvgBots = array.new_float(0)
var array<int> fvgBarIndices = array.new_int(0)
var array<bool> isBull = array.new_bool(0)
var array<bool> activeFvgs = array.new_bool(0)
var array<box> boxes = array.new_box(0)
var array<bool> insideFvg = array.new_bool(0)
var array<line> midLines = array.new_line(0) // Array for 50% FVG lines

// Calculate Average Candle Body Size
avgBody = ta.sma(math.abs(close[1] - open[1]), length)

// Initialize Historical FVGs
var bool initialized = false
if not initialized
    for m = 2 to 500 by 1
        historicalBullFVG = high[m + 2] < low[m]
        if historicalBullFVG
            historicalTop = math.max(low[m], high[m + 2])
            historicalBot = math.min(low[m], high[m + 2])
            historicalFvgSize = historicalTop - historicalBot
            historicalAvgBody = ta.sma(math.abs(close[1] - open[1]), length)[m]
            if historicalFvgSize >= historicalAvgBody * fvgSizeMultiplier
                array.push(fvgTops, historicalTop)
                array.push(fvgBots, historicalBot)
                array.push(fvgBarIndices, bar_index - m)
                array.push(isBull, true)
                array.push(activeFvgs, true)
                array.push(boxes, na)
                array.push(insideFvg, false)
                array.push(midLines, na) // Initialize line
        historicalBearFVG = low[m + 2] > high[m]
        if historicalBearFVG
            historicalTop = math.max(low[m + 2], high[m])
            historicalBot = math.min(low[m + 2], high[m])
            historicalFvgSize = historicalTop - historicalBot
            historicalAvgBody = ta.sma(math.abs(close[1] - open[1]), length)[m]
            if historicalFvgSize >= historicalAvgBody * fvgSizeMultiplier
                array.push(fvgTops, historicalTop)
                array.push(fvgBots, historicalBot)
                array.push(fvgBarIndices, bar_index - m)
                array.push(isBull, false)
                array.push(activeFvgs, true)
                array.push(boxes, na)
                array.push(insideFvg, false)
                array.push(midLines, na) // Initialize line
    initialized := true
    initialized

// FVG Conditions
bullFVG = high[2] < low
bearFVG = low[2] > high

// Clear Inactive or Old FVGs
if array.size(fvgTops) > 0
    for i = array.size(fvgTops) - 1 to 0 by 1
        if not array.get(activeFvgs, i) or bar_index - array.get(fvgBarIndices, i) > 500
            if not na(array.get(boxes, i))
                box.delete(array.get(boxes, i))
            if not na(array.get(midLines, i)) // Remove line
                line.delete(array.get(midLines, i))
            array.remove(fvgTops, i)
            array.remove(fvgBots, i)
            array.remove(fvgBarIndices, i)
            array.remove(isBull, i)
            array.remove(activeFvgs, i)
            array.remove(boxes, i)
            array.remove(insideFvg, i)
            array.remove(midLines, i) // Remove from line array

// Add New Bull FVG
if bullFVG
    topP = math.max(low, high[2])
    botP = math.min(low, high[2])
    fvgSize = topP - botP
    if fvgSize >= avgBody * fvgSizeMultiplier
        array.push(fvgTops, topP)
        array.push(fvgBots, botP)
        array.push(fvgBarIndices, bar_index)
        array.push(isBull, true)
        array.push(activeFvgs, true)
        array.push(boxes, na)
        array.push(insideFvg, false)
        array.push(midLines, na) // Add line to array

// Add New Bear FVG
if bearFVG
    topP = math.max(low[2], high)
    botP = math.min(low[2], high)
    fvgSize = topP - botP
    if fvgSize >= avgBody * fvgSizeMultiplier
        array.push(fvgTops, topP)
        array.push(fvgBots, botP)
        array.push(fvgBarIndices, bar_index)
        array.push(isBull, false)
        array.push(activeFvgs, true)
        array.push(boxes, na)
        array.push(insideFvg, false)
        array.push(midLines, na) // Add line to array

// Update All Active FVG Boxes
if array.size(fvgTops) > 0
    for i = 0 to array.size(fvgTops) - 1 by 1
        if array.get(activeFvgs, i) and bar_index - array.get(fvgBarIndices, i) <= 500
            if not na(array.get(boxes, i))
                box.delete(array.get(boxes, i))
            borderColor = array.get(isBull, i) ? bullBoxBorderColor : bearBoxBorderColor
            bgColor = array.get(isBull, i) ? color.new(bullBoxBgColor, transpPct) : color.new(bearBoxBgColor, transpPct)
            borderWidth = array.get(isBull, i) ? bullBoxBorderWidth : bearBoxBorderWidth
            borderStyle = array.get(isBull, i) ? getLineStyle(bullBoxBorderStyle) : getLineStyle(bearBoxBorderStyle)
            topPrice = array.get(fvgTops, i)
            botPrice = array.get(fvgBots, i)
            rightBar = math.min(bar_index, array.get(fvgBarIndices, i) + 500)
            newBox = box.new(left = array.get(fvgBarIndices, i), top = topPrice, right = rightBar, bottom = botPrice, border_color = borderColor, border_width = borderWidth, border_style = borderStyle, bgcolor = bgColor, xloc = xloc.bar_index, extend = extend.none)
            array.set(boxes, i, newBox)
            // Draw Line at 50% FVG Level
            midPrice = (topPrice + botPrice) / 2
            if not na(array.get(midLines, i))
                line.delete(array.get(midLines, i))
            newLine = line.new(x1 = array.get(fvgBarIndices, i), y1 = midPrice, x2 = rightBar, y2 = midPrice, xloc = xloc.bar_index, color = color.new(array.get(isBull, i) ? bullBoxBorderColor : bearBoxBorderColor, midLineTranspPct), style = line.style_dashed)
            array.set(midLines, i, newLine)

// Check for Breakouts and Exits from FVG and Set Signals
var bool buySignal = false
var bool sellSignal = false
var bool exitBuySignal = false
var bool exitSellSignal = false
buySignal := false
sellSignal := false
exitBuySignal := false
exitSellSignal := false
if array.size(fvgTops) > 0
    for i = 0 to array.size(fvgTops) - 1 by 1
        if array.get(activeFvgs, i)
            topPrice = array.get(fvgTops, i)
            botPrice = array.get(fvgBots, i)
            wasInside = array.get(insideFvg, i)
            isInside = close >= botPrice and close <= topPrice
            array.set(insideFvg, i, isInside)
            // Breakout Signals
            if array.get(isBull, i) and close < botPrice
                array.set(activeFvgs, i, false)
                if not na(array.get(boxes, i))
                    box.delete(array.get(boxes, i))
                if not na(array.get(midLines, i)) // Remove line on breakout
                    line.delete(array.get(midLines, i))
                sellSignal := true
                sellSignal
            else if not array.get(isBull, i) and close > topPrice
                array.set(activeFvgs, i, false)
                if not na(array.get(boxes, i))
                    box.delete(array.get(boxes, i))
                if not na(array.get(midLines, i)) // Remove line on breakout
                    line.delete(array.get(midLines, i))
                buySignal := true
                buySignal
            // Exit Signals
            else if wasInside and not isInside
                if array.get(isBull, i) and close > topPrice
                    exitBuySignal := true
                    exitBuySignal
                else if not array.get(isBull, i) and close < botPrice
                    exitSellSignal := true
                    exitSellSignal

// Draw Signals
plotshape(showBreakSignals and buySignal, title = 'Break Up Signal', location = location.belowbar, style = shape.triangleup, color = breakUpSignalColor, size = size.tiny)
plotshape(showBreakSignals and sellSignal, title = 'Break Down Signal', location = location.abovebar, style = shape.triangledown, color = breakDownSignalColor, size = size.tiny)
plotshape(showExitSignals and exitBuySignal, title = 'Exit Up Signal', location = location.belowbar, style = shape.circle, color = exitUpSignalColor, size = size.tiny)
plotshape(showExitSignals and exitSellSignal, title = 'Exit Down Signal', location = location.abovebar, style = shape.circle, color = exitDownSignalColor, size = size.tiny)

// Alerts for Signals
if showBreakSignals and buySignal
    alert('FVG Break Up Signal: Price broke above bearish FVG zone at ' + str.tostring(close), alert.freq_once_per_bar_close)
if showBreakSignals and sellSignal
    alert('FVG Break Down Signal: Price broke below bullish FVG zone at ' + str.tostring(close), alert.freq_once_per_bar_close)
if showExitSignals and exitBuySignal
    alert('FVG Exit Up Signal: Price exited above bullish FVG zone at ' + str.tostring(close), alert.freq_once_per_bar_close)
if showExitSignals and exitSellSignal
    alert('FVG Exit Down Signal: Price exited below bearish FVG zone at ' + str.tostring(close), alert.freq_once_per_bar_close)

Overview

FVG Zones with Signals plots bull and bear FVG zones as semi-transparent colored boxes with border styles and midline references. Signals appear as arrows for breaks and exits based on signal type selection. Inputs adjust FVG size threshold, box colors and transparency, and signal appearance. The script draws boxes and signals directly on the chart.

Details

Published by

alvinng214 on GitHub

Code credit

Uncle_the_shooter, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

SMC / ICT / price action, Support & resistance

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
Candle Size Periodint20length
FVG Size Multiplierfloat1fvgSizeMultiplier
Transparency (0 = opaque, 100 = invisible)int80transpPct
Middle Line Transparency (0 = opaque, 100 = invisible)int50midLineTranspPct
Bull Box Border Colorcolorcolor.rgb(22, 193, 67)bullBoxBorderColor
Bull Box Gradient Colorcolorcolor.greenbullBoxBgColor
Bull Box Border Widthint1bullBoxBorderWidth
Bull Box Border StylestringSolidbullBoxBorderStyle
Bear Box Border Colorcolorcolor.rgb(229, 11, 11)bearBoxBorderColor
Bear Box Gradient Colorcolorcolor.redbearBoxBgColor
Bear Box Border Widthint1bearBoxBorderWidth
Bear Box Border StylestringSolidbearBoxBorderStyle
Show all 17 settings
SettingTypeDefaultVariable
Break Up Signal Colorcolorcolor.greenbreakUpSignalColor
Break Down Signal Colorcolorcolor.redbreakDownSignalColor
Exit Up Signal Colorcolorcolor.greenexitUpSignalColor
Exit Down Signal Colorcolorcolor.redexitDownSignalColor
Signal TypestringBreaksignalType
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