Indicator · Pine Script v6 · On the chart

FVG [atrader934]

by Ahmedhub934

The script identifies bullish and bearish Fair Value Gaps (FVGs) on the current or specified timeframe.

View on GitHub

Repaints

GitHub stars2on the repository
Pine versionv6current
Lines of code99
Settings10inputs
LicenceMIT
Last update11 months ago9 Nov 2025

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

99 lines of Pine Script v6 from FVG.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

FVG.pine
//@version=6
indicator('FVG [atrader934]', shorttitle="FVG", overlay=true, max_bars_back=5000, max_boxes_count=500, max_labels_count=500)
// ████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
// ██                     NOTE:                                                                                                          ██
// ██  This script is provided for educational purposes only. It is not financial advice.                                                ██
// ██  Trading involves significant risk. The author is not responsible for any financial losses incurred using this script.             ██
// ██  Always conduct your own research and backtest thoroughly before trading live.                                                     ██
// ██  There will be more updates coming.                                                                                                ██
// ██                                                                                                                                    ██
// ████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
//atrader934
// === GROUPS ===
grpLogic    = "FVG Logic"
grpStyle    = "Visual Style"
grpCleanup  = "Box Removal"

// === INPUTS ===
fvgTimeframe   = input.timeframe('', "FVG Timeframe (empty=chart)", group=grpLogic, tooltip="Timeframe for FVG detection.")
boxExtendBars  = input.int(15, "Extend FVG Boxes (bars)", minval=1, maxval=100, group=grpStyle, tooltip="How far to extend FVG boxes to the right.")

bullFillColor  = input.color(color.new(#00ffe0, 75), "Bullish FVG Fill", group=grpStyle)
bullEdgeColor  = input.color(color.new(#00d1ab, 0), "Bullish FVG Border", group=grpStyle)
bearFillColor  = input.color(color.new(#ff4e6a, 80), "Bearish FVG Fill", group=grpStyle)
bearEdgeColor  = input.color(color.new(#ff2042, 10), "Bearish FVG Border", group=grpStyle)
labelTextSize  = input.string("small", "FVG Label Size", options=["tiny","small","normal","large"], group=grpStyle)
labelBgColor   = input.color(color.new(color.black, 80), "FVG Label Bg", group=grpStyle)
labelGlowColor = input.color(color.new(#222930, 70), "FVG Label Glow", group=grpStyle)
autoDelete     = input.bool(true, "Auto-Delete Filled", group=grpCleanup, tooltip="Remove FVG when price fills/mitigates the gap.")

// === MTF DATA ===
srcHigh = fvgTimeframe == '' ? high : request.security(syminfo.tickerid, fvgTimeframe, high, lookahead=barmerge.lookahead_on)
srcLow  = fvgTimeframe == '' ? low  : request.security(syminfo.tickerid, fvgTimeframe, low, lookahead=barmerge.lookahead_on)

// === ARRAYS ===
var box[] bullFvgBoxes    = array.new<box>()
var label[] bullFvgLabels = array.new<label>()
var box[] bearFvgBoxes    = array.new<box>()
var label[] bearFvgLabels = array.new<label>()

// === ACCURATE FVG DETECTION & VISUALS ===
bullFvg = srcLow > srcHigh[2]
bearFvg = srcHigh < srcLow[2]

if bullFvg and not bullFvg[1]
    left = bar_index
    right = bar_index + boxExtendBars
    top = srcLow
    bottom = srcHigh[2]
    newBox = box.new(left, top, right, bottom, bgcolor=bullFillColor, border_color=bullEdgeColor, border_width=2, xloc=xloc.bar_index, extend=extend.none)
    centerY = (top + bottom)/2
    centerX = math.round((left + right)/2)
    glowLabel = label.new(centerX, centerY, "FVG", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_center, color=labelGlowColor, textcolor=color.new(#00ffe0, 60), size=labelTextSize)
    mainLabel = label.new(centerX, centerY, "FVG", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_center, color=labelBgColor, textcolor=bullEdgeColor, size=labelTextSize)
    array.unshift(bullFvgBoxes, newBox)
    array.unshift(bullFvgLabels, mainLabel)
    array.unshift(bullFvgLabels, glowLabel)

if bearFvg and not bearFvg[1]
    left = bar_index
    right = bar_index + boxExtendBars
    top = srcLow[2]
    bottom = srcHigh
    newBox = box.new(left, top, right, bottom, bgcolor=bearFillColor, border_color=bearEdgeColor, border_width=2, xloc=xloc.bar_index, extend=extend.none)
    centerY = (top + bottom)/2
    centerX = math.round((left + right)/2)
    glowLabel = label.new(centerX, centerY, "FVG", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_center, color=labelGlowColor, textcolor=color.new(#ff4e6a, 50), size=labelTextSize)
    mainLabel = label.new(centerX, centerY, "FVG", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_center, color=labelBgColor, textcolor=bearEdgeColor, size=labelTextSize)
    array.unshift(bearFvgBoxes, newBox)
    array.unshift(bearFvgLabels, mainLabel)
    array.unshift(bearFvgLabels, glowLabel)

// === BOX & LABEL DELETION LOGIC ===
if autoDelete
    if array.size(bullFvgBoxes) > 0
        for i = array.size(bullFvgBoxes) - 1 to 0
            boxRef = array.get(bullFvgBoxes, i)
            mainLabelRef = array.get(bullFvgLabels, i * 2)
            glowLabelRef = array.get(bullFvgLabels, i * 2 + 1)
            boxBottom = box.get_bottom(boxRef)
            if close < boxBottom
                box.delete(boxRef)
                label.delete(mainLabelRef)
                label.delete(glowLabelRef)
                array.remove(bullFvgBoxes, i)
                array.remove(bullFvgLabels, i * 2)
                array.remove(bullFvgLabels, i * 2)
    if array.size(bearFvgBoxes) > 0
        for i = array.size(bearFvgBoxes) - 1 to 0
            boxRef = array.get(bearFvgBoxes, i)
            mainLabelRef = array.get(bearFvgLabels, i * 2)
            glowLabelRef = array.get(bearFvgLabels, i * 2 + 1)
            boxTop = box.get_top(boxRef)
            if close > boxTop
                box.delete(boxRef)
                label.delete(mainLabelRef)
                label.delete(glowLabelRef)
                array.remove(bearFvgBoxes, i)
                array.remove(bearFvgLabels, i * 2)
                array.remove(bearFvgLabels, i * 2)

Overview

FVG [atrader934] plots auto-updating boxes and labels directly on the price chart to highlight detected gaps. Main settings control box extension in bars, fill and border colors for bullish and bearish FVGs, label size and colors, and auto-delete when gaps are filled. It uses multi-timeframe data with lookahead and maximum bar and label counts for performance.

Details

Published by

Ahmedhub934 on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

SMC / ICT / price action

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

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

SettingTypeDefaultVariable
FVG Timeframe (empty=chart)timeframefvgTimeframe
Extend FVG Boxes (bars)int15boxExtendBars
Bullish FVG Fillcolorcolor.new(#00ffe0, 75)bullFillColor
Bullish FVG Bordercolorcolor.new(#00d1ab, 0)bullEdgeColor
Bearish FVG Fillcolorcolor.new(#ff4e6a, 80)bearFillColor
Bearish FVG Bordercolorcolor.new(#ff2042, 10)bearEdgeColor
FVG Label SizestringsmalllabelTextSize
FVG Label Bgcolorcolor.new(color.black, 80)labelBgColor
FVG Label Glowcolorcolor.new(#222930, 70)labelGlowColor
Auto-Delete FilledbooltrueautoDelete
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

575 stars

The indicator plots ICT displacement candles on the price chart and can switch to retracement scanning. Displacement requires a move larger than a set share of the 14-bar average high-low range, lasting at least a chosen number of bars, with optional close, pr

Indicator v6 SMC / ICT / price actionCandlestick patterns
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Displacement Candles Indicator

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

Fair Value Gaps - Basic

by TradersPost
218 stars

This indicator detects bullish and bearish fair value gaps on the price chart and draws a translucent box for each gap. A bullish gap needs the high two bars back below the current low and a bullish middle candle; a bearish gap uses the opposite gap and a bear

Indicator v6 SMC / ICT / price action
Updated 3 months ago · None stated GitHub repository of Fair Value Gaps - Basic

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