1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
77 lines of Pine Script v6 from trend_zones.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.
trend_zones.pine
// ============================================================
// Trend Zones
// Author: George Larter — github.com/georgedevprojects
// Shows trend direction with two moving averages, shades the
// zone between them, labels confirmed trend changes and sends
// alerts. Educational tool only — not financial advice.
// ============================================================
//@version=6
// overlay = true draws on the price chart, not in a separate panel
indicator("Trend Zones", overlay = true)
// ---------- 1. SETTINGS ----------
// Each input.* call adds a field to the indicator's Settings window
maType = input.string("EMA", "Average type", options = ["EMA", "SMA"], group = "Moving averages")
fastLen = input.int(20, "Fast length", minval = 1, group = "Moving averages")
slowLen = input.int(50, "Slow length", minval = 1, group = "Moving averages")
useRsi = input.bool(true, "Confirm labels with RSI", group = "RSI filter")
rsiLen = input.int(14, "RSI length", minval = 1, group = "RSI filter")
showLabels = input.bool(true, "Show trend-change labels", group = "Display")
showZones = input.bool(true, "Shade trend zone", group = "Display")
upColor = input.color(color.teal, "Uptrend colour", group = "Display")
downColor = input.color(color.red, "Downtrend colour", group = "Display")
// ---------- 2. CALCULATIONS ----------
// Helper function: returns the average type chosen in the settings
ma(len) => maType == "EMA" ? ta.ema(close, len) : ta.sma(close, len)
fastMa = ma(fastLen)
slowMa = ma(slowLen)
rsi = ta.rsi(close, rsiLen)
// Uptrend = fast average above slow average
isUptrend = fastMa > slowMa
// crossover/crossunder are true only on the bar where the lines cross
trendUp = ta.crossover(fastMa, slowMa)
trendDown = ta.crossunder(fastMa, slowMa)
trendColor = isUptrend ? upColor : downColor
// RSI filter: when on, an UP cross needs RSI > 50 and a DOWN cross needs RSI < 50.
// When off, (not useRsi) is true so every cross counts.
confirmedUp = trendUp and (not useRsi or rsi > 50)
confirmedDown = trendDown and (not useRsi or rsi < 50)
// Bars since the last confirmed (labelled) change — calculated on every bar so the count is correct
barsSinceChange = ta.barssince(confirmedUp or confirmedDown)
// ---------- 3. DRAWING ----------
pFast = plot(fastMa, "Fast MA", color = trendColor, linewidth = 2)
pSlow = plot(slowMa, "Slow MA", color = color.gray, linewidth = 1)
// color.new(c, 80) = 80% transparent; na = draw nothing
fill(pFast, pSlow, color = showZones ? color.new(trendColor, 80) : na, title = "Trend zone")
plotshape(showLabels and confirmedUp, "Trend up", shape.labelup, location.belowbar, upColor, text = "UP", textcolor = color.white, size = size.small)
plotshape(showLabels and confirmedDown, "Trend down", shape.labeldown, location.abovebar, downColor, text = "DOWN", textcolor = color.white, size = size.small)
// ---------- 4. INFO PANEL ----------
// "var" creates the table once instead of on every bar
var table info = table.new(position.top_right, 2, 5, bgcolor = color.new(color.black, 20), border_width = 1)
// Only fill the table on the latest bar
if barstate.islast
gapPct = (fastMa - slowMa) / slowMa * 100
table.cell(info, 0, 0, "Trend", text_color = color.white)
table.cell(info, 1, 0, isUptrend ? "UP" : "DOWN", text_color = trendColor)
table.cell(info, 0, 1, "Gap", text_color = color.white)
table.cell(info, 1, 1, str.tostring(gapPct, "#.##") + "%", text_color = color.white)
table.cell(info, 0, 2, "RSI", text_color = color.white)
table.cell(info, 1, 2, str.tostring(rsi, "#.0"), text_color = color.white)
table.cell(info, 0, 3, "Bars since change", text_color = color.white)
table.cell(info, 1, 3, na(barsSinceChange) ? "–" : str.tostring(barsSinceChange), text_color = color.white)
table.cell(info, 0, 4, "Type", text_color = color.white)
table.cell(info, 1, 4, maType, text_color = color.white)
// ---------- 5. ALERTS ----------
// Available in TradingView's "Create alert" menu; {{ticker}} becomes the symbol
alertcondition(confirmedUp, "Trend turned up", "{{ticker}}: trend turned up")
alertcondition(confirmedDown, "Trend turned down", "{{ticker}}: trend turned down")
Overview
Trend Zones shades the area between the two averages to reflect the active trend. Trend change labels are plotted during moving average crossovers, with optional RSI momentum confirmation filters requiring RSI to be above or below 50. An on-chart information panel displays the active trend direction, gap percentage between averages, current RSI value, and bar count since the last signal. Settings allow complete customization of lengths, colors, and visual toggles.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Average type
string
EMA
maType
Fast length
int
20
fastLen
Slow length
int
50
slowLen
Confirm labels with RSI
bool
true
useRsi
RSI length
int
14
rsiLen
Show trend-change labels
bool
true
showLabels
Shade trend zone
bool
true
showZones
Uptrend colour
color
color.teal
upColor
Downtrend colour
color
color.red
downColor
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
TradersPost Trading Checklist is an overlay indicator that evaluates a suite of popular technical conditions for long and short trade setups. It checks session-anchored VWAP, fast and slow EMA alignments and crosses, 200 SMA, RSI overbought or oversold conditi
This indicator analyzes historical candle direction and price range over a configurable lookback window to gauge market trend. It categorizes trend direction using candle count, price range sum, or both. Signals are filtered using a Simple Moving Average to en
MTF Trend Dashboard evaluates multi-timeframe trend conditions using Fast EMA, Slow EMA, and RSI across five user-selected timeframes. A timeframe is classified as bullish when price is above the Fast EMA, Fast EMA is above the Slow EMA, and RSI is above 50, o
Pocket Scout - SPY/QQQ is a mobile-optimized intraday bias indicator designed for major US equity ETFs and indices. It overlays a 9/21/50 EMA ribbon, session VWAP, prior day high/low/close levels, and intraday high/low lines directly on the main price chart. T
The script is a Pine Script v5 indicator that emulates strategy backtesting directly on the price chart. It evaluates modular entry strategies, trade directions, entry stop-loss types such as ATR multiples or fixed percentages, and a wide variety of trade filt
ForexAlgo generates trade signals directly on the price chart using a primary leading indicator, such as the Range Filter, combined with modular confirmation filters. Traders can toggle multiple technical filters, including exponential moving average crosses,