OPEN-SOURCE SCRIPT
Updated

Volume Sampled Supertrend [BackQuant]

306
Volume Sampled Supertrend [BackQuant]
A Supertrend that runs on a volume sampled price series instead of fixed time. New synthetic bars are only created after sufficient traded activity, which filters out low participation noise and makes the trend much easier to read and model.

Original Script Link
This indicator is built on top of my volume sampling engine. See the base implementation here:
tradingview.com/script/zHxrX0A6-Volume-Based-Sampling-BackQuant/

Why Volume Sampling
Traditional charts print a bar every N minutes regardless of how active the tape is. During quiet periods you accumulate many small, low information bars that add noise and whipsaws to downstream signals.

Volume sampling replaces the clock with participation. A new synthetic bar is created only when a pre-set amount of volume accumulates (or, in Dollar Bars mode, when pricevolume reaches a dollar threshold). The result is a non-uniform time series that stretches in busy regimes and compresses in quiet regimes. This naturally:
  • filters dead time by skipping low volume chop;
  • standardizes the information content per bar, improving comparability across regimes;
  • stabilizes volatility estimates used inside banded indicators;
  • gives trend and breakout logic cleaner state transitions with fewer micro flips.


What this tool does
It builds a synthetic OHLCV stream from volume based buckets and then applies a Supertrend to that synthetic price. You are effectively running Supertrend on a participation clock rather than a wall clock.

Core Features
  • Sampling Engine - Choose Volume buckets or Dollar Bars. Thresholds can be dynamic from a rolling mean or median, or fixed by the user.
  • Synthetic Candles - Plots the volume sampled OHLC candles so you can visually compare against regular time candles.
  • Supertrend on Synthetic Price - ATR bands and direction are computed on the sampled series, not on time bars.
  • Adaptive Coloring - Candle colors can reflect side, intensity by volume, or a neutral scheme.
  • Research Panels - Table shows total samples, current bucket fill, threshold, bars-per-sample, and synthetic return stats.
  • Alerts - Long and Short triggers on Supertrend direction flips for the synthetic series.


How it works
Sampling
  • Pick Sampling Method = Volume or Dollar Bars.
  • Set the dynamic threshold via Rolling Lookback and Filter (Mean or Median), or enable Use Fixed and type a constant.
  • The script accumulates volume (or pricevolume) each time bar. When the bucket reaches the threshold, it finalizes one or more synthetic candles and resets accumulation.
  • Each synthetic candle stores its own OHLCV and is appended to the synthetic series used for all downstream logic.

Supertrend on the sampled stream
  • Choose Supertrend Source (Open, High, Low, Close, HLC3, HL2, OHLC4, HLCC4) derived from the synthetic candle.
  • Compute ATR over the synthetic series with ATR Period, then form upperBand = src + factorATR and lowerBand = src - factorATR.
  • Apply classic trailing band and direction rules to produce Supertrend and trend state.
  • Because bars only come when there is sufficient participation, band touches and flips tend to align with meaningful pushes, not idle prints.


Reading the display
  • Synthetic Volume Bars - The non-uniform candles that represent equal information buckets. Expect more candles during active sessions and fewer during lulls.
  • Volume Sampled Supertrend - The main line. Green when Trend is 1, red when Trend is -1.
  • Markers - Small dots appear when a new synthetic sample is created, useful for aligning activity cycles.
  • Time Bars Overlay (optional) - Plot regular time candles to compare how the synthetic stream compresses quiet chop.


Settings you will use most
Data Settings
  • Sampling Method - Volume or Dollar Bars.
  • Rolling Lookback and Filter - Controls the dynamic threshold. Median is robust to outliers, Mean is smoother.
  • Use Fixed and Fixed Threshold - Force a constant bucket size for consistent sampling across regimes.
  • Max Stored Samples - Ring buffer limit for performance.


Indicator Settings
  • SMA over last N samples - A moving average computed on the synthetic close series. Can be hidden for a cleaner layout.
  • Supertrend Source - Price field from the synthetic candle.
  • ATR Period and Factor - Standard Supertrend controls applied on the synthetic series.

Visuals and UI
  • Show Synthetic Bars - Turn synthetic candles on or off.
  • Candle Color Mode - Green/Red, Volume Intensity, Neutral, or Adaptive.
  • Mark new samples - Puts a dot when a bucket closes.
  • Show Time Bars - Overlay regular candles for comparison.
  • Paint candles according to Trend - Colors chart candles using current synthetic Supertrend direction.
  • Line Width, Colors, and Stats Table toggles.


Some workflow notes:
Trend Following
  • Set Sampling Method = Volume, Filter = Median, and a reasonable Rolling Lookback so busy regimes produce more samples.
  • Trade in the direction of the Volume Sampled Supertrend. Because flips require real participation, you tend to avoid micro whipsaws seen on time bars.
  • Use the synthetic SMA as a bias rail and trailing reference for partials or re-entries.

Breakout and Continuation
  • Watch for rapid clustering of new sample markers and a clean flip of the synthetic Supertrend.
  • The compression of quiet time and expansion in busy bursts often makes breakouts more legible than on uniform time charts.

Mean Reversion
  • In instruments that oscillate, faded moves against the synthetic Supertrend are easier to time when the bucket cadence slows and Supertrend flattens.
  • Combine with the synthetic SMA and return statistics in the table for sizing and expectation setting.


Stats table (top right)
  • Method and Total Samples - Sampling regime and current synthetic history length.
  • Current Vol or Dollar and Threshold - Live bucket fill versus the trigger.
  • Bars in Bucket and Avg Bars per Sample - How much time data each synthetic bar tends to compress.
  • Avg Return and Return StdDev - Simple research metrics over synthetic close-to-close changes.


Why this reduces noise
Time based bars treat a 5 minute print with 1 percent of average participation the same as one with 300 percent. Volume sampling equalizes bar information content. By advancing the bar only when sufficient activity occurs, you skip low quality intervals that add variance but little signal. For banded systems like Supertrend, this often means fewer false flips and cleaner runs.

Notes and tips
  • Use Dollar Bars on assets where nominal price varies widely over time or across symbols.
  • Median filter can resist single burst outliers when setting dynamic thresholds.
  • If you need a stable research baseline, set Use Fixed and keep the threshold constant across tests.
  • Enable Show Time Bars occasionally to sanity check what the synthetic stream is compressing or stretching.


Link again for reference
Original Volume Based Sampling engine:
tradingview.com/script/zHxrX0A6-Volume-Based-Sampling-BackQuant/

Bottom line
When you let participation set the clock, your Supertrend reacts to meaningful flow instead of idle prints. The result is a cleaner state machine, fewer micro whipsaws, and a trend read that respects when the market is actually trading.

Release Notes
Input fix

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.