Indicator · Pine Script v6 · Own pane

Volume Surprise [LuxAlgo]

by MeridianAlgo· code credited to LuxAlgo

Volume Surprise plots volume against a historical summary for matching time periods in a separate pane.

View on GitHub

GitHub stars9on the repository
Pine versionv6current
Lines of code159
Settings15inputs
LicenceMIT
Last update4 months ago29 Jun 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

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

Volume_Surprise_LuxAlgo.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=6
indicator("Volume Surprise [LuxAlgo]", "LuxAlgo - Volume Surprise", overlay = false, format = format.volume)
//---------------------------------------------------------------------------------------------------------------------}
// Settings
//---------------------------------------------------------------------------------------------------------------------{
length = input.int(50,
  minval = 1)

smooth = input.int(1,
  minval = 1)

// Periods
autoFormat = input(true, 'Auto Selection',
  group = 'Periods',
  tooltip = 'Automatically choose a practical combination of periods based on the chart timeframe')

considerMinutes = input(true, 'Minutes',
  group = 'Periods')

considerHours = input(true, 'Hours',
  group = 'Periods')

considerDays = input(false, 'Days',
   inline = 'day',
   group = 'Periods')

daysOptions = input.string('Day of Week', '',
  options = ['Day of Week', 'Day of Month', 'Day of Year'],
  inline = 'day',
  group = 'Periods')

considerMonths = input(false, 'Months',
  group = 'Periods')

considerQuarters = input(false, 'Quarters',
  group = 'Periods')

// Summary
summaryMethod = input.string('Mean', 'Method',
  options = ['Mean', 'Percentile'],
  group = 'Summary')

percentile = input(50,
  active = summaryMethod == 'Percentile',
  group = 'Summary')

// Forecast
showForecast = input(true, 'Show Forecast',
  group = 'Forecast')

forecastWindow = input.int(50, 'Forecast Window',
  minval = 1,
  maxval = 499,
  group = 'Forecast')

forecastStyleColor = input(#2962ff, 'Style',
  inline = 'forecast_style',
  group = 'Forecast')

forecastStyleLine = input.string('Dotted', '',
  options = ['Solid', 'Dashed', 'Dotted'],
  inline = 'forecast_style',
  group = 'Forecast')

//---------------------------------------------------------------------------------------------------------------------}
// Types
//---------------------------------------------------------------------------------------------------------------------{
type vector
    array<float> v

//---------------------------------------------------------------------------------------------------------------------}
// Methods
//---------------------------------------------------------------------------------------------------------------------{
method getSummary(map<string, vector> id, key) =>
    summary = switch summaryMethod
        'Mean' => id.get(key).v.avg()
        'Percentile' => id.get(key).v.percentile_linear_interpolation(percentile)

//---------------------------------------------------------------------------------------------------------------------}
// Calculations
//---------------------------------------------------------------------------------------------------------------------{
if barstate.isfirst and autoFormat
    if timeframe.isseconds
        considerMinutes := true, considerHours := true, considerDays := false, considerMonths := false, considerQuarters := false
    else if timeframe.isminutes and timeframe.in_seconds(timeframe.period) >= 3600
        considerMinutes := false, considerHours := true, considerDays := true, considerMonths := false, considerQuarters := false
    else if timeframe.isminutes
        considerMinutes := true, considerHours := true, considerDays := false, considerMonths := false, considerQuarters := false
    else
        considerMinutes := false, considerHours := false, considerDays := false, considerMonths := true, considerQuarters := true

// custom datetime format
var format =
  str.format('{0}{1}{2}{3}{4}ss',
  considerQuarters ? str.tostring(math.ceil(month / 3)) : '',
  considerMonths ? 'MM:' : '',
  considerDays ? (daysOptions == 'Day of Week' ? 'EEE:' : daysOptions == 'Day of Month' ? 'dd:' : 'DDD:') : '',
  considerHours ? 'hh:' : '',
  considerMinutes ? 'mm:' : ''
  )

var data = map.new<string, vector>()

vol = ta.sma(volume, smooth)
key = str.format_time(time, format)

// Add new vector to map if key is not found
if not data.keys().includes(key)
    data.put(key, vector.new(array.new<float>(0)))

summary = data.getSummary(key)

data.get(key).v.push(vol)

// Trim vector
if data.get(key).v.size() > length
    data.get(key).v.shift()

//---------------------------------------------------------------------------------------------------------------------}
//Forecast
//---------------------------------------------------------------------------------------------------------------------{
var forecastStyle = switch forecastStyleLine
    'Solid' => line.style_solid
    'Dashed' => line.style_dashed
    'Dotted' => line.style_dotted

if showForecast and barstate.islast
    forecastCoordinates = array.new<chart.point>(0)
    forecastCoordinates.push(chart.point.from_time(time, summary))

    for i = 1 to forecastWindow
        t = time(timeframe.period, bars_back = -i)
        forecastKey = str.format_time(t, format)

        // Forecasted value
        if data.keys().includes(forecastKey)
            forecastValue = data.getSummary(forecastKey)
            forecastCoordinates.push(chart.point.from_time(t, forecastValue))
        else
            forecastCoordinates.push(chart.point.from_time(t, na))
    
    polyline.delete(polyline.new(forecastCoordinates, xloc = xloc.bar_time, line_style = forecastStyle, line_color = forecastStyleColor)[1])

//---------------------------------------------------------------------------------------------------------------------}
//Plot
//---------------------------------------------------------------------------------------------------------------------{
css = vol > summary ? color.new(#089981, 50) : color.new(#f23645, 50)

plotVolume = plot(vol, 'Volume', color = color.gray)
plotEv = plot(summary, 'Expected Volume', color = color.orange, linestyle = plot.linestyle_dotted)

plot(vol - summary, 'Difference',
  style = plot.style_columns,
  color = css)

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

Overview

Volume Surprise [LuxAlgo] groups past volume by minutes, hours, days, months, or quarters, then summarizes each group with a mean or a percentile. Length sets the sample window and smooth reduces noise. Auto selection can change which periods are used according to the chart timeframe. An optional forecast line projects that summary over a chosen window. The script does not generate trade entries or exits.

Details

Published by

MeridianAlgo on GitHub

Code credit

LuxAlgo, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Volume

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

code-converterconverterjavascriptpinescripttranspilercode-reviewmeridianalgocode-conversionpinescript-algorithms

Settings

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

SettingTypeDefaultVariable
lengthint50length
smoothint1smooth
Auto SelectionbooltrueautoFormat
MinutesbooltrueconsiderMinutes
HoursbooltrueconsiderHours
DaysboolfalseconsiderDays
daysOptionsstringDay of WeekdaysOptions
MonthsboolfalseconsiderMonths
QuartersboolfalseconsiderQuarters
MethodstringMeansummaryMethod
percentileint50percentile
Show ForecastbooltrueshowForecast
Show all 15 settings
SettingTypeDefaultVariable
Forecast Windowint50forecastWindow
Stylecolor#2962ffforecastStyleColor
forecastStyleLinestringDottedforecastStyleLine
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

Money Flow Index

by everget
948 stars

Calculates the standard Money Flow Index (MFI) oscillator alongside an exponential moving average signal line in a separate pane. The script visually highlights trend conditions through dynamic ribbon filling, optional difference histogram bars, and overbought

Indicator v4 Oscillators & momentumVolume
Updated 10 days ago · GPL-3.0 GitHub repository of Money Flow Index

This indicator plots a Supertrend-based trend-following setup in a separate pane and skips conditions it treats as a sideways market. A volatility range is built from an ATR value, with RMA, SMA, EMA, or WMA smoothing, or from a fixed point distance. Optional

Indicator v5 TrendVolatility & bands
Updated 1 year ago · MPL-2.0 GitHub repository of Trend Following Setup - Sideways Market Skipper
549 stars

Range Volume Change compares volume inside a chosen session window with the same window on the previous day and plots that change as a percentage. It accumulates volume during the window and, when enabled, volume outside it, drawing growing columns in a separa

Indicator v5 VolumeSessions & time Repaints
Updated 10 months ago · None stated GitHub repository of Range Volume Change
257 stars

This indicator builds a footprint of estimated buy and sell volume across price rows and plots it in a separate pane. It fills rows from bar low to high, stores volume per row, and draws buy and sell volume boxes, volume-profile boxes, row labels, and cumulati

Indicator v5 Volume Repaints
Updated 6 weeks ago · None stated GitHub repository of Footprint Delta Lite

Commitment Gauge

by harryguiacorn
219 stars

This indicator measures directional momentum by evaluating candlestick body proportions and volume over a user-defined lookback window. It computes the ratio of candle body to total range, weights the cumulative value by volume and absolute body size, and dete

Indicator v4 VolumeCandlestick patterns
Updated 1 year ago · None stated GitHub repository of Commitment Gauge

Aggregate Signal

by capissimo
114 stars

This indicator builds an aggregate oscillator in a separate pane. It scales open, high, low, close, and volume into a 0 to 1 range, then averages scaled readings from MACD, a MACD histogram, RSI, stochastic, CCI, momentum, OBV, a directional index, volume-weig

Indicator v4 Oscillators & momentumVolume Repaints
Updated 1 year ago · None stated GitHub repository of Aggregate Signal

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