SMI Ergodic Indicator
Pine Script to Detect Buying Surges Based on 24-Hour Trading Volume
Below is a Pine Script designed to analyze the 24-hour trading volume and detect buying surges. The script calculates the 24-hour average trading volume and identifies surges when the current volume exceeds a predefined multiplier of the average.
//@version=6
indicator("Buying Surge Detector", overlay=true, shorttitle="Volume Surge")
// Input parameters
volumeMultiplier = input.float(1.5, title="Volume Surge Multiplier", minval=1.0)
lookbackPeriod = input.int(1440, title="Lookback Period (Minutes)", minval=1) // Default: 1440 minutes = 24 hours
// Calculate average volume over the lookback period
avgVolume = ta.sma(volume, lookbackPeriod)
// Detect surges: Current volume > Average volume * Multiplier
isSurge = volume > (avgVolume * volumeMultiplier)
// Plot surge detection as a label on the chart
plotshape(isSurge, style=shape.labelup, color=color.green, size=size.small, location=location.belowbar, title="Buying Surge")
bgcolor(isSurge ? color.new(color.green, 90) : na, title="Background Highlight for Surge")
// Debugging and informational plots
plot(volume, color=color.blue, title="Current Volume")
plot(avgVolume, color=color.orange, title="Average Volume")
Script Details
Inputs
volumeMultiplier: defines how much higher the current volume must be in comparison to the average volume to trigger a "surge". Default is 1.5 (150% of the average volume)
lookbackPeriod: this is how far the script will look back to calculate the average volume. Default is is set to 1440 minutes (24 hours of 1-minute candles)
Visual Output
A green label (shape.labelup) is drawn on the chart below bars where a buying surge is detected.
The background is also highlighted faintly green during surges for additional visibility (bgcolor).
Two plots are added for reference: Current Volume (blue line) and Average Volume (orange volume)
Suggested Use
Optional Enhancements
Last updated
Was this helpful?