Skip to main content

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

Watch the series
ADX Indicator Explained: Is It a Trend or Just Chop?

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.

pine-Custom ATR with volatility state
1//@version=5
2indicator("Custom ATR", overlay=false)
3
4length = input.int(14, "ATR Length", minval=1)
5smoothed = input.bool(true, "Use Smoothed ATR (RMA)")
6
7trueRange = math.max(high - low,
8 math.max(math.abs(high - close[1]),
9 math.abs(low - close[1])))
10
11atrVal = smoothed ? ta.rma(trueRange, length) : ta.sma(trueRange, length)
12atrPct = atrVal / close * 100
13
14// Volatility state classification
15atrSMA = ta.sma(atrVal, length * 3)
16isHigh = atrVal > atrSMA * 1.5
17isLow = atrVal < atrSMA * 0.5
18
19atrColor = isHigh ? color.new(color.red, 20) :
20 isLow ? color.new(color.green, 20) :
21 color.new(color.gray, 20)
22
23plot(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 Rangemax(high - low, |high - prev close|, |low - prev close|). Captures gap moves that high-low alone misses.
RMA SmoothingWilder's smoothing method (default). Gives more weight to recent bars, responds faster to volatility changes.
SMA SmoothingEqual-weight average. Smoother output but slower to react. Better for longer-term volatility assessment.
ATR as PercentageATR / 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.

pine-Multi-MA crossover with selectable types
1//@version=5
2indicator("MA Crossover Suite", overlay=true)
3
4// Inputs
5fastLen = 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"])
9
10// MA calculation helper
11getMA(src, len, typ) =>
12 switch typ
13 "SMA" => ta.sma(src, len)
14 "EMA" => ta.ema(src, len)
15 "WMA" => ta.wma(src, len)
16 "VWMA" => ta.vwma(src, len)
17
18fastMA = getMA(close, fastLen, maType)
19slowMA = getMA(close, slowLen, maType)
20
21bullCross = ta.crossover(fastMA, slowMA)
22bearCross = ta.crossunder(fastMA, slowMA)
23
24// Trend color
25trendUp = fastMA > slowMA
26fastColor = trendUp ? color.new(color.green, 0) : color.new(color.red, 0)
27slowColor = trendUp ? color.new(color.green, 40) : color.new(color.red, 40)
28
29plot(fastMA, "Fast MA", fastColor, 2)
30plot(slowMA, "Slow MA", slowColor, 2)
31
32plotshape(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)
36
37bgcolor(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.

pine-MA color filter with gradient intensity
1//@version=5
2indicator("MA Color Filter", overlay=true)
3
4maLen = input.int(21, "MA Length")
5src = input.source(close, "Source")
6ema = ta.ema(src, maLen)
7
8dist = (close - ema) / ema * 100
9strength = math.min(math.abs(dist) * 15, 80)
10
11bullColor = color.new(color.green, 100 - strength)
12bearColor = color.new(color.red, 100 - strength)
13
14barcolor(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.

pine-6-MA ribbon indicator
1//@version=5
2indicator("MA Ribbon", overlay=true)
3
4baseLen = 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"])
7
8calc(len) => maType == "EMA" ? ta.ema(close, len) : ta.sma(close, len)
9
10ma1 = 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)))
16
17bullish = ma1 > ma2 and ma2 > ma3 and ma3 > ma4
18
19p1 = 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)
25
26fill(p1, p6, bullish ? color.new(color.green, 88) :
27 color.new(color.red, 88))

Fibonacci-spaced ribbons

Using a multiplier of 1.618 (the golden ratio) creates naturally spaced MAs that avoid redundancy. Lengths like 10, 16, 26, 42, 68, 110 each capture a different cycle frequency. On ETH daily charts, this spacing catches both short-term swings and the macro trend simultaneously.

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.

pine-VWAP and VWMA comparison
1//@version=5
2indicator("VWAP vs VWMA", overlay=true)
3
4vwmaLen = input.int(20, "VWMA Length")
5
6// Built-in VWMA
7vwmaVal = ta.vwma(close, vwmaLen)
8
9// Manual VWAP (cumulative, session-resetting)
10var float cumVol = 0.0
11var float cumVolPrc = 0.0
12
13isNewSession = ta.change(time("D")) != 0
14if isNewSession
15 cumVol := 0.0
16 cumVolPrc := 0.0
17
18cumVol += volume
19cumVolPrc += close * volume
20vwapVal = cumVolPrc / cumVol
21
22plot(vwapVal, "VWAP", color.new(color.orange, 0), 2)
23plot(vwmaVal, "VWMA", color.new(#5ce1e6, 0), 2)
24
25// Distance from VWAP as background intensity
26vwapDist = (close - vwapVal) / vwapVal * 100
27bgcolor(vwapDist > 0 ? color.new(color.green, 93) :
28 color.new(color.red, 93))
VWAPCumulative, resets each session. Standard benchmark for institutional fills. Best on intraday timeframes (1m–1H).
VWMARolling window, no reset. Behaves like an EMA that weights high-volume bars more. Works on any timeframe.
Above VWAPPrice trading above VWAP means buyers are aggressive: average buyer is in profit for the session.
Below VWAPPrice 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.

pine-Ichimoku Cloud with all five components
1//@version=5
2indicator("Ichimoku Cloud", overlay=true)
3
4tenkanLen = 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")
8
9// Donchian midline helper
10donchian(len) => (ta.highest(high, len) + ta.lowest(low, len)) / 2
11
12tenkan = donchian(tenkanLen)
13kijun = donchian(kijunLen)
14senkouA = (tenkan + kijun) / 2
15senkouB = donchian(senkouBLen)
16chikou = close
17
18// Plots
19plot(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)
23
24pA = 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)
28
29fill(pA, pB, senkouA >= senkouB ?
30 color.new(color.green, 85) : color.new(color.red, 85),
31 title="Cloud Fill")
1

Tenkan-sen (Conversion Line)

The 9-period midline of the high-low range. Acts as a short-term trend gauge. When price is above the Tenkan, short-term momentum is bullish. On BTC daily charts, a Tenkan cross above the Kijun is an early bull signal.
2

Kijun-sen (Base Line)

The 26-period midline. Acts as a medium-term support/resistance level and equilibrium price. Price returning to the Kijun often represents a pullback entry opportunity within a larger trend. The Kijun is the most important single line in the system.
3

Senkou Span A & B (The Cloud)

Senkou A is the average of Tenkan and Kijun, plotted 26 periods ahead. Senkou B is the 52-period midline, also displaced 26 periods forward. The space between them forms the cloud (kumo). A thick cloud provides strong support/resistance. A thin cloud is easily broken. Cloud color (green vs red) shows future trend bias.
4

Chikou Span (Lagging Span)

The current close plotted 26 periods in the past. It confirms trend by comparing the current price to where price was 26 bars ago. If Chikou is above past price, the trend is confirmed bullish. This is the confirmation component of the system.

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.

pine-Combined trend dashboard
1//@version=5
2indicator("Trend Dashboard", overlay=true)
3
4ema21 = ta.ema(close, 21)
5ema50 = ta.ema(close, 50)
6ema200 = ta.ema(close, 200)
7atr = ta.atr(14)
8atrSMA = ta.sma(atr, 42)
9
10// Ichimoku components
11tenkan = (ta.highest(high, 9) + ta.lowest(low, 9)) / 2
12kijun = (ta.highest(high, 26) + ta.lowest(low, 26)) / 2
13senkouA = (tenkan + kijun) / 2
14senkouB = (ta.highest(high, 52) + ta.lowest(low, 52)) / 2
15
16// Scoring: 0-5 bullish conditions
17score = (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)
22
23volState = atr > atrSMA * 1.3 ? "HIGH" :
24 atr < atrSMA * 0.7 ? "LOW" : "NORMAL"
25
26if barstate.islast
27 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

A score of 4–5 means all trend systems agree. This is when you look for long entries on pullbacks. A score of 0–1 means everything is bearish. Look for shorts or stay flat. Scores of 2–3 indicate indecision. Reduce position size or wait for alignment. Combine this with the oscillator dashboard from the next lesson for a complete market assessment.

Put this lesson to work

Free on Thrive, no account needed.