//@version=6
indicator("TREND_34EMA_RD", overlay = true)
// TREND_34EMA_RD — Enhanced 34 EMA Trend Suite (Ryan DeBraal)
// DESCRIPTION
//--------------------------------------------------------------------------------------------------
// This indicator visualizes market trend behavior using a trend-adaptive 34-period EMA combined
// with ATR-based volatility analysis, trend-strength grading, and optional crossover signals.
// It is designed to deliver a fast, intuitive read on market direction, momentum quality,
// and volatility conditions.
//
// FEATURES
//--------------------------------------------------------------------------------------------------
// • 34 EMA Trend Line
// - Standard 34-period exponential moving average
// - Clean aqua color scheme for immediate visibility
// - Adjustable line thickness
//
// • Trend Strength Grading
// - Measures the absolute percent distance between price and the 34 EMA
// - Converts trend strength into a letter grade (A through F) or percent distance
// - Grade scale based on realistic 34-EMA deviation thresholds
// - Auto-updates on the last bar with a color-coded label:
// • Gray = weak trend
// • Orange = moderate trend
// • Green = strong trend
//
// • Optional Crossover Signals
// - Detects when price crosses above or below the 34 EMA
// - Displays up/down arrows at crossover points
// - Includes built-in alert conditions for bullish and bearish crossovers
//
// PURPOSE
//--------------------------------------------------------------------------------------------------
// This tool provides a clear, minimalistic framework for monitoring:
// • Early trend shifts
// • Trend continuation
// • Trend strength and momentum quality
// • Price over-extension via volatility bands
//
// The indicator is ideal for traders seeking a clean, high-signal trend-reading tool suited for
// discretionary, algorithmic, or confirmation-based trading approaches.
// Inputs
lineThickness = input.int(1)
emaLength = input.int(34, "EMA Length", minval = 1)
showTrendLabel = input.bool(true, "Show Trend Strength Label")
labelMode = input.string("Grade", "Label Mode", options = ["Grade", "Percent"])
showCrossMarks = input.bool(false, "Show Crossover Arrows")
// EMA
emaLine = ta.ema(close, emaLength)
plot(emaLine, "34 EMA", color.new(color.orange, 50), lineThickness)
// Trend Strength (distance from EMA)
distancePct = emaLine != 0 ? math.abs(close - emaLine) / emaLine * 100.0 : 0.0
// Grade mapping
grade = distancePct >= 20 ? "A" : distancePct >= 14 ? "A-" : distancePct >= 11 ? "B+" : distancePct >= 8.5 ? "B" : distancePct >= 6.5 ? "B-" : distancePct >= 5 ? "C+" : distancePct >= 3.5 ? "C" : distancePct >= 2.5 ? "C-" : distancePct >= 1.5 ? "D+" : distancePct >= 0.75 ? "D" : distancePct >= 0.25 ? "D-" : "F"
// Label color
labelColor = distancePct < 2.5 ? color.new(color.gray, 10) : distancePct < 6.5 ? color.new(color.orange, 0) : color.new(color.green, 0)
// Trend label
var label trendLabel = na
if showTrendLabel and barstate.islast
if not na(trendLabel)
label.delete(trendLabel)
labelText = labelMode == "Percent" ? str.tostring(distancePct, "#.0") + "%" : grade
trendLabel := label.new(bar_index, emaLine, labelText, style=label.style_label_left, color=labelColor, textcolor=color.white, size=size.small)
// Crossovers
bullCross = ta.crossover(close, emaLine)
bearCross = ta.crossunder(close, emaLine)
plotshape(showCrossMarks and bullCross, title="Bullish", color=color.new(color.green, 0), style=shape.triangleup, location=location.belowbar, size=size.tiny)
plotshape(showCrossMarks and bearCross, title="Bearish", color=color.new(color.red, 0), style=shape.triangledown, location=location.abovebar, size=size.tiny)
// Alerts
alertcondition(bullCross, "Bullish EMA Crossover", "Price crossed ABOVE the 34 EMA")
alertcondition(bearCross, "Bearish EMA Crossover", "Price crossed BELOW the 34 EMA")