Logo
OFFLINEPIXEL
/ pinescript-strategies / pine-script-herrick-payoff-index

$ Pinescript Herrick Payoff Index (HPI)

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

500+ Clients Helped
100% Satisfaction
Live Trading Ready
⚠️
Trading financial markets carries risk. All content (PineScript code, indicators, strategies) on this website is for educational purposes only. Past performance is not indicative of future results. By using any code or information from this site, you agree that you are solely responsible for your trading decisions. The author disclaims all liability for any losses incurred. To gain from experts experiences, You can always try our Invite Only Scripts
01

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:

  • Confirm price trends: A rising HPI confirms an uptrend, and a falling HPI confirms a downtrend, especially in futures markets where open interest is a key factor.
  • Identify divergences: When price and HPI move in opposite directions, it can signal an impending trend reversal.
  • Gauge market conviction: Provides insight into the commitment of market participants.
02

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.
03

Basic Herrick Payoff Index (HPI) Implementation in Pinescript

pine-script@terminal
//@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 Pinescript 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.
// Pinescript'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")
$ ✓ Compiled successfully
04

Commitment Power

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.

05

Practical HPI Trading Strategies

06

1. Zero-Line Crossovers (Money Flow Shift)

pine-script@terminal
//@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)
$ ✓ Compiled successfully
07

2. HPI Divergence (Key Reversal Signal)

pine-script@terminal
//@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.new(color.green, 0), style=shape.triangleup, size=size.small)
plotshape(bearishDiv, title="Bearish HPI Divergence", location=location.abovebar, color=color.new(color.red, 0), 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)
$ ✓ Compiled successfully
08

3. HPI and Price Trend Confirmation

pine-script@terminal
//@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)
$ ✓ Compiled successfully
09

Optimizing Herrick Payoff Index (HPI) Performance

To get the most from the Herrick Payoff Index in Pinescript:

  • Data Availability: HPI is most effective when reliable open interest data is available. For assets without open interest, the indicator will still calculate (often using volume as a proxy), but its unique advantage is diminished. Verify open interest data for your chosen asset/timeframe.
  • Focus on Divergence: HPI's most robust and actionable signals often come from divergences with price. These are reliable indicators of weakening trends and potential reversals, as they reveal a disconnect between price and underlying money flow.
  • Parameter Tuning: The `length` parameter smooths the HPI. Shorter lengths make it more responsive but potentially noisy. Longer lengths will smooth it out but introduce more lag. Experiment to find a balance for your trading style and asset.
  • Combine with Price Action: Always confirm HPI signals with price action. A bullish divergence is stronger if price also forms a bullish reversal candlestick pattern or breaks a short-term resistance.
  • Trend Context: Use HPI in the context of the larger trend. In an uptrend, focus on bullish divergences and zero-line bounces for long entries. In a downtrend, focus on bearish divergences and zero-line rejections for short entries.
  • Volatile Markets: HPI can be particularly useful in volatile markets where rapid price swings might make simpler volume indicators less clear. The inclusion of range and open interest can provide more stable insights.
10

Money Flow Depth

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.

11

Common HPI Pitfalls

  • Open Interest Dependency: If open interest data is not available or is inconsistent for an asset, HPI's primary advantage is lost, and it might behave similarly to other volume-price indicators.
  • Complexity and Interpretation: HPI's calculation is more complex than basic volume indicators, which can make its nuanced interpretation challenging for beginners.
  • Lag: As a smoothed, cumulative indicator, HPI inherently lags price action. Its signals are for confirmation or long-term trend shifts rather than immediate entries.
  • False Signals: In very choppy or low-volume markets (especially those without strong open interest participation), HPI can generate ambiguous signals or whipsaws around the zero line.
  • Not a Standalone Indicator: HPI provides crucial insights but should never be used in isolation. It works best as a confirming or filtering indicator within a broader trading strategy.
12

Conclusion

Conclusion

The Herrick Payoff Index (HPI) is an advanced and highly insightful momentum oscillator available in Pinescript 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 Pinescript 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 Pinescript 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.

Get Pinescript Strategy