OPEN-SOURCE SCRIPT

Volume Standard Deviation Alert Gus

Purpose
The script detects and alerts traders when the volume of a trading asset significantly exceeds a calculated threshold based on the standard deviation of volume over a specified lookback period. It optionally filters these alerts based on whether the price action is bullish or bearish.

Key Components
Inputs
lookback (default: 20)
The number of bars to consider when calculating the moving average and standard deviation of volume.

stdDevFactor (default: 2.0)
The multiplier for the standard deviation to determine the threshold for a volume spike.

alertOnClose (default: true)
Determines whether alerts should only be triggered after the bar has closed.

checkBullBear (default: false)
Enables filtering of alerts based on the bullishness or bearishness of the bar.

Calculations
volSMA
The simple moving average (SMA) of the volume over the lookback period.

volStd
The standard deviation of the volume over the lookback period.

threshold
The alert threshold is calculated as:

Threshold
=
volSMA
+
(
stdDevFactor
×
volStd
)
Threshold=volSMA+(stdDevFactor×volStd)
isBullish & isBearish
Determines whether the current bar is bullish (close > open) or bearish (close < open).

volumeSpikeCondition
A condition that triggers when the current volume exceeds the calculated threshold.

bullishCondition & bearishCondition
Refines the spike condition by requiring the bar to be bullish or bearish when checkBullBear is enabled.

finalCondition
The ultimate alert condition based on the user’s preference for bullish/bearish filtering.

finalTrigger
Ensures the alert only triggers at bar close if alertOnClose is set to true.

Visualization
Plots the SMA of the volume (volSMA) and the threshold line (threshold), helping traders visually understand the conditions.
Histograms the current volume and colors the bars:
Red: Volume exceeds the threshold.
Blue: Volume is below the threshold.
Alerts
The script generates an alert message when the finalTrigger condition is met:

"Bullish Volume Spike!" if the bar is bullish.
"Bearish Volume Spike!" if the bar is bearish.
"High Volume Spike!" if no bull/bear filter is applied.
Alerts are sent using alert() with the message and set to trigger once per bar close.

Usage
Traders can use this script to identify unusual volume activity, which often precedes significant price movements.
Customizability allows traders to tune the lookback period, standard deviation multiplier, and whether to filter for bullish/bearish spikes.
Visual and audible cues help in identifying important market events in real time.
This indicator is particularly useful for spotting market breakouts or breakdowns driven by high trading activity.
Volume

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer