All pages
Powered by GitBook
1 of 1

Loading...

Ease of Movement

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

1

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)

2

Logic

  • The script calculates the simple moving average (SMA) of volume over the pre-defined lookback period (avgVolume)

  • It then checks if the current volume exceeds the average volume multiplied by the defined volumeMultiplier.

  • If the condition is met, a buying surge is detected.

3

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

1

Set the timeframe of your analysis

Use this indicator on a lower timeframe (1 minute or 5 minute charts). This script aggregates volume based on the lookbackPeriod parameter, so ensure this aligns with your strategy.

2

Adjust the multiplier to your trading strategy

Modify the the VolumeMultiplier input to fine-tune the surge detection sensitivity. A higher multiple is better because it will result in fewer but more significant surges.

3

Interpret the resulting signals

A green label or background indicates a potential buying surge, which points to increased liquidity and interest in the asset.

Optional Enhancements

1

Add Alerts for when surges are detected

alertcondition(isSurge, title="Buying Surge Alert", message="A buying surge has been detected!")
2

Using exponential moving average (ta.ema) instead of SMA

avgVolume = ta.ema(volume, lookbackPeriod)
3

Filtering based on price action

Filtering based on price action (only detect surges when the close price is higher than the open price)