Skip to content
GetProfitable
Search
Trend

EMA Trend Ribbon

Three exponential moving averages with the gap between the fastest and slowest shaded, so the direction and the strength of a trend read at a glance.

indicator
//@version=6
indicator("EMA Trend Ribbon", "Ribbon", overlay = true)

fastLen = input.int(8, "Fast", minval = 1, group = "Settings")
midLen = input.int(21, "Middle", minval = 1, group = "Settings")
slowLen = input.int(55, "Slow", minval = 1, group = "Settings")
bull = input.color(#26A69A, "Bullish", group = "Style")
bear = input.color(#EF5350, "Bearish", group = "Style")
flat = input.color(#787B86, "Unstacked", group = "Style")

fast = ta.ema(close, fastLen)
mid = ta.ema(close, midLen)
slow = ta.ema(close, slowLen)

stacked = fast > mid and mid > slow
inverted = fast < mid and mid < slow
tone = stacked ? bull : inverted ? bear : flat

pFast = plot(fast, "Fast", color = tone)
pSlow = plot(slow, "Slow", color = color.new(tone, 40))
plot(mid, "Middle", color = color.new(tone, 20))
fill(pFast, pSlow, color = color.new(tone, 88), title = "Ribbon")

turnedUp = stacked and not stacked[1]
turnedDown = inverted and not inverted[1]
plotshape(turnedUp, "Stacked up", location = location.belowbar, style = shape.triangleup, color = bull, size = size.tiny)
plotshape(turnedDown, "Stacked down", location = location.abovebar, style = shape.triangledown, color = bear, size = size.tiny)
alertcondition(turnedUp, "Ribbon stacked up", "The EMA ribbon has stacked bullish")
alertcondition(turnedDown, "Ribbon stacked down", "The EMA ribbon has stacked bearish")
This runs in TradingView, not here
Pine Script only executes inside TradingView. Paste the source into the Pine Editor and add it to a chart to see it plotted.

What it will not do

  • Moving averages lag by construction. The ribbon confirms a move that has already happened; it does not anticipate one.
  • Stacking flips often in a range, which is where most of the false signals come from.

Written from this description

Plot 8, 21 and 55 period EMAs, colour them green when they are stacked bullish and red when stacked bearish, shade the area between the fastest and slowest, and mark the bar where they first stack.

Educational only, not financial advice. The maths is simple arithmetic on the numbers you enter; it knows nothing about your broker, fees, slippage or the market. Something wrong with it? Say so in Site Feedback.