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.
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:
The calculation of the Herrick Payoff Index is complex, combining price changes, volume, and open interest. For each period (bar), the calculation generally involves:
//@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")
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.
//@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)
//@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)
//@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)
To get the most from the Herrick Payoff Index in Pinescript:
HPI's unique ability to incorporate open interest provides a deeper look into the conviction of market participants, beyond just daily transactional volume.
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.
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