Logo
OFFLINEPIXEL
/ pinescript-strategies / pine-script-elder-ray-index

$ Pinescript Elder-Ray Index

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

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

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

Basic Elder-Ray Index Implementation in Pinescript

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

Trend Filter First

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.

05

Practical Elder-Ray Index Trading Strategies

06

1. Trend Confirmation with Bull and Bear Power

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

2. Reversal Signals with Bull Power

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

3. Reversal Signals with Bear Power

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

Optimizing Elder-Ray Index Performance

To get the most from the Elder-Ray Index in Pinescript:

  • Trend is Paramount: Always use the EMA to determine the direction of the trend first. Only look for bullish signals in uptrends (or when an uptrend is beginning/confirming) and bearish signals in downtrends.
  • Combine with Price Action: Elder-Ray works best when its signals are confirmed by price action. For example, a bullish Bull Power signal is stronger if the price forms a bullish candlestick pattern or breaks a short-term resistance.
  • Divergence is Key: Pay close attention to divergence between Bull/Bear Power and price. If price makes a new high but Bull Power makes a lower high, it signals weakening buying pressure. If price makes a new low but Bear Power makes a higher low (less negative), it signals weakening selling pressure.
  • Not a Standalone Indicator: Elder-Ray provides valuable insights into power, but it's not a complete system. Combine it with other indicators (e.g., volume, other momentum oscillators) for better confirmation and risk management.
  • Parameter Tuning: The default 13-period EMA is widely used, but you can experiment with other lengths (e.g., 20 or 26) to suit different timeframes or asset volatilities.
10

The "Elder" in Elder-Ray

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.

11

Common Elder-Ray Index Pitfalls

  • Whipsaws in Sideways Markets: In choppy or range-bound markets, the EMA will flatten, and Bull/Bear Power might oscillate frequently around zero, generating false signals. Elder-Ray performs best in trending environments.
  • Lag: As it uses an EMA, the Elder-Ray Index has some inherent lag and will not pinpoint exact tops or bottoms immediately.
  • Requires Understanding of Price Action: Interpreting Elder-Ray effectively often requires a good understanding of candlestick patterns and support/resistance levels.
  • Subjectivity: Interpreting nuances like "higher low" or "lower high" in the histograms can sometimes be subjective without robust pivot detection.
  • Not for Scalping: Due to its reliance on an EMA, it's generally not suited for very short-term scalping strategies.
12

Conclusion

Conclusion

The Elder-Ray Index is a powerful and insightful technical indicator in Pinescript 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 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