Indicator · Pine Script v5 · On the chart

Inverse FVG with Rejections [TFO]

by theonetrade· code credited to tradeforopp

This indicator detects and visualizes Regular Fair Value Gaps (FVGs) and Inverse Fair Value Gaps (IFVGs) alongside price rejections occurring within these imbalance zones.

View on GitHub

GitHub stars34on the repository
Pine versionv5runs as is
Lines of code199
Settings16inputs
LicenceMIT
Last update2 weeks ago8 Nov 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

199 lines of Pine Script v5 from assets/indicator/bit-exact/inverse_fvg_with_rejections_tfo_arQP5Q2f.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

inverse_fvg_with_rejections_tfo_arQP5Q2f.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tradeforopp

//@version=5
indicator("Inverse FVG with Rejections [TFO]", "Inverse FVG [TFO]", true)

// -------------------------------------------------- Inputs --------------------------------------------------
var g_SET = "Settings"
show_rfvg = input.bool(true, "Show Regular FVG", inline = "RFVG", group = g_SET)
show_ifvg = input.bool(true, "Show Inverse FVG", inline = "IFVG", group = g_SET)
extend_right = input.bool(true, "Extend Boxes", group = g_SET)

rfvg_color = input.color(color.new(#2962ff, 60), "", inline = "RFVG", group = g_SET)
ifvg_color = input.color(color.new(#f23645, 60), "", inline = "IFVG", group = g_SET)

tf = input.timeframe("", "Timeframe", group = g_SET)
disp_x = input.int(3, "Displacement", 1, 10, tooltip = "Larger Displacement will require larger FVGs", group = g_SET)
disp_limit = input.int(10, "Display Limit", 1, 50, tooltip = "The maximum amount of FVGs and IFVGs to display", group = g_SET)

session = input.session("0000-0000", "Session", tooltip = "FVGs will only be saved if they are created within this time period", group = g_SET)

var g_RJ = "Rejections"
ps = input.int(1, "Rejection Strength", tooltip = "Larger values will require larger fractals/swing pivots to justify as rejections", group = g_RJ) 

show_rrj = input.bool(false, "Regular FVG", inline = "RRJ", tooltip = "Show rejections made within regular FVGs", group = g_RJ)
show_irj = input.bool(false, "Inverse FVG", inline = "IRJ", tooltip = "Show rejections made within inverse FVGs", group = g_RJ)
show_brj = input.bool(true, "Regular + Inverse FVG", inline = "BRJ", tooltip = "Show rejections made within both regular and inverse FVGs", group = g_RJ)

rrj_color = input.color(#2962ff, "", inline = "RRJ", group = g_RJ)
irj_color = input.color(#f23645, "", inline = "IRJ", group = g_RJ)
brj_color = input.color(color.black, "", inline = "BRJ", group = g_RJ)
// -------------------------------------------------- Inputs --------------------------------------------------


// -------------------------------------------------- Logic --------------------------------------------------
t = not na(time(tf, session, "America/New_York"))

[o, h, l, c, ti] = request.security(syminfo.tickerid, tf, [open[1], high[1], low[1], close[1], time[1]], lookahead = barmerge.lookahead_on, gaps = barmerge.gaps_off)

var tf_o = array.new_float()
var tf_h = array.new_float()
var tf_l = array.new_float()
var tf_c = array.new_float()
var tf_time = array.new_int()
var tf_t = array.new_bool()

var reg_fvg = array.new_box()
var reg_fvg_ce = array.new_line()
var reg_fvg_side = array.new_string()

var inv_fvg = array.new_box()
var inv_fvg_ce = array.new_line()
var inv_fvg_side = array.new_string()

reg_rj_bear = false
reg_rj_bull = false

inv_rj_bear = false
inv_rj_bull = false

solid_color(color x) =>
    color.new(x, 0)

avg_over(float[] h, float[] l, int len) =>
    sum = 0.0
    for i = 0 to len
        sum += (h.get(i) - l.get(i))
    result = sum / len

var tf_new = false

if timeframe.change(tf) and timeframe.in_seconds(tf) >= timeframe.in_seconds(timeframe.period)
    tf_o.unshift(o)
    tf_h.unshift(h)
    tf_l.unshift(l)
    tf_c.unshift(c)
    tf_t.unshift(t[1])
    tf_time.unshift(ti)

    tf_new := true

    if tf_o.size() > 300
        tf_o.pop()
        tf_h.pop()
        tf_l.pop()
        tf_c.pop()
        tf_t.pop()
        tf_time.pop()

if not extend_right
    if reg_fvg.size() > 0
        for i = 0 to reg_fvg.size() - 1
            reg_fvg.get(i).set_right(time)
            reg_fvg_ce.get(i).set_x2(time)
            
    if inv_fvg.size() > 0
        for i = 0 to inv_fvg.size() - 1
            inv_fvg.get(i).set_right(time)
            inv_fvg_ce.get(i).set_x2(time)

if tf_o.size() > 20 and tf_new
    bull = tf_c.get(1) > tf_o.get(1)
    fvg = bull ? (tf_h.get(2) < tf_l.get(0) and tf_l.get(1) <= tf_h.get(2) and tf_h.get(1) >= tf_l.get(0)) : (tf_l.get(2) > tf_h.get(0) and tf_l.get(1) <= tf_h.get(0) and tf_l.get(2) <= tf_h.get(1))
    fvg_len = bull ? tf_l.get(0) - tf_h.get(2) : tf_l.get(2) - tf_h.get(0)
    atr_check = fvg_len > avg_over(tf_h, tf_l, 20) * disp_x / 10

    if tf_t.get(2) and fvg and atr_check
        top = bull ? tf_l.get(0) : tf_l.get(2)
        bottom = bull ? tf_h.get(2) : tf_h.get(0)
        reg_fvg.unshift(box.new(tf_time.get(1), top, time, bottom, xloc = xloc.bar_time, extend = extend_right ? extend.right : extend.none, bgcolor = show_rfvg ? rfvg_color : na, border_color = na))
        reg_fvg_ce.unshift(line.new(tf_time.get(1), math.avg(top, bottom), time, math.avg(top, bottom), xloc = xloc.bar_time, extend = extend_right ? extend.right : extend.none, color = show_rfvg ? solid_color(rfvg_color) : na, style = line.style_dashed))
        reg_fvg_side.unshift(bull ? 'bull' : 'bear')
        
        tf_new := false

    if reg_fvg.size() > 0
        for i = reg_fvg.size() - 1 to 0
            remove_bull = reg_fvg_side.get(i) == 'bull' and tf_c.get(0) < reg_fvg.get(i).get_bottom()
            remove_bear = reg_fvg_side.get(i) == 'bear' and tf_c.get(0) > reg_fvg.get(i).get_top()

            if remove_bull or remove_bear
                inv_fvg.unshift(box.copy(reg_fvg.get(i)))
                inv_fvg_ce.unshift(line.copy(reg_fvg_ce.get(i)))
                inv_fvg.get(0).set_bgcolor(show_ifvg ? ifvg_color : na)
                inv_fvg_ce.get(0).set_color(show_ifvg ? solid_color(ifvg_color) : na)

                box.delete(reg_fvg.get(i))
                line.delete(reg_fvg_ce.get(i))
                reg_fvg.remove(i)
                reg_fvg_ce.remove(i)
                reg_fvg_side.remove(i)
                
                if remove_bear
                    inv_fvg_side.unshift('inv bear')
                else if remove_bull
                    inv_fvg_side.unshift('inv bull')

        if reg_fvg.size() > disp_limit
            box.delete(reg_fvg.pop())
            line.delete(reg_fvg_ce.pop())
            reg_fvg_side.pop()

    if inv_fvg.size() > 0
        for i = inv_fvg.size() - 1 to 0
            remove_inv_bear = inv_fvg_side.get(i) == 'inv bear' and tf_c.get(0) < inv_fvg.get(i).get_bottom()
            remove_inv_bull = inv_fvg_side.get(i) == 'inv bull' and tf_c.get(0) > inv_fvg.get(i).get_top()

            if remove_inv_bear or remove_inv_bull
                box.delete(inv_fvg.get(i))
                line.delete(inv_fvg_ce.get(i))
                inv_fvg.remove(i)
                inv_fvg_ce.remove(i)
                inv_fvg_side.remove(i)

        if inv_fvg.size() > disp_limit
            box.delete(inv_fvg.pop())
            line.delete(inv_fvg_ce.pop())
            inv_fvg_side.pop()

    if math.min(reg_fvg.size(), inv_fvg.size()) > 0
        for i = 0 to reg_fvg.size() - 1
            _rrj_bear = ta.pivothigh(high, ps, ps) and high[ps] >= reg_fvg.get(i).get_bottom() and high[ps] <= reg_fvg.get(i).get_top()
            _rrj_bull = ta.pivotlow(low, ps, ps) and low[ps] >= reg_fvg.get(i).get_bottom() and low[ps] <= reg_fvg.get(i).get_top()

            if _rrj_bear
                reg_rj_bear := true
            if _rrj_bull
                reg_rj_bull := true

        for i = 0 to inv_fvg.size() - 1
            _irj_bear = ta.pivothigh(high, ps, ps) and high[ps] >= inv_fvg.get(i).get_bottom() and high[ps] <= inv_fvg.get(i).get_top()
            _irj_bull = ta.pivotlow(low, ps, ps) and low[ps] >= inv_fvg.get(i).get_bottom() and low[ps] <= inv_fvg.get(i).get_top()

            if _irj_bear
                inv_rj_bear := true
            if _irj_bull
                inv_rj_bull := true

plotshape(show_rrj and reg_rj_bear[1], color = rrj_color, size = size.small, location = location.abovebar, style = shape.triangledown)
plotshape(show_rrj and reg_rj_bull[1], color = rrj_color, size = size.small, location = location.belowbar, style = shape.triangleup)

plotshape(show_irj and inv_rj_bear[1], color = irj_color, size = size.small, location = location.abovebar, style = shape.triangledown)
plotshape(show_irj and inv_rj_bull[1], color = irj_color, size = size.small, location = location.belowbar, style = shape.triangleup)

plotshape(show_brj and reg_rj_bear[1] and inv_rj_bear[1], color = brj_color, size = size.small, location = location.abovebar, style = shape.triangledown)
plotshape(show_brj and reg_rj_bull[1] and inv_rj_bull[1], color = brj_color, size = size.small, location = location.belowbar, style = shape.triangleup)

alertcondition(show_rrj and (reg_rj_bear[1] or reg_rj_bull[1]), "Any Regular FVG Rejection")
alertcondition(show_rrj and reg_rj_bear[1], "Regular FVG Bear Rejection")
alertcondition(show_rrj and reg_rj_bull[1], "Regular FVG Bull Rejection")

alertcondition(show_irj and (inv_rj_bear[1] or inv_rj_bull[1]), "Any Inverse FVG Rejection")
alertcondition(show_irj and inv_rj_bear[1], "Inverse FVG Bear Rejection")
alertcondition(show_irj and inv_rj_bull[1], "Inverse FVG Bull Rejection")

alertcondition(show_brj and ((reg_rj_bear[1] and inv_rj_bear[1]) or (reg_rj_bull[1] and inv_rj_bull[1])), "Any FVG + IFVG Rejection")
alertcondition(show_brj and reg_rj_bear[1] and inv_rj_bear[1], "FVG + IFVG Bear Rejection")
alertcondition(show_brj and reg_rj_bull[1] and inv_rj_bull[1], "FVG + IFVG Bull Rejection")
// -------------------------------------------------- Logic --------------------------------------------------

Overview

Inverse FVG with Rejections [TFO] plots customizable boxes and midline levels directly on the main price chart. Settings allow traders to adjust multi-timeframe analysis, session filtering, displacement thresholds, maximum display limits, and rejection pivot strength to identify key market structure reactions.

Details

Published by

theonetrade on GitHub

Code credit

tradeforopp, as written in the script's header

Draws

On the price chart

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.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Show Regular FVGbooltrueshow_rfvg
Show Inverse FVGbooltrueshow_ifvg
Extend Boxesbooltrueextend_right
rfvg_colorcolorcolor.new(#2962ff, 60)rfvg_color
ifvg_colorcolorcolor.new(#f23645, 60)ifvg_color
Timeframetimeframetf
Displacementint3disp_x
Display Limitint10disp_limit
Sessionsession0000-0000session
Rejection Strengthint1ps
Regular FVGboolfalseshow_rrj
Inverse FVGboolfalseshow_irj
Show all 16 settings
SettingTypeDefaultVariable
Regular + Inverse FVGbooltrueshow_brj
rrj_colorcolor#2962ffrrj_color
irj_colorcolor#f23645irj_color
brj_colorcolorcolor.blackbrj_color
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
302 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 3 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 4 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 3 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 3 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