OPEN-SOURCE SCRIPT
Mis à jour

Volume Pressure MACD

641
Volume Pressure MACD is a momentum indicator built on the MACD framework,
extended with three independent volume analysis layers that work together
to weight each signal by the quality and direction of volume participation —
not just its size.

The core idea: a price move backed by high volume is more meaningful than
the same move on thin volume. But volume size alone is incomplete —
a large-volume candle where price closes near the low tells a very different
story than one where price closes near the high. This indicator attempts to
capture both dimensions.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
BACKGROUND — WHY THREE VOLUME LAYERS?
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Standard MACD is calculated purely from price EMAs and ignores volume entirely.
Most volume-weighted MACD variants address this by multiplying the MACD value
by a simple volume ratio — more volume means a stronger signal. That approach
has a limitation: it treats all high-volume candles equally, whether the close
was bullish or bearish within the candle.

Volume Pressure MACD uses three separate volume inputs, each measuring a
different aspect of market participation:

LAYER 1 — VOLUME FACTOR
Measures how current volume compares to its recent average using a power
function (math.pow). The Volume Effect input controls the exponent, which
determines how aggressively above-average volume amplifies the MACD and how
much below-average volume dampens it. At 0.1 the effect is subtle and smooth;
higher values make the indicator more reactive to volume spikes. This layer
answers the question: how much volume is there?

LAYER 2 — VOLUME PRESSURE SCORE
This is the differentiating layer. For each bar, it calculates how much of
the total volume was spent by buyers versus sellers, based on where the
closing price lands relative to the bar's high-low range:

Buy Pressure = Volume × (Close - Low) / (High - Low)
Sell Pressure = Volume × (High - Close) / (High - Low)
Net Pressure = Buy Pressure - Sell Pressure

A candle that closes at its high assigns nearly all volume to buyers.
A candle that closes at its low assigns nearly all volume to sellers.
A doji near the midpoint splits volume roughly equally and contributes
minimal pressure in either direction.

The net pressure is normalized against its recent average and then applied
as a secondary weight on the MACD — clamped to a ±30% influence so it
modulates rather than dominates the output. This layer answers the question:
in which direction was volume being used?

LAYER 3 — VOLUME MOMENTUM
Compares a 5-bar volume average against a 20-bar volume average to determine
whether market participation is currently expanding or contracting. This does
not affect the MACD calculation itself — instead it drives the 4-tone histogram
coloring, giving a visual indication of whether the current MACD move is
occurring on growing or fading volume. This layer answers the question:
is volume increasing or decreasing?

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
DYNAMIC ZONE SYSTEM
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
One of the practical problems with MACD-based indicators is that fixed
overbought/oversold lines are meaningless across different assets and
timeframes. MACD values on a 5-minute chart of a low-priced asset can be
a fraction of a unit, while the same indicator on a weekly chart of a
high-priced asset can reach thousands. Static horizontal lines cannot
account for this.

The zone system in this indicator is fully dynamic:

- The upper boundary (Strong Bull) is set to the highest MACD value
over the Zone Lookback period, floored at zero
- The lower boundary (Strong Bear) is set to the lowest MACD value
over the Zone Lookback period, capped at zero
- The Weak/Strong boundary is calculated as a percentage of those
extremes, controlled by the Weak/Strong Split input
- All four zone boundaries automatically adjust as new bars print
and as you switch between timeframes or assets

Zone definitions:
Strong Bull — MACD is in the upper portion of its recent historical
range; momentum is extended to the upside
Weak Bull — MACD is positive but has not yet reached historically
elevated levels; upward momentum is present but moderate
Weak Bear — MACD is negative but within the lower portion of its
recent range; downward momentum is present but moderate
Strong Bear — MACD is deep in its recent historical range; momentum
is extended to the downside

The zones are color-filled between their boundaries and labeled at the
right edge of the chart for easy reading. Bull zones are drawn in green
tones and are mathematically prevented from crossing below zero. Bear zones
are drawn in red tones and are mathematically prevented from crossing above
zero, so the zone layout always remains logically consistent regardless of
MACD behavior.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
HISTOGRAM COLORING
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The histogram uses four distinct colors based on the combination of MACD
direction and volume momentum, allowing you to read both momentum and
participation at a glance:

Dark green — histogram above zero + volume momentum expanding
(positive momentum with growing participation)
Light green — histogram above zero + volume momentum contracting
(positive momentum but participation fading)
Dark red — histogram below zero + volume momentum expanding
(negative momentum with growing participation)
Light red — histogram below zero + volume momentum contracting
(negative momentum but participation fading)

The transition from dark to light (or vice versa) within the same direction
can be an early indication of momentum exhaustion or resumption.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
SIGNAL TYPES
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
▲ BUY triangle (green, bottom)
MACD crosses above Signal line AND volume exceeds the average
by the Strong Volume Multiplier threshold. Both conditions must
be true simultaneously.

▼ SELL triangle (red, top)
MACD crosses below Signal line AND volume exceeds the average
by the Strong Volume Multiplier threshold. Both conditions must
be true simultaneously.

+ Cross marker on MACD line
All MACD/Signal crossovers, regardless of volume. Plotted directly
at the crossover price level on the indicator, not at the top or
bottom of the pane.

M↑ circle (teal) — Bullish divergence on the MACD line
Price makes a lower low while MACD makes a higher low,
detected using asymmetric pivot logic.

M↓ circle (fuchsia) — Bearish divergence on the MACD line
Price makes a higher high while MACD makes a lower high.

H↑ diamond (yellow) — Bullish divergence on the Histogram
Price makes a lower low while the histogram makes a higher low.

H↓ diamond (orange) — Bearish divergence on the Histogram
Price makes a higher high while the histogram makes a lower high.

Note: MACD line divergence and histogram divergence are calculated
independently. When both trigger together it may indicate a stronger
divergence condition. When only one triggers it can reflect early or
partial divergence development.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
INFO TABLE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
A live data table in the top-right corner displays four values
for the most recent closed bar:

Diff — the current distance between the MACD and Signal lines,
with a directional arrow showing which is above the other
Vol Factor — the current volume multiplier relative to the average.
Values above 1.0 indicate above-average volume (green);
values below 1.0 indicate below-average volume (red)
Vol Momentum — whether the 5-bar volume average is above or below
the 20-bar average (Rising / Falling)
Vol Pressure — the net directional pressure score for the current bar
(Buy / Sell / Neutral), based on the pressure calculation
described above

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
INPUT REFERENCE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Fast EMA — fast EMA length for classic MACD (default 12)
Slow EMA — slow EMA length for classic MACD (default 26)
Signal EMA — signal line EMA length (default 9)
MACD Smooth — additional EMA smoothing applied to the
volume-weighted MACD line (default 3)
Volume SMA Length — lookback for calculating average volume,
used in both Volume Factor and Pressure Score
Volume Effect — exponent controlling how strongly volume
scales the MACD; lower = smoother (default 0.1)
Strong Volume Multiplier — volume must exceed average × this value
for BUY/SELL triangles to appear (default 1.5)
Divergence Lookback — pivot bar count for divergence detection;
higher values find fewer but more significant
divergences (default 5)
Zone Lookback Bars — how many bars are used to define the dynamic
zone boundaries (default 100)
Weak/Strong Split — the percentage point within the zone range
where weak ends and strong begins (default 0.35)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
COMPATIBILITY
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Works on all asset classes including equities, cryptocurrency, forex,
commodities, and indices. Compatible with all timeframes. The dynamic
zone system and volume pressure calculation are designed to produce
meaningful output regardless of the absolute price or volume scale
of the instrument.

Pine Script v5.
Notes de version
### How It Works — Technical Details

**Volume-Weighted MACD Calculation**

The standard MACD line (fastEMA − slowEMA) is computed first using
ta.ema() on close. This classic value is then modified by two
independent volume weights before the final MACD line is produced:

Step 1 — Volume Factor:
volFactorRaw = volume / ta.sma(volume, volLen)
volFactor = math.pow(volFactorRaw, volPower)

The power function is used intentionally rather than a simple ratio.
At volPower = 0.1, a bar with 4× average volume produces a factor of
math.pow(4, 0.1) = 1.149 — a 14.9% amplification rather than 400%.
This keeps the volume influence proportional and prevents single
extreme-volume bars from distorting the output. At volPower = 0.5
(square root), the same 4× volume produces a 2× factor. Higher
values make the indicator progressively more reactive to volume spikes.

Step 2 — Pressure Weight:
buyPressure = volume × (close − low) / (high − low + 0.0001)
sellPressure = volume × (high − close) / (high − low + 0.0001)
netPressure = buyPressure − sellPressure
pressureScore = netPressure / ta.sma(math.abs(netPressure), volLen)
pressureWeight = 1 + math.max(−0.3, math.min(0.3, pressureScore × 0.1))

The 0.0001 offset in the denominator prevents division by zero on
doji candles where high equals low. The pressure weight is clamped
to a maximum influence of ±30% so that candle structure modulates
the MACD rather than overriding it.

The final MACD line is:
macd = ta.ema(macdClassic × volFactor × pressureWeight, smoothLen)

The additional smoothLen EMA pass reduces noise introduced by the
volume weighting without adding significant lag to crossover timing.

**Asymmetric Pivot Divergence Detection**

Both MACD line and histogram divergences use an asymmetric pivot
structure: leftBars = max(divLookback / 2, 2) and rightBars =
divLookback. Using fewer bars on the left than the right makes the
pivot detection faster to confirm while still requiring meaningful
right-side validation. This is different from symmetric pivot
detection where both sides use the same bar count.

Divergence is confirmed when two conditions are simultaneously true
at a pivot:
— Bullish: price pivot low is lower than previous price pivot low
AND indicator pivot low is higher than previous indicator pivot low
— Bearish: price pivot high is higher than previous price pivot high
AND indicator pivot high is lower than previous indicator pivot high

Previous pivot values are retrieved using ta.valuewhen() with
occurrence index 1, which finds the most recent prior instance
of a confirmed pivot. MACD line and histogram divergences are
detected independently so they can trigger separately or together.

**Dynamic Zone Boundaries**

Zone boundaries are recalculated on every bar using the rolling
highest and lowest MACD values over Zone Lookback bars:

macdPeak = math.max(ta.highest(macd, zoneLookback), 0)
macdTrough = math.min(ta.lowest(macd, zoneLookback), 0)

The math.max(..., 0) and math.min(..., 0) floors prevent the bull
and bear zone boundaries from crossing the zero line even in
strongly trending conditions where all recent MACD values are on
one side of zero.

The Weak/Strong boundary splits each zone:
bullWeakLine = macdPeak × weakSplit
bearWeakLine = macdTrough × weakSplit

At the default weakSplit of 0.35, the lower 35% of the positive
MACD range is the Weak Bull zone and the upper 65% is the Strong
Bull zone. The same proportion applies symmetrically to the
negative range.

**4-Tone Histogram Coloring Logic**

histColor is determined by two independent boolean conditions:
— hist >= 0 (MACD above signal)
— volMomentum >= 1 (5-bar volume SMA above 20-bar volume SMA)

The four combinations produce:
— Dark green: positive histogram + expanding volume participation
— Light green: positive histogram + contracting volume participation
— Dark red: negative histogram + expanding volume participation
— Light red: negative histogram + contracting volume participation

### Originality

This script is an original work that modifies the standard MACD
calculation at the formula level using two independent volume
adjustments applied multiplicatively before the signal line is
computed. Most published volume-weighted MACD variants apply a
single volume ratio as a post-calculation multiplier. This
implementation applies the volume factor via a configurable power
function (controlling non-linear scaling) and the pressure weight
via a candle-body position score (measuring directional volume
commitment) as separate multiplicative terms within the MACD
calculation itself, before smoothing. The combination of this
three-layer volume system with asymmetric pivot divergence
detection on both the MACD line and histogram independently,
a self-scaling dynamic zone system that adapts to each asset's
historical MACD range, and a 4-tone histogram driven by volume
momentum represents the author's own original design and is not
derived from any existing published script.

Clause de non-responsabilité

Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.