Logo
OFFLINEPIXEL
/ pinescript-strategies / pine-script-mass-index

$ Pinescript Mass Index

Master this unique indicator in TradingView's Pinescript that identifies potential trend reversals by measuring the widening and narrowing of the trading range.

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 Mass Index?

The Mass Index, developed by Donald Dorsey, is a technical indicator that aims to predict trend reversals by measuring the expanding and contracting trading range (high-low difference) over a specific period. Unlike momentum indicators that focus on price speed or direction, the Mass Index focuses on volatility compression and expansion. It signals an impending trend reversal when the trading range widens significantly, often referred to as the "reversal bulge." The indicator sums up a series of Exponential Moving Averages (EMAs) of the high-low range.

In Pinescript, the Mass Index is a valuable tool for traders who believe that significant shifts in price range often precede a change in the prevailing trend, allowing them to anticipate potential reversals.

02

Components and Calculation

The calculation of the Mass Index involves several steps:

  1. Single Period High-Low Range: `Range = High - Low`
  2. Exponential Moving Average (EMA) of the Range: Calculate an EMA of the `Range` over a specified `emaPeriod` (e.g., 9 periods).
    `EMA_Range = ta.ema(Range, emaPeriod)`
  3. Double EMA of the Range: Calculate another EMA of the `EMA_Range` (smoothed EMA_Range) over the same `emaPeriod`.
    `Double_EMA_Range = ta.ema(EMA_Range, emaPeriod)`
  4. Ratio: Divide the `EMA_Range` by the `Double_EMA_Range`.
    `Ratio = EMA_Range / Double_EMA_Range`
  5. Mass Index Formula: Sum the `Ratio` over a longer `sumPeriod` (e.g., 25 periods).
    `Mass Index = sum(Ratio, sumPeriod)`
03

Basic Mass Index Implementation in Pinescript

pine-script@terminal
//@version=5
indicator("My Mass Index", overlay=false) // overlay=false to plot in a separate pane

// Inputs for Mass Index lengths
emaPeriod = input.int(9, title="EMA Period", minval=1)
sumPeriod = input.int(25, title="Summation Period", minval=1)

// Calculate Mass Index using the built-in function
massIndexValue = ta.massindex(emaPeriod, sumPeriod)

// Plot the Mass Index line
plot(massIndexValue, title="Mass Index", color=color.blue, linewidth=2)

// Plot critical trigger lines
// The 27 level is the "reversal bulge" threshold
hline(27, "Reversal Threshold (27)", color.red, linestyle=hline.style_dashed)
// The 26.5 level is a confirmation line, often watched for downside breach after 27 is hit
hline(26.5, "Confirmation Line (26.5)", color.gray, linestyle=hline.style_dashed)
$ ✓ Compiled successfully
04

"Reversal Bulge"

"Reversal Bulge"

The core signal of the Mass Index is when it rises above 27 and then falls back below 26.5. This pattern suggests an imminent trend reversal.

05

Practical Mass Index Trading Strategies

06

1. The Reversal Bulge (Primary Strategy)

pine-script@terminal
//@version=5
strategy("Mass Index Reversal Bulge Strategy", overlay=true)

emaPeriod = input.int(9, title="EMA Period", minval=1)
sumPeriod = input.int(25, title="Summation Period", minval=1)

massIndexValue = ta.massindex(emaPeriod, sumPeriod)

plot(massIndexValue, "Mass Index", color.blue, display=display.pane_only)
hline(27, "Reversal Threshold", color.red, linestyle=hline.style_dashed, display=display.pane_only)
hline(26.5, "Confirmation Line", color.gray, linestyle=hline.style_dashed, display=display.pane_only)

// Define conditions for the reversal bulge
// Mass Index touches 27 (or higher)
hits27 = massIndexValue >= 27
// Mass Index falls back below 26.5 AFTER hitting 27
// We need to keep track if 27 was hit recently
var bool hit27Recently = false
if (hits27)
    hit27Recently := true
if (massIndexValue[1] > 26.5 and massIndexValue <= 26.5 and hit27Recently) // Crosses down 26.5
    hit27Recently := false // Reset after signal

// The strategy assumes you are in a trend and this signal indicates reversal of that trend.
// For practical use, you'd combine this with a trend identification method.
// Here, we'll use a simple moving average for trend direction for example purposes.
trendLength = input.int(200, title="Trend EMA Length", minval=10)
trendEMA = ta.ema(close, trendLength)

// Reversal signal is active when Mass Index falls below 26.5 after hitting 27
reversalSignal = massIndexValue[1] > 26.5 and massIndexValue <= 26.5 and (massIndexValue[2] >= 27 or massIndexValue[3] >= 27 or massIndexValue[4] >= 27) // Check if 27 was hit recently

// If price is above long-term EMA, it's an uptrend, so reversal means short.
// If price is below long-term EMA, it's a downtrend, so reversal means long.
if (reversalSignal)
    if (close > trendEMA) // Was in uptrend, now expecting reversal down
        strategy.entry("Short Reversal", strategy.short)
    else if (close < trendEMA) // Was in downtrend, now expecting reversal up
        strategy.entry("Long Reversal", strategy.long)

// Add exits based on time or profit target/stop loss for robust strategy
// strategy.close_all() after X bars or at profit target/stop loss
$ ✓ Compiled successfully
07

2. Confirmation of Strength/Weakness (Less Common)

pine-script@terminal
//@version=5
indicator("Mass Index Volatility State", overlay=true)

emaPeriod = input.int(9, title="EMA Period", minval=1)
sumPeriod = input.int(25, title="Summation Period", minval=1)

massIndexValue = ta.massindex(emaPeriod, sumPeriod)

plot(massIndexValue, "Mass Index", color.blue)
hline(27, "Reversal Threshold", color.red, linestyle=hline.style_dashed)
hline(26.5, "Confirmation Line", color.gray, linestyle=hline.style_dashed)

// Highlight periods of volatility expansion (approaching 27)
var bool approaching27 = false
if (massIndexValue >= 26 and massIndexValue < 27)
    approaching27 := true
else
    approaching27 := false

// Highlight periods of range contraction (below 26.5)
var bool below26_5 = false
if (massIndexValue < 26.5)
    below26_5 := true
else
    below26_5 := false

bgcolor(approaching27 ? color.new(color.yellow, 90) : na, title="Volatility Expanding")
bgcolor(below26_5 ? color.new(color.blue, 90) : na, title="Range Contracting")
$ ✓ Compiled successfully
08

Optimizing Mass Index Performance

To get the most from the Mass Index in Pinescript:

  • Focus on the "Reversal Bulge": This is its primary and most reliable signal. Don't try to force other interpretations, as they might not be as robust.
  • Combine with Trend Identification: The Mass Index tells you *when* a reversal might occur, but it doesn't tell you *what the current trend is*. Always use it in conjunction with a trend-following indicator (e.g., moving averages, ADX) to understand the trend that is being reversed. This allows you to apply the reversal signal correctly (e.g., a bullish reversal if the prior trend was down).
  • Confirm with Price Action: After the Mass Index signals a reversal, wait for confirmation from price action (e.g., a candlestick reversal pattern, a break of a short-term support/resistance level, or a shift in market structure).
  • Standard Parameters: The default lengths (9, 25) are widely used and recommended. Experimenting with other values might lead to less reliable signals as these parameters are tuned for the "reversal bulge" phenomenon.
  • Volume Analysis: Often, significant range expansions (leading to the Mass Index bulge) are accompanied by high volume, which can add confirmation to the potential reversal.
09

Not a Directional Indicator

Not a Directional Indicator

The Mass Index is not a directional indicator. It doesn't tell you *which way* the price will go, only *that a reversal is likely*. The direction must be inferred from the preceding trend or other indicators.

10

Common Mass Index Pitfalls

  • False Signals: Like all indicators, the Mass Index can generate false signals. The "reversal bulge" doesn't guarantee a reversal; it only indicates a higher probability. Confirmation is key.
  • Lag: The Mass Index is a lagging indicator due to its reliance on multiple moving averages. Signals will not occur at the exact top or bottom of a trend.
  • Not for All Market Conditions: It performs best in trending markets where a clear reversal can be identified. In prolonged sideways or extremely choppy markets, the signals might be less clear or more frequent, leading to whipsaws.
  • Interpretation Complexity: Understanding the precise "reversal bulge" pattern (crossing 27, then falling below 26.5) requires careful observation. Missing these specific nuances can lead to misinterpretation.
  • Requires Volume Data: Although not directly using `volume` in its calculation in `ta.massindex`, the concept of range expansion/contraction is implicitly related to market activity. However, unlike MFI or FI, it doesn't directly leverage the `volume` variable.
  • Not a Standalone Indicator: Mass Index is a specialized tool best used in conjunction with a complete trading plan that includes trend identification, risk management, and confirmation from other analysis methods.
11

Conclusion

Conclusion

The Mass Index is a unique and insightful technical indicator in Pinescript for TradingView. Its primary strength lies in its ability to predict potential trend reversals by analyzing the expansion and contraction of an asset's trading range, specifically through the "reversal bulge" pattern. By understanding its calculation and focusing on its key signal (rising above 27 then falling below 26.5), and by combining it with robust trend identification and price action confirmation, traders can leverage the Mass Index to anticipate significant market turns. While it requires careful interpretation and integration into a broader strategy, the Mass Index offers a powerful edge for identifying high-probability reversal opportunities.

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