Indicator · Pine Script v6 · On the chart

Trend Zones

by georgedevprojects

Trend Zones displays market direction on the price chart using fast and slow moving averages (EMA or SMA).

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code77
Settings9inputs
LicenceMIT
Last update6 days ago18 Nov 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 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.

Details

Published by

georgedevprojects on GitHub

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pine-scripttrading-toolkittradingview-ideastradingview-professional-tools

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Average typestringEMAmaType
Fast lengthint20fastLen
Slow lengthint50slowLen
Confirm labels with RSIbooltrueuseRsi
RSI lengthint14rsiLen
Show trend-change labelsbooltrueshowLabels
Shade trend zonebooltrueshowZones
Uptrend colourcolorcolor.tealupColor
Downtrend colourcolorcolor.reddownColor
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.

Similar Pine Scripts

228 stars

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

Indicator v6 Screeners & dashboardsTrend
Updated 4 months ago · None stated GitHub repository of TradersPost Trading Checklist
53 stars

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

Indicator v6 TrendOscillators & momentum
Updated 3 months ago · MPL-2.0 GitHub repository of Candle Counter + MA + RSI + Mode

MTF Trend Dashboard

by theonetrade
34 stars

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

Indicator v6 TrendMoving averages
Updated 2 weeks ago · MIT GitHub repository of MTF Trend Dashboard

Pocket Scout - SPY/QQQ

by chris-c-thomas
13 stars

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

Indicator v6 TrendOscillators & momentum Repaints
Updated 7 months ago · MIT GitHub repository of Pocket Scout - SPY/QQQ

Portfolio Backtester

by f-cksociety
11 stars

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

Indicator v5 TrendOscillators & momentum
Updated 4 years ago · MPL-2.0 GitHub repository of Portfolio Backtester

ForexAlgo

by Harshil427
7 stars

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,

Indicator v5 TrendOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of ForexAlgo

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers