Indicator · Pine Script v6 · Own pane

Trend Score History

by ryangaraygay· code credited to swoozshies

Trend Score History calculates a composite trend metric ranging between -5 and +5 by evaluating session VWAP, EMA alignment, price-volume flow, lower-timeframe Donchian channel breakouts, and Opening Range breakouts.

View on GitHub

Repaints

GitHub stars2on the repository
Pine versionv6current
Lines of code89
Settings10inputs
LicenceMIT
Last update1 year ago10 Apr 2025

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

89 lines of Pine Script v6 from trend-score-history.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

trend-score-history.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © swoozshies

//@version=6
indicator("Trend Score History", overlay = false)

atr_length = input.int(14, "ATR Length")
atr_low_level = input.float(4.0, "Low ATR Level")
uptrend_color = input.color(color.green, "uptrend color")
downtrend_color = input.color(color.red, "downtrend color")

atr = ta.atr(atr_length)

float source = input.source(hlc3, "Source", tooltip="", inline="", group="Volume Weighted Average Price")
string my_session = input.session("0830-1600", title='Custom Session')
timeinrange(res, sess) => not na(time(res, sess))
in_session = timeinrange("1", my_session)
newYorkVwap = ta.vwap(source, in_session[0] and not in_session[1])
vwapValue = in_session ? newYorkVwap  : na

// price-volume
bv = (close-open) * volume // body x volume
bv_length = 21 // TODO input
bvema1 = ta.ema(bv, bv_length)
bvema2 = ta.ema(bvema1, bv_length)
bvema3 = ta.ema(bvema2, bv_length)
bvout = 3 * (bvema1 - bvema2) + bvema3

b = math.abs(bvout)
b2 = math.abs(bvout[1])
b3 = math.abs(bvout[2])

messy = 1500 // TODO input messy
isMessy = b < messy and b2 < messy and b3 < messy

// ema-band
ema9 = ta.ema(close, 9)
ema21 = ta.ema(close, 21)

// donchian
length = input(20, title="Channel Length")
lower_tf = input.timeframe("1", title="Lower Timeframe")

// Function to get Donchian Channel values from a lower timeframe
[lower_tf_upper, lower_tf_lower] = request.security(syminfo.tickerid, lower_tf, [ta.highest(high, length), ta.lowest(low, length)])

var string lastSignalType = ""
if (lower_tf_upper > lower_tf_upper[1])
    lastSignalType := "long"
else if (lower_tf_lower < lower_tf_lower[1])
    lastSignalType := "short"

vwap_diff = close - vwapValue

string openrange_session = input.session("0830-0845", title='Opening Range Session')
in_openrange_session = timeinrange(timeframe.period, openrange_session)

string post_openrange_session = input.session("0846-1600", title='Post Opening Range Session')
in_post_openrange_session = timeinrange(timeframe.period, post_openrange_session)

is_new_session(res, sess) =>
    t = time(res, sess)
    na(t[1]) and not na(t) or t[1] < t

new_openrange_session = is_new_session("1440", openrange_session)

var float reg_high = close
var float reg_low = close
reg_high := new_openrange_session ? high : in_openrange_session ? math.max(high, reg_high[1]) : reg_high[1]
reg_low := new_openrange_session ? low : in_openrange_session ? math.min(low, reg_low[1]) : reg_low[1]

ref_close = close
openrange_diff = ref_close > reg_high[0] ? (ref_close - reg_high[0]) : (ref_close < reg_low[0] ? ref_close - reg_low[0] : na)
openrange_score = na(openrange_diff) ? 0 : (openrange_diff > 0 ? 1 : -1)

vwap_score = na(vwap_diff) ? 0 : (vwap_diff > 0 ? 1 : -1)
emaband_score = (ema9 - ema21) > 0 ? 1 : -1
pricevolume_score = (isMessy or bvout ==0) ? 0 :(bvout > 0 ? 1 : -1)
donchian_score = (lastSignalType == "long" ? 1 : -1)
trend_score = vwap_score + emaband_score + pricevolume_score + donchian_score + (in_post_openrange_session ? openrange_score : 0)

series color trend_color = na

if barstate.isconfirmed
    trend_color := atr < atr_low_level ? color.new(color.gray, 70) : (trend_score == 0 ? color.black : (trend_score > 0 ? color.from_gradient(trend_score, 0, 4, color.white, uptrend_color) : color.from_gradient(trend_score, -4, 0, downtrend_color, color.white)))

plot(trend_score, style = plot.style_columns, color = trend_color)
plot(5, color = color.new(color.gray, 50))
plot(-5, color = color.new(color.gray, 50))

Overview

Trend Score History plots the cumulative score as histogram columns in a separate pane, using color gradients to reflect trend direction and score magnitude. Bars are shaded gray when ATR falls below a user-defined threshold to indicate low volatility. Key settings allow adjusting session times, ATR limits, and Donchian channel parameters. Requesting lower-timeframe data via security functions can lead to repainting on historical chart bars.

Details

Published by

ryangaraygay on GitHub

Code credit

swoozshies, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Trend, Oscillators & momentum, Sessions & time, Breakout

Markets

Any symbol

Timeframes

M15-H1

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

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

SettingTypeDefaultVariable
ATR Lengthint14atr_length
Low ATR Levelfloat4.0atr_low_level
uptrend colorcolorcolor.greenuptrend_color
downtrend colorcolorcolor.reddowntrend_color
Sourcesourcehlc3source
Custom Sessionsession0830-1600my_session
Channel Lengthint20length
Lower Timeframetimeframe1lower_tf
Opening Range Sessionsession0830-0845openrange_session
Post Opening Range Sessionsession0846-1600post_openrange_session
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

Schaff Trend Cycle

by everget
948 stars

This indicator plots the Schaff Trend Cycle in a separate pane. It subtracts a slow exponential moving average from a fast one, applies a stochastic cycle twice, and smooths each result to form a 0–100 oscillator. Line color follows the slope, or the upper and

Indicator v4 Oscillators & momentumTrend
Updated 10 days ago · GPL-3.0 GitHub repository of Schaff Trend Cycle

MACD Breakout

by jerryinyang
5 stars

Calculates multi-timeframe Moving Average Convergence Divergence (MACD) alongside a Money Flow filter to identify potential market breakouts. It evaluates higher-timeframe MACD calculations using exponential or simple moving averages combined with Money Flow o

Indicator v4 TrendOscillators & momentum Repaints
Updated 2 years ago · None stated GitHub repository of MACD Breakout

SPY 0DTE Scalper - 15min

by chris-c-thomas
14 stars

This intraday overlay establishes directional bias and high-conviction swing setups for SPY on the 15-minute timeframe. It computes a weighted confluence score combining an EMA ribbon, a 50 EMA anchor, session VWAP bands, RSI divergence, ADX, TTM Squeeze, cand

Indicator v6 TrendOscillators & momentum
Updated 6 months ago · MIT GitHub repository of SPY 0DTE Scalper - 15min

GainzAlgo V2 Alpha

by Bakomebandias
8 stars

This overlay indicator scores breakouts of recent highs and lows against failed-breakout checks, EMA trend alignment, RSI momentum, and an ATR volatility band. It plots green buy and red sell labels when conditions pass a minimum score, and it prints ATR-based

Indicator v6 TrendOscillators & momentum
Updated 6 months ago · None stated GitHub repository of GainzAlgo V2 Alpha

Target Radar

by eddiebelaval
7 stars

Target Radar is a multi-factor forecasting indicator that plots projection bands, forward boxes, and dynamic target zones directly on the main price chart. It calculates a forecast score by combining z-scores for trend, momentum, volume pressure, and volatilit

Indicator v5 TrendOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Target Radar

Edge 59

by subos2008
6 stars

This indicator identifies trend-following breakout opportunities by combining directional movement, trend channels, and multi-period price extremes. It calculates an ADX-colored weighted moving average, a linear regression trend filter based on a volatility ch

Indicator v5 TrendBreakout
Updated 2 years ago · Custom licence GitHub repository of Edge 59

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers