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.
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:
The calculation of the Elder-Ray Index involves the following:
//@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)
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.
//@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")
//@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.")
//@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.")
To get the most from the Elder-Ray Index in Pinescript:
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.
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.
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