Indicator · Pine Script v5 · On the chart

FVG Positioning Average [LuxAlgo]

by theonetrade· code credited to LuxAlgo

Calculates average price levels derived from bullish and bearish Fair Value Gaps (FVGs) filtered by an ATR multiplier.

View on GitHub

GitHub stars34on the repository
Pine versionv5runs as is
Lines of code126
Settings7inputs
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

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

fvg_positioning_average_luxalgo_UvnN0grH.pine
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo

//@version=5
indicator("FVG Positioning Average [LuxAlgo]", shorttitle = "LuxAlgo - FVG Positioning Average", overlay = true)

//---------------------------------------------------------------------------------------------------------------------}
//User Inputs
//---------------------------------------------------------------------------------------------------------------------{

lb = input.int(30, title = "FVG Lookback", tooltip = "Determines how many FVGs to consider for calculating the averages.", group = "Settings")
lbType = input.string("Bar Count", title = "Lookback Type", options = ["Bar Count","FVG Count"], tooltip = "Bar Count => Uses any FVGs within this Bar Lookback\nFVG Count => Uses only this amount of recent FVGs", group = "Settings")
atrMulti = input.float(0.25, step = 0.25, title = "ATR Multiplier", tooltip = "Only uses FVGs that are greater than ATR * Multiplier.", group = "Settings")

fvgTog = input.bool(true, title = "Show FVGs on Chart", group = "Style")
green =  input.color(#089981, title = "Bullish Color", group = "Style")
red = input.color(#f23645, title = "Bearish Color", group = "Style")
showFill = input.bool(true, title = "Show Gradient Areas", group = "Style")

invis = color.rgb(0,0,0,100)

//---------------------------------------------------------------------------------------------------------------------}
//Constants
//---------------------------------------------------------------------------------------------------------------------{

//ATR
atr = nz(ta.atr(200)*atrMulti, ta.cum(high - low) / (bar_index+1))

//FVG Detection
fvg_up = low > high[2] and close[1] > high[2] and (low-high[2]) > atr
fvg_down = high < low[2] and close[1] < low[2] and (low[2]-high) > atr

//Highest/Lowest
hst = ta.highest(high,5)
lst = ta.lowest(low,5)

//---------------------------------------------------------------------------------------------------------------------}
//Calculations
//---------------------------------------------------------------------------------------------------------------------{

var up_ary = array.new_box(na)
var down_ary = array.new_box(na)

if fvg_up
    up_ary.push(
      box.new(bar_index[2], low, bar_index, high[2]
      , border_color = fvgTog?color.new(green,50):na
      , bgcolor = fvgTog?color.new(green,50):na))

if fvg_down
    down_ary.push(
      box.new(bar_index[2],  low[2], bar_index, high
      , border_color = fvgTog?color.new(red,50):na
      , bgcolor = fvgTog?color.new(red,50):na))

//Array Size Management
if lbType == "FVG Count"
    if up_ary.size() > lb
        box.delete(up_ary.shift())
    if down_ary.size() > lb 
        box.delete(down_ary.shift())

if lbType == "Bar Count"
    for [index,bx] in up_ary
        left = bx.get_left()
        if left < bar_index-lb
            bx.delete()
            up_ary.remove(index)

    for [index,bx] in down_ary
        left = bx.get_left()
        if left < bar_index-lb
            bx.delete()
            down_ary.remove(index)


//Value Accumulation
up_vals = array.new_float(na)
down_vals = array.new_float(na)

for bx in up_ary
    up_vals.push(bx.get_bottom())
for bx in down_ary
    down_vals.push(bx.get_top())

//Averages
up_avg = array.avg(up_vals)
down_avg = array.avg(down_vals)

//Points to use for gradients
c_mid_h = math.max(math.avg(open,close),up_avg)
c_mid_l = math.min(math.avg(open,close),down_avg)

//---------------------------------------------------------------------------------------------------------------------}
//Display 
//---------------------------------------------------------------------------------------------------------------------{

//Up & Down Averages, only displaying if the highest/lowest is above/below the value.
ua = plot(up_avg
  , style = plot.style_linebr
  , color = (hst<up_avg?invis:green)
  , title = "Bull Average")

da = plot(down_avg
  , style = plot.style_linebr
  , color = (lst>down_avg?invis:red)
  , title = "Bear Average")

ul = plot(c_mid_h,display = display.none, editable = false)
dl = plot(c_mid_l,display = display.none, editable = false)

fill(ua, ul
  , c_mid_h
  , math.min(ta.sma(up_avg,10),up_avg)
  , color.new(chart.bg_color,100)
  , c_mid_h<=up_avg?invis:color.new(green,50)
  , display = showFill ? display.all : display.none)

fill(da, dl
  , math.max(ta.sma(down_avg,10),down_avg)
  , c_mid_l 
  , c_mid_l>=down_avg?invis:color.new(red,50)
  , color.new(chart.bg_color,100)
  , display = showFill ? display.all : display.none)

//---------------------------------------------------------------------------------------------------------------------}

Overview

Users can configure lookback mode based on bar count or total FVG count to adjust how many historical gaps contribute to the positional averages. The indicator plots FVG boxes directly on the price chart along with gradient areas to highlight liquidity zones and spatial positioning relative to active imbalances.

Details

Published by

theonetrade on GitHub

Code credit

LuxAlgo, 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
FVG Lookbackint30lb
Lookback TypestringBar CountlbType
ATR Multiplierfloat0.25atrMulti
Show FVGs on ChartbooltruefvgTog
Bullish Colorcolor#089981green
Bearish Colorcolor#f23645red
Show Gradient AreasbooltrueshowFill
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