Pine Script Herrick Payoff Index (HPI)

Master this advanced money flow indicator in TradingView's Pine Script that uniquely combines price, volume, and open interest to gauge market strength and anticipate powerful trend reversals.

Subscribe now @ $99/month

What is the Herrick Payoff Index (HPI)?

The Herrick Payoff Index (HPI) is a sophisticated momentum oscillator that measures the money flowing into or out of a futures contract. Unlike many other volume-based indicators that only consider price and volume, the HPI adds a crucial third component: Open Interest. This makes HPI particularly relevant for futures and options markets where open interest provides additional insight into market participation and commitment.

The HPI essentially calculates the dollar value of money flowing into or out of a security. A positive HPI value indicates that money is flowing into the asset (accumulation), while a negative value suggests money is flowing out (distribution). The indicator fluctuates around a zero line and is often smoothed with a moving average.

HPI is primarily used by traders to:

In Pine Script, incorporating the Herrick Payoff Index allows for a deeper analysis of money flow, especially when open interest data is available for the traded asset.

Components and Calculation

The calculation of the Herrick Payoff Index is complex, combining price changes, volume, and open interest. For each period (bar), the calculation generally involves:

  1. Price Change: The difference between the current day's closing price and the previous day's closing price (`close - close[1]`).
  2. Daily Range: The difference between the current day's high and low (`high - low`).
  3. Volume: The total trading volume for the current period.
  4. Open Interest: The total number of open contracts for futures (or open interest for options). This is the unique and crucial component of HPI.

The core formula for HPI (un-smoothed) is often presented as:


`HPI = [ (Current Close - Previous Close) / (Current High - Current Low) ] * (Current Volume * HPI_Multiplier)`
Where `HPI_Multiplier` typically involves the lesser of current and previous Open Interest, or simply a scaling factor.
Specifically, a widely recognized version is:
`HPI = ( (close - close[1]) / (high - low) ) * volume * Min(openInterest, openInterest[1]) / ScalingFactor`

The `ScalingFactor` (e.g., 1000 or 100000) is used to bring the HPI values into a more manageable range for plotting. The `Min(openInterest, openInterest[1])` ensures that if there's a sudden large change in open interest, the calculation isn't distorted by only one side. It also helps in situations where open interest data might be irregular.

The final HPI value is usually smoothed using a moving average (e.g., 10-period SMA or EMA) to reduce noise and identify a clearer trend.

Basic Herrick Payoff Index (HPI) Implementation in Pine Script

Pine Script v5 provides a built-in function `ta.hpi()` which simplifies the calculation of the Herrick Payoff Index. It automatically handles the various components, including open interest if provided.

//@version=5
indicator("My Herrick Payoff Index (HPI)", overlay=false) // overlay=false to plot in a separate pane

// Input for HPI smoothing length
length = input.int(10, title="HPI Smoothing Length", minval=1)

// Input for the Scaling Factor (adjusts the magnitude of HPI values for readability)
// This value depends on the typical price and volume of the asset.
// For stocks, it might be 1000 or 10000. For futures, it can be higher.
// The ta.hpi function in Pine Script may have its own internal scaling,
// but for explicit control or manual calculation, this would be important.
// For the built-in, we just need to provide the required series.
// Pine Script's ta.hpi() does not expose a scaling factor input, so it's handled internally.

// Fetch Open Interest data. Note: Open Interest is typically available for futures and some options.
// For regular stocks/forex, this might be `na` or correspond to `volume`.
// If openInterest is `na`, ta.hpi will typically use `volume` as a fallback or return `na`.
// Check your chart's data window for 'Open Interest' to confirm availability.
var float oi = openinterest // Use 'openinterest' built-in variable

// Calculate HPI using the built-in function
// The 'openinterest' built-in variable can be used directly.
// ta.hpi(open, high, low, close, volume, openinterest, length)
hpiValue = ta.hpi(open, high, low, close, volume, oi, length)

// Plot the HPI line
plot(hpiValue, title="HPI", color=color.blue, linewidth=2)

// Plot the Zero Line as a key reference point
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted)

// Optional: Add reference levels for visual clarity (subjective based on asset)
// These levels can indicate strong buying/selling pressure.
hline(500, "Upper Ref (+500)", color.green, linestyle=hline.style_dashed)
hline(-500, "Lower Ref (-500)", color.red, linestyle=hline.style_dashed)

// Highlight regions where HPI is positive (accumulation) or negative (distribution)
fill(hpiValue, 0, color=color.new(color.lime, 90), title="Accumulation Zone")
fill(hpiValue, 0, color=color.new(color.maroon, 90), title="Distribution Zone")

Commitment Power: HPI's inclusion of Open Interest makes it particularly powerful for futures/options, as it reflects the true commitment of market participants, not just trading activity.

Practical HPI Trading Strategies

1. Zero-Line Crossovers (Money Flow Shift)

Crossovers of the zero line indicate a shift in the overall money flow from net buying to net selling, or vice versa. These signals are best used as confirmations rather than standalone entries.

//@version=5
strategy("HPI Zero Line Crossover Strategy", overlay=true)

length = input.int(10, title="HPI Smoothing Length", minval=1)
var float oi = openinterest
hpiValue = ta.hpi(open, high, low, close, volume, oi, length)

plot(hpiValue, "HPI", color.blue, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)

// Long entry: HPI crosses above zero
longCondition = ta.crossover(hpiValue, 0)

// Short entry: HPI crosses below zero
shortCondition = ta.crossunder(hpiValue, 0)

if (longCondition)
    strategy.entry("Long HPI Cross", strategy.long)

if (shortCondition)
    strategy.entry("Short HPI Cross", strategy.short)

// Basic exit: opposite signal or fixed profit/loss
strategy.close("Long HPI Cross", when=shortCondition)
strategy.close("Short HPI Cross", when=longCondition)

2. HPI Divergence (Key Reversal Signal)

Divergence between price and HPI is often considered the most powerful signal from the indicator, suggesting a weakening trend and potential reversal, as the money flow isn't confirming the price action.

//@version=5
strategy("HPI Divergence Strategy", overlay=true)

length = input.int(10, title="HPI Smoothing Length", minval=1)
var float oi = openinterest
hpiValue = ta.hpi(open, high, low, close, volume, oi, length)

plot(hpiValue, "HPI", color.blue, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)

// Simple divergence detection (conceptual, robust detection requires advanced pivot logic)
// This example looks for recent higher/lower swings in price and HPI.

// Bullish Divergence: Price lower low, HPI higher low
bullishDiv = close < close[1] and close[1] < close[2] and hpiValue > hpiValue[1] and hpiValue[1] > hpiValue[2]

// Bearish Divergence: Price higher high, HPI lower high
bearishDiv = close > close[1] and close[1] > close[2] and hpiValue < hpiValue[1] and hpiValue[1] < hpiValue[2]

// Plot shapes on the chart to indicate divergence
plotshape(bullishDiv, title="Bullish HPI Divergence", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(bearishDiv, title="Bearish HPI Divergence", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)

if (bullishDiv)
    strategy.entry("Long Divergence", strategy.long)
if (bearishDiv)
    strategy.entry("Short Divergence", strategy.short)

// Basic exit after a few bars or on opposite signal
strategy.exit("Long Divergence Exit", from_entry="Long Divergence", profit=close*0.02, loss=close*0.01)
strategy.exit("Short Divergence Exit", from_entry="Short Divergence", profit=close*0.02, loss=close*0.01)

3. HPI and Price Trend Confirmation

A sustained trend in HPI that aligns with price action provides strong confirmation of the trend's health, particularly when open interest is factored in.

//@version=5
strategy("HPI Trend Confirmation Strategy", overlay=true)

length = input.int(10, title="HPI Smoothing Length", minval=1)
var float oi = openinterest
hpiValue = ta.hpi(open, high, low, close, volume, oi, length)

plot(hpiValue, "HPI", color.blue, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)

// Price trend filter (e.g., using a long-term EMA)
priceMALength = input.int(50, title="Price MA Length", minval=1)
priceMA = ta.ema(close, priceMALength)

// Conditions for trend confirmation based on HPI and Price
// Long: Price above MA AND HPI is positive and rising
longConfirm = close > priceMA and hpiValue > 0 and hpiValue > hpiValue[1]

// Short: Price below MA AND HPI is negative and falling
shortConfirm = close < priceMA and hpiValue < 0 and hpiValue < hpiValue[1]

if (longConfirm)
    strategy.entry("Long Confirm", strategy.long)

if (shortConfirm)
    strategy.entry("Short Confirm", strategy.short)

// Basic exit: opposite signal or fixed profit/loss
strategy.close("Long Confirm", when=close < priceMA or hpiValue < 0)
strategy.close("Short Confirm", when=close > priceMA or hpiValue > 0)

Optimizing Herrick Payoff Index (HPI) Performance

To get the most from the Herrick Payoff Index in Pine Script:

Money Flow Depth: HPI's unique ability to incorporate open interest provides a deeper look into the conviction of market participants, beyond just daily transactional volume.

Common HPI Pitfalls

Conclusion

The Herrick Payoff Index (HPI) is an advanced and highly insightful momentum oscillator available in Pine Script for TradingView. By uniquely combining price, volume, and crucially, open interest, it offers traders a deeper and more comprehensive understanding of the money flow and underlying conviction driving an asset's price. While its greatest strength lies in identifying powerful divergences with price (signaling potential trend reversals), it also excels at confirming existing trends and validating shifts in market sentiment through its zero-line crossovers. By understanding its calculation, ensuring data availability (especially for open interest), thoughtfully tuning its parameters, and integrating it strategically with price action and other technical analysis tools, you can leverage HPI to enhance your pine script strategies and gain a clearer understanding of the forces driving market movement, particularly in futures and options markets.

Enhance Your Trading

Get a high-performance Pine Script analysis tool for actionable market insights, designed for traders on the move.

This strategy runs in live mode on TradingView, helping you identify potential opportunities.

Subscribe now @ $99/month