Moving Averages & Trend Indicators
ATR, SMA/EMA/WMA crosses, MA color filters, multiple moving average ribbons, VWAP and VWMA, and the Ichimoku Cloud in PineScript.
From Thrive on YouTube
Watch the matching Thrive video
ADX Indicator Explained: Is It a Trend or Just Chop?
Part of Charting and Market Structure. Education only. Not financial advice.
Building an ATR Indicator
The Average True Range (ATR) measures market volatility by calculating the average of the true range over a specified period. True range accounts for gaps between bars. It is the greatest of the current high minus the current low, the absolute value of the current high minus the previous close, and the absolute value of the current low minus the previous close. In crypto markets like BTC/USDT, ATR is indispensable for sizing stop losses and gauging whether volatility is expanding or contracting.
1//@version=52indicator("Custom ATR", overlay=false)34length = input.int(14, "ATR Length", minval=1)5smoothed = input.bool(true, "Use Smoothed ATR (RMA)")67trueRange = math.max(high - low,8 math.max(math.abs(high - close[1]),9 math.abs(low - close[1])))1011atrVal = smoothed ? ta.rma(trueRange, length) : ta.sma(trueRange, length)12atrPct = atrVal / close * 1001314// Volatility state classification15atrSMA = ta.sma(atrVal, length * 3)16isHigh = atrVal > atrSMA * 1.517isLow = atrVal < atrSMA * 0.51819atrColor = isHigh ? color.new(color.red, 20) :20 isLow ? color.new(color.green, 20) :21 color.new(color.gray, 20)2223plot(atrVal, "ATR", atrColor, 2)24plot(atrSMA, "ATR SMA", color.new(color.yellow, 40), 1, plot.style_line)25hline(0, "Zero", color.new(color.gray, 80))| True Range | max(high - low, |high - prev close|, |low - prev close|). Captures gap moves that high-low alone misses. |
| RMA Smoothing | Wilder's smoothing method (default). Gives more weight to recent bars, responds faster to volatility changes. |
| SMA Smoothing | Equal-weight average. Smoother output but slower to react. Better for longer-term volatility assessment. |
| ATR as Percentage | ATR / close * 100. Normalizes across assets: lets you compare BTC volatility to ETH or SOL directly. |
Moving Average Crossover Indicators
Moving average crossovers remain the foundation of trend-following systems. The concept is simple: when a faster MA crosses above a slower MA, momentum is shifting bullish. When it crosses below, momentum shifts bearish. The key is selecting the right MA types and lengths for your timeframe. On a daily BTC chart, the 50/200 SMA crossover (the "golden cross" and "death cross") has historically signaled major trend shifts.
1//@version=52indicator("MA Crossover Suite", overlay=true)34// Inputs5fastLen = input.int(9, "Fast Length", minval=1)6slowLen = input.int(21, "Slow Length", minval=1)7maType = input.string("EMA", "MA Type",8 options=["SMA", "EMA", "WMA", "VWMA"])910// MA calculation helper11getMA(src, len, typ) =>12 switch typ13 "SMA" => ta.sma(src, len)14 "EMA" => ta.ema(src, len)15 "WMA" => ta.wma(src, len)16 "VWMA" => ta.vwma(src, len)1718fastMA = getMA(close, fastLen, maType)19slowMA = getMA(close, slowLen, maType)2021bullCross = ta.crossover(fastMA, slowMA)22bearCross = ta.crossunder(fastMA, slowMA)2324// Trend color25trendUp = fastMA > slowMA26fastColor = trendUp ? color.new(color.green, 0) : color.new(color.red, 0)27slowColor = trendUp ? color.new(color.green, 40) : color.new(color.red, 40)2829plot(fastMA, "Fast MA", fastColor, 2)30plot(slowMA, "Slow MA", slowColor, 2)3132plotshape(bullCross, "Bull Cross", shape.triangleup,33 location.belowbar, color.green, size=size.small)34plotshape(bearCross, "Bear Cross", shape.triangledown,35 location.abovebar, color.red, size=size.small)3637bgcolor(bullCross ? color.new(color.green, 90) :38 bearCross ? color.new(color.red, 90) : na)MA Color Filter: Candle Coloring by Trend
One of the most immediately useful visual tools is coloring candlesticks based on their relationship to a moving average. When price is above the MA, candles are green. Below, they are red. This transforms your chart into an instant trend map. You can see at a glance which periods were bullish and which were bearish without adding extra lines.
1//@version=52indicator("MA Color Filter", overlay=true)34maLen = input.int(21, "MA Length")5src = input.source(close, "Source")6ema = ta.ema(src, maLen)78dist = (close - ema) / ema * 1009strength = math.min(math.abs(dist) * 15, 80)1011bullColor = color.new(color.green, 100 - strength)12bearColor = color.new(color.red, 100 - strength)1314barcolor(close > ema ? bullColor : bearColor)15plot(ema, "EMA", color.new(color.white, 60), 1)Multiple Moving Average Ribbon
A moving average ribbon plots six or more MAs with incrementing lengths, creating a visual "ribbon" effect. When all MAs are fanned out in order (shortest on top for uptrends), the trend is strong and clean. When the MAs compress and tangle, the market is in consolidation. The ribbon provides richer trend context than a single MA crossover. You can see trend strength, momentum shifts, and compression zones at a glance.
1//@version=52indicator("MA Ribbon", overlay=true)34baseLen = input.int(10, "Base Length", minval=2)5mult = input.float(1.618, "Length Multiplier", step=0.1)6maType = input.string("EMA", "Type", options=["SMA", "EMA"])78calc(len) => maType == "EMA" ? ta.ema(close, len) : ta.sma(close, len)910ma1 = calc(int(baseLen))11ma2 = calc(int(baseLen * mult))12ma3 = calc(int(baseLen * math.pow(mult, 2)))13ma4 = calc(int(baseLen * math.pow(mult, 3)))14ma5 = calc(int(baseLen * math.pow(mult, 4)))15ma6 = calc(int(baseLen * math.pow(mult, 5)))1617bullish = ma1 > ma2 and ma2 > ma3 and ma3 > ma41819p1 = plot(ma1, "MA 1", color.new(#5ce1e6, 0), 2)20p2 = plot(ma2, "MA 2", color.new(#5ce1e6, 20), 1)21p3 = plot(ma3, "MA 3", color.new(#5ce1e6, 40), 1)22p4 = plot(ma4, "MA 4", color.new(#ff4895, 40), 1)23p5 = plot(ma5, "MA 5", color.new(#ff4895, 20), 1)24p6 = plot(ma6, "MA 6", color.new(#ff4895, 0), 2)2526fill(p1, p6, bullish ? color.new(color.green, 88) :27 color.new(color.red, 88))Fibonacci-spaced ribbons
VWAP vs VWMA: Volume-Weighted Averages
VWAP (Volume Weighted Average Price) and VWMA (Volume Weighted Moving Average) both incorporate volume, but they work differently. VWAP is a cumulative calculation that resets every session. It represents the average price weighted by volume from the session open. VWMA is a rolling window calculation like any other MA but weights each bar's price by its volume. For crypto trading, VWAP is the institutional benchmark for intraday execution quality, while VWMA is better for trend analysis on higher timeframes.
1//@version=52indicator("VWAP vs VWMA", overlay=true)34vwmaLen = input.int(20, "VWMA Length")56// Built-in VWMA7vwmaVal = ta.vwma(close, vwmaLen)89// Manual VWAP (cumulative, session-resetting)10var float cumVol = 0.011var float cumVolPrc = 0.01213isNewSession = ta.change(time("D")) != 014if isNewSession15 cumVol := 0.016 cumVolPrc := 0.01718cumVol += volume19cumVolPrc += close * volume20vwapVal = cumVolPrc / cumVol2122plot(vwapVal, "VWAP", color.new(color.orange, 0), 2)23plot(vwmaVal, "VWMA", color.new(#5ce1e6, 0), 2)2425// Distance from VWAP as background intensity26vwapDist = (close - vwapVal) / vwapVal * 10027bgcolor(vwapDist > 0 ? color.new(color.green, 93) :28 color.new(color.red, 93))| VWAP | Cumulative, resets each session. Standard benchmark for institutional fills. Best on intraday timeframes (1m–1H). |
| VWMA | Rolling window, no reset. Behaves like an EMA that weights high-volume bars more. Works on any timeframe. |
| Above VWAP | Price trading above VWAP means buyers are aggressive: average buyer is in profit for the session. |
| Below VWAP | Price below VWAP means sellers dominate: average buyer is underwater for the session. |
Ichimoku Cloud: Complete Implementation
The Ichimoku Kinko Hyo ("one-glance equilibrium chart") is a complete trend system in a single indicator. It uses five lines and a colored cloud to show support, resistance, trend direction, and momentum simultaneously. Originally designed for Japanese rice markets, it is exceptionally effective on crypto because crypto trades 24/7 with strong trends. The standard settings (9, 26, 52) map to 1.5 weeks, 1 month, and 2 months on a daily chart.
1//@version=52indicator("Ichimoku Cloud", overlay=true)34tenkanLen = input.int(9, "Tenkan-sen (Conversion)")5kijunLen = input.int(26, "Kijun-sen (Base)")6senkouBLen = input.int(52, "Senkou Span B")7displacement = input.int(26, "Displacement")89// Donchian midline helper10donchian(len) => (ta.highest(high, len) + ta.lowest(low, len)) / 21112tenkan = donchian(tenkanLen)13kijun = donchian(kijunLen)14senkouA = (tenkan + kijun) / 215senkouB = donchian(senkouBLen)16chikou = close1718// Plots19plot(tenkan, "Tenkan-sen", color.new(#5ce1e6, 0), 1)20plot(kijun, "Kijun-sen", color.new(#ff4895, 0), 1)21plot(chikou, "Chikou Span", color.new(color.green, 40), 1,22 offset=-displacement)2324pA = plot(senkouA, "Senkou A", color.new(color.green, 60), 1,25 offset=displacement)26pB = plot(senkouB, "Senkou B", color.new(color.red, 60), 1,27 offset=displacement)2829fill(pA, pB, senkouA >= senkouB ?30 color.new(color.green, 85) : color.new(color.red, 85),31 title="Cloud Fill")Tenkan-sen (Conversion Line)
Kijun-sen (Base Line)
Senkou Span A & B (The Cloud)
Chikou Span (Lagging Span)
Complete Trend Dashboard: ATR + MAs + Ichimoku
This indicator combines everything from this lesson into a single trend dashboard. It scores trend strength using MA alignment, Ichimoku position, and ATR state, then displays a summary table on the chart. This is the kind of tool professional traders build to get a single-glance assessment of market conditions.
1//@version=52indicator("Trend Dashboard", overlay=true)34ema21 = ta.ema(close, 21)5ema50 = ta.ema(close, 50)6ema200 = ta.ema(close, 200)7atr = ta.atr(14)8atrSMA = ta.sma(atr, 42)910// Ichimoku components11tenkan = (ta.highest(high, 9) + ta.lowest(low, 9)) / 212kijun = (ta.highest(high, 26) + ta.lowest(low, 26)) / 213senkouA = (tenkan + kijun) / 214senkouB = (ta.highest(high, 52) + ta.lowest(low, 52)) / 21516// Scoring: 0-5 bullish conditions17score = (close > ema21 ? 1 : 0)18score += (ema21 > ema50 ? 1 : 0)19score += (close > ema200 ? 1 : 0)20score += (close > math.max(senkouA, senkouB) ? 1 : 0)21score += (tenkan > kijun ? 1 : 0)2223volState = atr > atrSMA * 1.3 ? "HIGH" :24 atr < atrSMA * 0.7 ? "LOW" : "NORMAL"2526if barstate.islast27 t = table.new(position.top_right, 2, 5,28 bgcolor=color.new(#1a1a2e, 10),29 border_width=1,30 border_color=color.new(color.gray, 70))31 table.cell(t, 0, 0, "Trend Score", text_color=color.gray,32 text_size=size.small)33 table.cell(t, 1, 0, str.tostring(score) + "/5",34 text_color=score >= 4 ? color.green :35 score <= 1 ? color.red : color.yellow,36 text_size=size.small)37 table.cell(t, 0, 1, "Volatility", text_color=color.gray,38 text_size=size.small)39 table.cell(t, 1, 1, volState,40 text_color=volState == "HIGH" ? color.red :41 volState == "LOW" ? color.green : color.gray,42 text_size=size.small)43 table.cell(t, 0, 2, "ATR", text_color=color.gray,44 text_size=size.small)45 table.cell(t, 1, 2, str.tostring(atr, "#.##"),46 text_color=color.white, text_size=size.small)47 table.cell(t, 0, 3, "EMA Trend", text_color=color.gray,48 text_size=size.small)49 table.cell(t, 1, 3, ema21 > ema50 ? "Bullish" : "Bearish",50 text_color=ema21 > ema50 ? color.green : color.red,51 text_size=size.small)52 table.cell(t, 0, 4, "Cloud", text_color=color.gray,53 text_size=size.small)54 table.cell(t, 1, 4, close > math.max(senkouA, senkouB) ?55 "Above" : close < math.min(senkouA, senkouB) ?56 "Below" : "Inside",57 text_color=close > math.max(senkouA, senkouB) ?58 color.green : color.red, text_size=size.small)Using the trend dashboard
Put this lesson to work
Free on Thrive, no account needed.