Indicator · Pine Script v5 · On the chart

Dynamic Supply and Demand Zones [AlgoAlpha]

by theonetrade· code credited to AlgoAlpha

Dynamic Supply and Demand Zones [AlgoAlpha] calculates high-volume support and demand regions directly on the price chart.

View on GitHub

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

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

dynamic_supply_and_demand_zones_algoalpha_Sz1PjzR7.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlgoAlpha

//@version=5
indicator("Dynamic Supply and Demand Zones [AlgoAlpha]", "AlgoAlpha - 📦Dynamic Supply/Demand",overlay = true, max_boxes_count = 500, max_bars_back = 4999)
import PineCoders/VisibleChart/4

dynamic = input.bool(true, "Use Dynamic Look-Back", "If true, the indicator adjusts its lookback such that it considers data from the previous major pivot point to present", group = "Main Calculation")
len = input.int(100, "Look-back (For Non-Dynamic Look-Back)", group = "Main Calculation", tooltip = "If Dynamic Look-Back is disabled, the indicator will use this fixed look-back instead")
plen = input.int(200, "Pivot Point Detection Period", tooltip = "The look-back period of pivot points detection, pivots are detected with delay(depending on user imput, 100 by default)", group = "Main Calculation")
res = input.int(40, "Resolution", group = "Main Calculation", tooltip = "The profile resolution")
scale = input.int(33, "Profile Horizontal Width", tooltip = "The Horizontal Width of the profile, a smaller value will make the profile thinner", maxval = 100, minval = 1, group = "Main Calculation")
tolerance = input.float(0.93,"Zone Tolerance",tooltip = "The tolerance for zone detection, the lower the value the less zones will be marked", maxval = 1, minval = 0.01, group = "Main Calculation")
h = input.bool(true, "Show Profile", group = "Appearance")
h1 = input.bool(true, "Show Background Box", group = "Appearance")
neut = input.color(color.gray, "Levels Color", group = "Appearance")
green = input.color(#00ffbb, "Bullish Color", group = "Appearance")
red = input.color(#ff1100, "Bearish Color", group = "Appearance")

ph = ta.pivothigh(plen, plen)
pl = ta.pivotlow(plen, plen)

var pivotindex = 0

if not na(ph) or not na(pl)
    pivotindex := bar_index - plen

len1 = dynamic ? bar_index - pivotindex : len
var left = 0
top_boundaries = array.new_float(res)
bottom_boundaries = array.new_float(res)
binlen = array.new_float(res)
var boxes = array.new_box()
highs = array.new_float()
lows = array.new_float()
volumes = array.new_float()

for i = 0 to bar_index - (bar_index - len1)
    highs.push(high[i])
    lows.push(low[i])
    volumes.push(volume[i])

maxx = array.max(highs)
minn = array.min(lows)
size = array.size(highs)
var t = array.new_box()
var lab = array.new_label()

while t.size() > 0
    t.shift().delete()
while boxes.size() > 0
    boxes.shift().delete()
while lab.size() > 0
    lab.shift().delete()


if size > 0
    step = (maxx - minn) / res
    granularity = res
    for i = 0 to granularity - 1
        bin_size = 0.0
        bottom = minn + (i*step)
        top = minn + ( (i+1)*step )
        bottom_boundaries.insert(i, bottom)
        top_boundaries.insert(i, top)   
        for j = 0 to array.size(highs) - 1
            candle_above_hbar = lows.get(j) > top
            candle_below_hbar = highs.get(j) < bottom
            is_candle_in_bucket = not (candle_above_hbar or candle_below_hbar)
            bin_size += is_candle_in_bucket ? volumes.get(j) : 0
        array.insert(binlen, i, bin_size)

for i = 0 to res - 1
    iskey = (i == res - 1 ? true : binlen.get(i) < binlen.get(i + 1)*tolerance) and (i == 0 ? true : binlen.get(i) < binlen.get(i - 1)*tolerance)
    box_right = bar_index// + 7 + scale
    box_left = iskey ? (bar_index - len1) : bar_index
    box_top = array.get(top_boundaries, i)
    box_bottom = array.get(bottom_boundaries, i)
    left := box_left
    if iskey
        boxes.push(box.new(box_left, box_top, box_right, box_bottom, border_style = line.style_solid, border_color = color.new(neut, 70), border_width = 1, bgcolor = color.new(neut, 80)))
        lab.push(label.new(box_left, math.avg(box_top, box_bottom), str.tostring((1-(binlen.get(i)/binlen.max()))*100, format.percent), color = chart.fg_color, textcolor = chart.bg_color, style = label.style_label_right))

for i = 0 to res - 1
    box_right = bar_index + 7 + scale//binlen.max()
    box_left = box_right - math.round(binlen.get(i))/math.round(binlen.max()) * scale
    box_top = array.get(top_boundaries, i)
    box_bottom = array.get(bottom_boundaries, i)
    left := box_left
    boxes.push(h ? box.new(box_left, box_top, box_right, box_bottom, border_style = line.style_solid, border_color = color.black, border_width = 1, bgcolor = color.gray) : na)
    

if h1
    t.push(box.new(bar_index-len1, top_boundaries.max(), bar_index, bottom_boundaries.min(), color.new(color.blue, 70), 1, line.style_solid, extend.none, bgcolor = color.new(color.blue, 90), text = "Total Look-Back Data", text_size = size.tiny, text_color = color.gray, text_halign =  text.align_center, text_valign = text.align_top))

if boxes.size() > 0
    qt = boxes.size()

    for ln = qt - 1 to 0
        if ln < boxes.size()
            cL = boxes.get(ln)
            yL = cL.get_top()
            yLa = cL.get_bottom()

            if close > yL
                cL.set_border_color(color.new(green, 50))
                cL.set_bgcolor(color.new(green, 50))

            else if close < yLa
                cL.set_border_color(color.new(red, 50))
                cL.set_bgcolor(color.new(red, 50))

plotchar(ph != 0 ? true : false, "Pivot Highs", "●", location.abovebar, chart.fg_color, size = size.tiny, offset = -plen)
plotchar(pl != 0 ? true : false, "Pivot Lows", "●", location.belowbar, chart.fg_color, size = size.tiny, offset = -plen)

alertcondition(not na(ph) or not na(pl), "New Pivot Detected!")

Overview

Dynamic Supply and Demand Zones [AlgoAlpha] aggregates volume into user-defined price bins across either a dynamic lookback period driven by major pivot points or a customizable fixed bar length. The indicator detects key price steps with significant volume concentration to draw dynamic supply and demand zones alongside an optional horizontal volume profile. Profile appearance and zone sensitivity can be adjusted using settings for resolution, zone tolerance, horizontal scale, and custom colors.

Details

Published by

theonetrade on GitHub

Code credit

AlgoAlpha, 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
Use Dynamic Look-Backbooltruedynamic
Look-back (For Non-Dynamic Look-Back)int100len
Pivot Point Detection Periodint200plen
Resolutionint40res
Profile Horizontal Widthint33scale
Zone Tolerancefloat0.93tolerance
Show Profilebooltrueh
Show Background Boxbooltrueh1
Levels Colorcolorcolor.grayneut
Bullish Colorcolor#00ffbbgreen
Bearish Colorcolor#ff1100red
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

Moon Dev GEX Sweep & CVD

by moondevonyt
98 stars

The indicator detects liquidity sweeps across key price levels and calculates a cumulative volume delta proxy. It uses pivot high and low lookbacks to identify swing points, marking sweeps when price breaks beyond a level and quickly closes back inside. Featur

Indicator v5 Support & resistanceSMC / ICT / price action
Updated 2 months ago · Custom licence GitHub repository of Moon Dev GEX Sweep & CVD

Order Flow Strategy (OFS)

by roan-maverick
69 stars

The Order Flow Strategy is a chart overlay indicator based on auction market theory and order flow concepts. It evaluates higher-timeframe value structure across custom timeframes alongside value area profiles (VAH, POC, VAL) and Fibonacci discount or premium

Indicator v6 SMC / ICT / price actionSupport & resistance Repaints
Updated 10 days ago · Custom licence GitHub repository of Order Flow Strategy (OFS)

Calculates higher-timeframe volume profiles to identify Value Area High (VAH), Value Area Low (VAL), and Point of Control (POC) levels directly on the price chart. It flags potential reversal setups and Change in State of Delivery (CISD) patterns relative to v

Indicator v6 VolumeSupport & resistance
Updated 3 months ago · None stated GitHub repository of CandelaCharts - Value Area Reversals

Copilot

by milocaetano
48 stars

Copilot is an order flow range-reversal indicator designed to overlay trading setups directly on the price chart. It evaluates four criteria: market context (sideways vs trending regime based on ATR height), structure (double top or double bottom retests), abs

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 4 weeks ago · MIT GitHub repository of Copilot

Supply and Demand Visible Range identifies supply, demand, and equilibrium zones across the visible chart range. It accumulates high, low, and volume data starting from the leftmost visible bar, optionally requesting lower timeframe intrabar data for finer res

Indicator v5 Support & resistanceVolume Repaints
Updated 3 months ago · AGPL-3.0 GitHub repository of Supply and Demand Visible Range [LuxAlgo]
13 stars

This script identifies and visualizes bullish and bearish order blocks on the price chart. It detects low-volatility consolidation ranges followed by breakout moves accompanied by high trading volume. Users can select between Simple, Relative, or Weighted volu

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 6 months ago · MIT GitHub repository of Advanced Order Blocks with Volume

More Support & resistance 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