Pine Script Elder-Ray Index

Master this powerful indicator by Alexander Elder in TradingView's Pine Script, revealing the true strength of bulls and bears in relation to the prevailing trend.

Subscribe now @ $99/month

What is the Elder-Ray Index?

The Elder-Ray Index, developed by Dr. Alexander Elder (author of "Trading for a Living"), is a technical indicator that measures the power of buyers and sellers in relation to a prevailing trend. It consists of three components:

  1. An Exponential Moving Average (EMA) (typically 13-period) which defines the trend.
  2. Bull Power: Measures the ability of buyers to push prices above the EMA.
  3. Bear Power: Measures the ability of sellers to push prices below the EMA.

The core idea behind the Elder-Ray Index is that an EMA acts as a flexible equilibrium price. Bull Power and Bear Power then quantify how far the actual price deviates from this equilibrium, indicating the strength of the underlying buying or selling pressure. It is typically displayed as two separate histograms, one for Bull Power and one for Bear Power, both oscillating around a zero line.

In Pine Script, the Elder-Ray Index is a valuable tool for traders seeking to understand the conviction behind price moves, identify potential reversals, and confirm trend strength by analyzing the relative power of bulls and bears.

Components and Calculation

The calculation of the Elder-Ray Index involves the following:

  1. EMA (Exponential Moving Average): This is the baseline for measurement.
    `EMA_Value = ta.ema(close, length)` (e.g., 13 periods)
  2. Bull Power: Measures the strength of buying pressure.
    `Bull Power = High - EMA_Value`
    This value is plotted as a histogram. Positive values indicate that bulls are pushing the price above the average; negative values mean the high is still below the average.
  3. Bear Power: Measures the strength of selling pressure.
    `Bear Power = Low - EMA_Value`
    This value is also plotted as a histogram. Negative values indicate that bears are pushing the price below the average; positive values mean the low is still above the average.

Both Bull Power and Bear Power are often smoothed with an EMA themselves to reduce noise (e.g., a 13-period EMA of Bull Power and Bear Power, which is how TradingView's built-in version often operates).

Basic Elder-Ray Index Implementation in Pine Script

Pine Script v5 makes it straightforward to calculate the components of the Elder-Ray Index using `ta.ema()`.

//@version=5
indicator("My Elder-Ray Index", overlay=false, format=format.price) // overlay=false to plot in a separate pane

// Input for EMA length (often 13)
emaLength = input.int(13, title="EMA Length", minval=1)

// Calculate the EMA baseline
emaValue = ta.ema(close, emaLength)

// Calculate Bull Power
bullPower = high - emaValue

// Calculate Bear Power
bearPower = low - emaValue

// Plot Bull Power as a histogram
plot(bullPower, title="Bull Power", style=plot.style_columns, color=bullPower >= 0 ? color.green : color.red)

// Plot Bear Power as a histogram (typically inverted or distinct color)
plot(bearPower, title="Bear Power", style=plot.style_columns, color=bearPower <= 0 ? color.maroon : color.lime) // Using maroon for negative, lime for positive

// Plot the Zero Line
hline(0, "Zero Line", color.gray, linestyle=hline.style_solid)

Trend Filter First: Alexander Elder emphasizes that Elder-Ray should always be used in conjunction with the EMA that defines the trend. Only consider Bull Power signals when the EMA is rising, and Bear Power signals when the EMA is falling.

Practical Elder-Ray Index Trading Strategies

1. Trend Confirmation with Bull and Bear Power

This strategy uses the direction of the EMA to define the trend, and then looks for Bull Power and Bear Power to confirm or diverge from that trend.

//@version=5
strategy("Elder-Ray Trend Confirmation", overlay=true)

emaLength = input.int(13, title="EMA Length", minval=1)
emaValue = ta.ema(close, emaLength)

// Plot EMA on price chart
plot(emaValue, "EMA", color.blue, linewidth=2, overlay=true)

bullPower = high - emaValue
bearPower = low - emaValue

// Plot Bull and Bear Power histograms in a separate pane
plot(bullPower, title="Bull Power", style=plot.style_columns, color=bullPower >= 0 ? color.green : color.gray, display=display.pane_only)
plot(bearPower, title="Bear Power", style=plot.style_columns, color=bearPower <= 0 ? color.red : color.gray, display=display.pane_only)
hline(0, "Zero Line", color.black, display=display.pane_only)

// Trend definition
isUptrend = emaValue > emaValue[1]
isDowntrend = emaValue < emaValue[1]

// Entry/Exit conditions based on trend and power
if (isUptrend and bullPower > 0 and bullPower > bullPower[1]) // Bullish trend, bull power increasing
    strategy.entry("Long", strategy.long)

if (isDowntrend and bearPower < 0 and bearPower < bearPower[1]) // Bearish trend, bear power increasing
    strategy.entry("Short", strategy.short)

// Example exit: if trend reverses or power wanes
if (isUptrend and (bearPower > 0 or bullPower < bullPower[1]))
    strategy.close("Long")

if (isDowntrend and (bullPower < 0 or bearPower > bearPower[1]))
    strategy.close("Short")

2. Reversal Signals with Bull Power

Even in a downtrend, Bull Power can signal potential bottoms or rallies if it starts to increase while still negative, or turns positive. This indicates buyers stepping in.

//@version=5
indicator("Elder-Ray Bull Power Reversal", overlay=true)

emaLength = input.int(13, title="EMA Length", minval=1)
emaValue = ta.ema(close, emaLength)

bullPower = high - emaValue
bearPower = low - emaValue

// Plot Bull and Bear Power histograms in a separate pane
plot(bullPower, title="Bull Power", style=plot.style_columns, color=bullPower >= 0 ? color.green : color.red)
plot(bearPower, title="Bear Power", style=plot.style_columns, color=bearPower <= 0 ? color.maroon : color.fuchsia)
hline(0, "Zero Line", color.gray)

// Check for downtrend (EMA falling)
isDowntrend = emaValue < emaValue[1]

// Bullish Reversal Condition (Simplified for example)
// Bear Power is negative but rising (less negative), Bull Power is making a higher low or turning positive
bullishReversalSignal = isDowntrend and bearPower > bearPower[1] and bullPower > bullPower[1] and bullPower[1] < 0

plotshape(bullishReversalSignal, title="Bull Reversal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
alertcondition(bullishReversalSignal, "Bullish Elder-Ray Reversal", "Potential bullish reversal based on Elder-Ray Bull Power.")

3. Reversal Signals with Bear Power

Conversely, even in an uptrend, Bear Power can signal potential tops or pullbacks if it starts to decline while still positive, or turns negative. This indicates sellers stepping in.

//@version=5
indicator("Elder-Ray Bear Power Reversal", overlay=true)

emaLength = input.int(13, title="EMA Length", minval=1)
emaValue = ta.ema(close, emaLength)

bullPower = high - emaValue
bearPower = low - emaValue

// Plot Bull and Bear Power histograms in a separate pane
plot(bullPower, title="Bull Power", style=plot.style_columns, color=bullPower >= 0 ? color.green : color.red)
plot(bearPower, title="Bear Power", style=plot.style_columns, color=bearPower <= 0 ? color.maroon : color.fuchsia)
hline(0, "Zero Line", color.gray)

// Check for uptrend (EMA rising)
isUptrend = emaValue > emaValue[1]

// Bearish Reversal Condition (Simplified for example)
// Bull Power is positive but falling, Bear Power is making a lower high or turning negative
bearishReversalSignal = isUptrend and bullPower < bullPower[1] and bearPower < bearPower[1] and bearPower[1] > 0

plotshape(bearishReversalSignal, title="Bear Reversal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
alertcondition(bearishReversalSignal, "Bearish Elder-Ray Reversal", "Potential bearish reversal based on Elder-Ray Bear Power.")

Optimizing Elder-Ray Index Performance

To get the most from the Elder-Ray Index in Pine Script:

The "Elder" in Elder-Ray: Dr. Alexander Elder's approach emphasizes understanding market psychology (bulls vs. bears) and combining multiple indicators for confluence, of which Elder-Ray is a core component.

Common Elder-Ray Index Pitfalls

Conclusion

The Elder-Ray Index is a powerful and insightful technical indicator in Pine Script for TradingView, designed by Dr. Alexander Elder to quantify the underlying strength of buyers and sellers relative to the prevailing trend. By dissecting market momentum into "Bull Power" and "Bear Power," it provides a unique perspective on the market's internal dynamics. Whether used for confirming trend strength, spotting early signs of reversal through power shifts, or identifying powerful divergences, the Elder-Ray Index offers valuable insights. By understanding its calculation, thoughtfully combining it with price action and the EMA trend filter, you can leverage this indicator to enhance your trading decisions and gain a deeper understanding of market forces.

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