Indicator · Pine Script v6 · On the chart

Swing Profile [BigBeluga]

by theonetrade· code credited to BigBeluga

Swing Profile [BigBeluga] is an overlay indicator that calculates volume profiles for individual price swings.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code424
Settings14inputs
LicenceMIT
Last update2 weeks ago7 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

424 lines of Pine Script v6 from assets/structure-aware-volume-profiling-per-swing.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

structure-aware-volume-profiling-per-swing.pine
// This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International  
// https://creativecommons.org/licenses/by-nc-sa/4.0/
// © BigBeluga

//@version=6
indicator("Swing Profile [BigBeluga]", overlay = true, max_labels_count = 500, max_boxes_count = 500, calc_bars_count = 2000, max_bars_back = 5000)


// INPUTS ---------------------------------------------------------------------

swingLen = input.int(50, "Swing Length", minval = 10)

swingColorUp = input.color(color.lime, "▲", inline = "colors")
swingColorDown = input.color(color.orange, "▼", inline = "colors")

showProfile = input.bool(true, "Profile", group = "Swing Volume Profile")
showHeatMap = input.bool(false, "HeatMap", group = "Swing Volume Profile")

showZigZag = input.bool(true, "ZigZag", inline = "Zz")
zigZagStyleInput = input.string("Dotted", "", ["Dotted", "Dashed", "Solid"], inline = "Zz")

showPOC = input.bool(true, "PoC", "", inline = "Poc", group = "Point of Control")
pocWidthInput = input.int(2, "", inline = "Poc", group = "Point of Control")
pocColor = input.color(color.red, "", inline = "Poc", group = "Point of Control")

transparentNA = color.new(color.black, 100)

string dataSizeInput = input.string("Small", title = "Data Size", options = ["Tiny", "Small", "Normal", "Large", "Huge"])

// Size switcher for labels
getLabelSize() =>
    switch dataSizeInput
        "Small"  => size.small
        "Normal" => size.normal
        "Large"  => size.large
        "Huge"   => size.huge
        => size.tiny

getZigZagLineStyle() =>
    switch zigZagStyleInput
        "Dotted" => line.style_dotted
        "Dashed" => line.style_dashed
        "Solid"  => line.style_solid


// Persistent storage containers
var polyline profilePoly = na
var dataLabel = label(na)
var pocLineHandle = line(na)
var profileBoxes = array.new<box>()

// Structs for swing points
type SwingData
    float price
    int index

var highSwing = SwingData.new(na, na)
var lowSwing  = SwingData.new(na, na)

// Direction flag: true = down move, false = up move
var isDownMove = false

// CALCULATIONS ---------------------------------------------------------------

// Detect swing highs and lows
highestSwingHigh = ta.highest(swingLen)
lowestSwingLow   = ta.lowest(swingLen)

if high == highestSwingHigh
    isDownMove := true
if low == lowestSwingLow
    isDownMove := false

// Store completed swing high
if high[1] == highestSwingHigh[1] and high < highestSwingHigh
    highSwing.index := bar_index[1]
    highSwing.price := high[1]

// Store completed swing low
if low[1] == lowestSwingLow[1] and low > lowestSwingLow
    lowSwing.index := bar_index[1]
    lowSwing.price := low[1]

// Default bin size based on ATR
priceBinSize = ta.atr(200) * 0.5

// HISTORICAL SWING LEG -------------------------------------------------------

// When direction flips we finalize previous swing leg and build full profile
if isDownMove != isDownMove[1]

    // Clear previous drawings
    profilePoly.delete()
    dataLabel.delete()
    for b in profileBoxes
        b.delete()
    profileBoxes.clear()

    swingMainColor = isDownMove ? swingColorDown : swingColorUp

    // Draw zigzag connector
    if showZigZag
        line.new(highSwing.index, highSwing.price, lowSwing.index, lowSwing.price, color = swingMainColor, style = getZigZagLineStyle())

    // Determine swing boundaries
    swingBottom = math.min(highSwing.price, lowSwing.price)
    swingTop    = math.max(highSwing.price, lowSwing.price)

    // Number of volume bins
    binCount = int(math.abs(highSwing.price - lowSwing.price) / priceBinSize)
    binStep  = math.abs(highSwing.price - lowSwing.price) / binCount

    lastSwingIndex = math.max(highSwing.index, lowSwing.index)
    prevSwingIndex = math.min(highSwing.index, lowSwing.index)

    // Arrays for volume accumulation
    volumeBins = array.new<float>(binCount, 0.)
    profilePoints = array.new<chart.point>()
    buyVolumeBins = array.new<float>(binCount, 0.)
    sellVolumeBins = array.new<float>(binCount, 0.)

    barOffset = bar_index - lastSwingIndex

    // Accumulate volume per price bin
    for i = barOffset to (lastSwingIndex - prevSwingIndex) + barOffset

        candleClose = close[i]
        candleOpen  = open[i]
        candleVol   = volume[i]

        for k = 0 to binCount - 1
            binMidPrice = swingBottom + (k * binStep) + (binStep / 2)

            if math.abs(binMidPrice - candleClose) < binStep

                volumeBins.set(k, volumeBins.get(k) + candleVol)

                if candleClose > candleOpen
                    buyVolumeBins.set(k, buyVolumeBins.get(k) + candleVol)
                else
                    sellVolumeBins.set(k, sellVolumeBins.get(k) + candleVol)

    // Draw boxes and build profile outline
    for k = 0 to binCount - 1

        binLow  = swingBottom + (k * binStep)
        binHigh = binLow + binStep

        volumeRatio = volumeBins.get(k) / volumeBins.max()
        profileWidth = int(volumeRatio * ((lastSwingIndex - prevSwingIndex) / 2))

        // Draw POC line
        if volumeRatio == 1 and showPOC
            line.new(showProfile ? prevSwingIndex + profileWidth : prevSwingIndex, math.avg(binLow, binHigh), lastSwingIndex, math.avg(binLow, binHigh), color = pocColor, width = pocWidthInput)

        // Create volume box
        box.new(
            showProfile ? prevSwingIndex + profileWidth : prevSwingIndex,
            binHigh,
            showHeatMap ? lastSwingIndex : prevSwingIndex,
            binLow,
            transparentNA,
            0,
            bgcolor = showProfile or showHeatMap ? color.from_gradient(volumeRatio, 0, 1, color.new(swingMainColor, 90), color.new(volumeRatio == 1 and showPOC ? pocColor : swingMainColor, 50)) : transparentNA,
            text = showHeatMap ? "" : volumeRatio == 1 ? str.tostring(volumeBins.max(), format.volume) : ""
        )

        // Build polygon outline
        if k == 0
            profilePoints.push(chart.point.from_index(prevSwingIndex, binLow))
        profilePoints.push(chart.point.from_index(prevSwingIndex + profileWidth, binLow))
        profilePoints.push(chart.point.from_index(prevSwingIndex + profileWidth, binHigh))
        if k == binCount - 1
            profilePoints.push(chart.point.from_index(prevSwingIndex, binHigh))

    // Draw outer polyline
    if showProfile
        polyline.new(profilePoints, false, true, line_color = showHeatMap ? color.new(swingMainColor, 50) : swingMainColor)

    // Summary label for historical swing
    swingArrowText = isDownMove ? "▼" : "▲"

    swingTooltip =
          "Total Volume: " + str.tostring(volumeBins.sum(), format.volume)
         + "\nBuy Volume: " + str.tostring(buyVolumeBins.sum(), format.volume)
         + "\nSell Volume: " + str.tostring(sellVolumeBins.sum(), format.volume)
         + "\nDelta Volume: " + str.tostring((buyVolumeBins.sum() - sellVolumeBins.sum()) / volumeBins.sum() * 100, format.percent)

    label.new(prevSwingIndex, isDownMove ? swingTop : swingBottom, swingArrowText,
         style = isDownMove ? label.style_label_down : label.style_label_up,
         color = transparentNA,
         textcolor = swingMainColor,
         size = getLabelSize(),
         tooltip = swingTooltip)


// REAL-TIME SWING LEG --------------------------------------------------------

// Real-time profile rebuilding while swing is still forming
if not isDownMove

    // Clear boxes on every update
    for b in profileBoxes
        b.delete()
    profileBoxes.clear()

    if barstate.islast

        swingMainColor = chart.fg_color

        // Remove previous zigzag preview line
        line.delete(line.new(highSwing.index, highSwing.price, lowSwing.index, lowSwing.price, color = swingMainColor, style = line.style_dashed)[1])

        swingBottom = math.min(highSwing.price, lowSwing.price)
        swingTop    = math.max(highSwing.price, lowSwing.price)

        binCount = int(math.abs(highSwing.price - lowSwing.price) / priceBinSize)
        binStep  = math.abs(highSwing.price - lowSwing.price) / binCount

        lastSwingIndex = math.max(highSwing.index, lowSwing.index)
        prevSwingIndex = math.min(highSwing.index, lowSwing.index)

        volumeBins = array.new<float>(binCount, 0.)
        profilePoints = array.new<chart.point>()
        buyVolumeBins = array.new<float>(binCount, 0.)
        sellVolumeBins = array.new<float>(binCount, 0.)

        barOffset = bar_index - lastSwingIndex

        // Accumulate volume in real time
        for i = barOffset to (lastSwingIndex - prevSwingIndex) + barOffset

            candleClose = close[i]
            candleOpen  = open[i]
            candleVol   = volume[i]

            for k = 0 to binCount - 1
                binMidPrice = swingBottom + (k * binStep) + (binStep / 2)

                if math.abs(binMidPrice - candleClose) < binStep

                    volumeBins.set(k, volumeBins.get(k) + candleVol)
                    if candleClose > candleOpen
                        buyVolumeBins.set(k, buyVolumeBins.get(k) + candleVol)
                    else
                        sellVolumeBins.set(k, sellVolumeBins.get(k) + candleVol)

        // Draw real-time boxes
        for k = 0 to binCount - 1

            binLow  = swingBottom + (k * binStep)
            binHigh = binLow + binStep

            volumeRatio = volumeBins.get(k) / volumeBins.max()
            profileWidth = int(volumeRatio * ((lastSwingIndex - prevSwingIndex) / 2))

            if volumeRatio == 1 and showPOC
                pocLineHandle := line.new(showProfile ? prevSwingIndex + profileWidth : prevSwingIndex, math.avg(binLow, binHigh), lastSwingIndex, math.avg(binLow, binHigh), color = pocColor, width = pocWidthInput)
                line.delete(pocLineHandle[1])

            profileBoxes.push(box.new(
                 showProfile ? prevSwingIndex + profileWidth : prevSwingIndex,
                 binHigh,
                 showHeatMap ? lastSwingIndex : prevSwingIndex,
                 binLow,
                 transparentNA,
                 0,
                 bgcolor = showProfile or showHeatMap ? color.from_gradient(volumeRatio, 0, 1, color.new(swingMainColor, 90), color.new(volumeRatio == 1 and showPOC ? pocColor : swingMainColor, 50)) : transparentNA,
                 text = showHeatMap ? "" : volumeRatio == 1 ? str.tostring(volumeBins.max(), format.volume) : ""
            ))

            if k == 0
                profilePoints.push(chart.point.from_index(prevSwingIndex, binLow))
            profilePoints.push(chart.point.from_index(prevSwingIndex + profileWidth, binLow))
            profilePoints.push(chart.point.from_index(prevSwingIndex + profileWidth, binHigh))
            if k == binCount - 1
                profilePoints.push(chart.point.from_index(prevSwingIndex, binHigh))

        // Update polyline in real time
        if showProfile
            polyline.delete(profilePoly[1])
            profilePoly := polyline.new(profilePoints, false, true, line_color = showHeatMap ? color.new(swingMainColor, 50) : swingMainColor)

        // Label with summary data
        swingTooltip = "T - Total Volume\nB - Buy Volume\nS - Sell Volume\nD - Delta Volume"

        swingDataText =
              "T: " + str.tostring(volumeBins.sum(), format.volume)
             + "\nB: " + str.tostring(buyVolumeBins.sum(), format.volume)
             + "\nS: " + str.tostring(sellVolumeBins.sum(), format.volume)
             + "\nD: " + str.tostring((buyVolumeBins.sum() - sellVolumeBins.sum()) / volumeBins.sum() * 100, format.percent)

        dataLabel := label.new(prevSwingIndex, not isDownMove ? swingTop : swingBottom, swingDataText,
             style = not isDownMove ? label.style_label_down : label.style_label_up,
             color = transparentNA,
             textcolor = swingMainColor,
             size = getLabelSize(),
             tooltip = swingTooltip,
             textalign = text.align_left)

        label.delete(dataLabel[1])


// MIRROR OF ABOVE FOR isDownMove == true ------------------------------------------

// Mirror logic for bullish direction
else

    for b in profileBoxes
        b.delete()
    profileBoxes.clear()

    if barstate.islast

        swingMainColor = chart.fg_color

        line.delete(line.new(highSwing.index, highSwing.price, lowSwing.index, lowSwing.price, color = swingMainColor, style = line.style_dashed)[1])

        swingBottom = math.min(highSwing.price, lowSwing.price)
        swingTop    = math.max(highSwing.price, lowSwing.price)

        binCount = int(math.abs(highSwing.price - lowSwing.price) / priceBinSize)
        binStep  = math.abs(highSwing.price - lowSwing.price) / binCount

        lastSwingIndex = math.max(highSwing.index, lowSwing.index)
        prevSwingIndex = math.min(highSwing.index, lowSwing.index)

        volumeBins = array.new<float>(binCount, 0.)
        profilePoints = array.new<chart.point>()
        buyVolumeBins = array.new<float>(binCount, 0.)
        sellVolumeBins = array.new<float>(binCount, 0.)

        barOffset = bar_index - lastSwingIndex

        for i = barOffset to (lastSwingIndex - prevSwingIndex) + barOffset

            candleClose = close[i]
            candleOpen  = open[i]
            candleVol   = volume[i]

            for k = 0 to binCount - 1

                binMidPrice = swingBottom + (k * binStep) + (binStep / 2)

                if math.abs(binMidPrice - candleClose) < binStep

                    volumeBins.set(k, volumeBins.get(k) + candleVol)
                    if candleClose > candleOpen
                        buyVolumeBins.set(k, buyVolumeBins.get(k) + candleVol)
                    else
                        sellVolumeBins.set(k, sellVolumeBins.get(k) + candleVol)

        for k = 0 to binCount - 1

            binLow  = swingBottom + (k * binStep)
            binHigh = binLow + binStep

            volumeRatio = volumeBins.get(k) / volumeBins.max()
            profileWidth = int(volumeRatio * ((lastSwingIndex - prevSwingIndex) / 2))

            if volumeRatio == 1 and showPOC
                pocLineHandle := line.new(showProfile ? prevSwingIndex + profileWidth : prevSwingIndex, math.avg(binLow, binHigh), lastSwingIndex, math.avg(binLow, binHigh), color = pocColor, width = pocWidthInput)
                line.delete(pocLineHandle[1])

            profileBoxes.push(box.new(
                 showProfile ? prevSwingIndex + profileWidth : prevSwingIndex,
                 binHigh,
                 showHeatMap ? lastSwingIndex : prevSwingIndex,
                 binLow,
                 transparentNA,
                 0,
                 bgcolor = showProfile or showHeatMap ? color.from_gradient(volumeRatio, 0, 1, color.new(swingMainColor, 90), color.new(volumeRatio == 1 and showPOC ? pocColor : swingMainColor, 50)) : transparentNA,
                 text = showHeatMap ? "" : volumeRatio == 1 ? str.tostring(volumeBins.max(), format.volume) : ""
             ))

            if k == 0
                profilePoints.push(chart.point.from_index(prevSwingIndex, binLow))
            profilePoints.push(chart.point.from_index(prevSwingIndex + profileWidth, binLow))
            profilePoints.push(chart.point.from_index(prevSwingIndex + profileWidth, binHigh))
            if k == binCount - 1
                profilePoints.push(chart.point.from_index(prevSwingIndex, binHigh))

        if showProfile
            polyline.delete(profilePoly[1])
            profilePoly := polyline.new(profilePoints, false, true, line_color = showHeatMap ? color.new(swingMainColor, 50) : swingMainColor)

        swingTooltip = "T - Total Volume\nB - Buy Volume\nS - Sell Volume\nD - Delta Volume"

        swingDataText =
              "T: " + str.tostring(volumeBins.sum(), format.volume)
             + "\nB: " + str.tostring(buyVolumeBins.sum(), format.volume)
             + "\nS: " + str.tostring(sellVolumeBins.sum(), format.volume)
             + "\nD: " + str.tostring((buyVolumeBins.sum() - sellVolumeBins.sum()) / volumeBins.sum() * 100, format.percent)

        dataLabel := label.new(prevSwingIndex, not isDownMove ? swingTop : swingBottom, swingDataText,
             style = not isDownMove ? label.style_label_down : label.style_label_up,
             color = transparentNA,
             textcolor = swingMainColor,
             size = getLabelSize(),
             tooltip = swingTooltip,
             textalign = text.align_left)

        label.delete(dataLabel[1])




// Smoothing MA inputs
GRP = "Moving Average"
maTypeInput = input.string("None", "Type", options = ["None", "SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group = GRP, display = display.none)
maLengthInput = input.int(25, "Length", group = GRP, display = display.none, active = maTypeInput != "None")
src = input(close, title="Source", group = GRP, active = maTypeInput != "None")


// Smoothing MA Calculation
ma(source, length, MAtype) =>
    switch MAtype
        "SMA"                   => ta.sma(source, length)
        "EMA"                   => ta.ema(source, length)
        "SMMA (RMA)"            => ta.rma(source, length)
        "WMA"                   => ta.wma(source, length)
        "VWMA"                  => ta.vwma(source, length)

plot(ma(src, maLengthInput, maTypeInput), color=color.yellow, title="MA")

Overview

Swing Profile [BigBeluga] identifies swing highs and lows over a set lookback length, connects them with a ZigZag line, and evaluates volume distribution within each swing leg. The indicator draws the Point of Control (POC), volume deltas, and optional heatmap visualisations using Pine Script drawing objects. Settings allow customization of the swing length, POC appearance, drawing styles, and label sizes on the main price chart.

Details

Published by

theonetrade on GitHub

Code credit

BigBeluga, 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-tradingbacktestingccxtcryptofair-value-gapheikin-ashiohlcvorder-flowpine-scriptpinescriptpynecorepythonquantitative-financesupertrendtechnical-analysistrading-indicatorstradingviewtradingview-indicatorsvolume-profile

Settings

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

SettingTypeDefaultVariable
Swing Lengthint50swingLen
▲colorcolor.limeswingColorUp
▼colorcolor.orangeswingColorDown
ProfilebooltrueshowProfile
HeatMapboolfalseshowHeatMap
ZigZagbooltrueshowZigZag
zigZagStyleInputstringDottedzigZagStyleInput
PoCbooltrueshowPOC
pocWidthInputint2pocWidthInput
pocColorcolorcolor.redpocColor
Data SizestringSmalldataSizeInput
TypestringNonemaTypeInput
Show all 14 settings
SettingTypeDefaultVariable
Lengthint25maLengthInput
Sourcesourceclosesrc
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

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 8 days ago · MIT GitHub repository of Volume Profile and Indicator by DGT

MGIC-tracker

by Allen1212
302 stars

The MGIC-tracker is a TradingView indicator that overlays ARK Invest trade records onto stock price charts. It plots buy and sell labels at the exact timestamp of each transaction, showing share volume and ETF weight. Users select a specific ETF type via setti

Indicator v4 Support & resistanceVolume
Updated 3 years ago · None stated GitHub repository of MGIC-tracker
228 stars

Comprehensive Volume Profile is an overlay indicator that calculates and plots volume distribution across specified time ranges such as daily sessions, weekly, monthly, or custom bar lengths. It identifies key structural price levels including the Point of Con

Indicator v6 VolumeSupport & resistance
Updated 4 months ago · None stated GitHub repository of Comprehensive Volume Profile

Moon Dev GEX Arrows

by moondevonyt
98 stars

This overlay indicator plots option strike walls and an optional session VWAP on the price chart for SPY or ES. It spaces major strikes by the selected instrument, draws a set number of strikes on each side, and marks wall-trap and sweep events after a cooldow

Indicator v5 Support & resistanceSessions & time
Updated 2 months ago · Custom licence GitHub repository of Moon Dev GEX Arrows

More Volume 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