Indicator · Pine Script v6 · Own pane

ezTrend Lines

by ezPappi

ezTrend Lines calculates selected oscillator indicators, including RSI, CCI, Momentum, OBV, or MACD, and displays them in a separate pane.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code180
Settings10inputs
LicenceGPL-3.0
Last update1 year ago23 Jun 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

180 lines of Pine Script v6 from ez_trend_lines.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

ez_trend_lines.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Based on script of © LonesomeTheBlue
// Trend Lines for RSI, CCI, Momentum, OBV and MACD
// By ezPappi
//@version=6
indicator('ezTrend Lines', overlay = false, max_bars_back = 4000)

indi = input.string(defval = 'RSI', title = 'Indicator', options = ['RSI', 'CCI', 'OBV', 'Momentum', 'MACD'])
Src = input(defval = close, title = 'Source')
rsilen = input.int(defval = 12, title = 'RSI Length', minval = 1)
ccilen = input.int(defval = 20, title = 'CCI Length', minval = 1)
momlen = input.int(defval = 10, title = 'Momentum Length', minval = 1)
prd = input.int(defval = 10, title = 'Pivot Point Period', minval = 5, maxval = 50)
PPnum = input.int(defval = 3, title = 'Number of Pivot Point to check', minval = 2, maxval = 3)

// MACD inputs
fastLength = input(12, title = 'MACD Fast Length')
slowLength = input(26, title = 'MACD Slow Length')
signalLength = input(9, title = 'MACD Signal Length')

Rsi = ta.rsi(Src, rsilen)
Cci = ta.cci(Src, ccilen)
Mom = ta.mom(Src, momlen)
[macdLine, signalLine, histLine] = ta.macd(Src, fastLength, slowLength, signalLength)

src = indi == 'RSI' ? Rsi : indi == 'CCI' ? Cci : indi == 'Momentum' ? Mom : indi == 'MACD' ? macdLine : ta.obv

hline1 = indi == 'RSI' ? 70 : indi == 'CCI' ? 100 : indi == 'MACD' ? 4 : na

hline2 = indi == 'RSI' ? 0 : indi == 'CCI' ? 0 : indi == 'MACD' ? 0 : na

hline3 = indi == 'RSI' ? 30 : indi == 'CCI' ? -100 : indi == 'MACD' ? -4 : na

h1 = hline(hline1, color = color.new(#ffffff, 50))
h2 = hline(hline2, color = color.new(#ffffff, 50))
h3 = hline(hline3, color = color.new(#ffffff, 50))
// Custom background for MACD
macdBackgroundColor = macdLine > signalLine ? color.new(color.gray, 99) : color.new(color.gray, 99)
bgcolor(indi == 'MACD' ? macdBackgroundColor : na)

fill(h1, h3, color = color.new(#9915fa, 90))
plot(src, linewidth = 1, color = color.new(color.blue, 0))

// Plot MACD components if MACD is selected
plot(indi == 'MACD' ? macdLine : na, color = color.new(color.blue, 0), linewidth = 2, title = 'MACD Line')
plot(indi == 'MACD' ? signalLine : na, color = color.new(color.orange, 0), linewidth = 2, title = 'Signal Line')
plot(indi == 'MACD' ? histLine : na, style = plot.style_histogram, color = color.new(color.gray, 0), title = 'Histogram')

// The rest of the code remains the same
float ph = na
float pl = na
ph := ta.pivothigh(src, prd, prd)
pl := ta.pivotlow(src, prd, prd)

getloc(bar_i) =>
    bar_index + prd - bar_i

t1pos = ta.valuewhen(bool(ph), bar_index, 0)
t1val = nz(src[getloc(t1pos)])
t2pos = ta.valuewhen(bool(ph), bar_index, 1)
t2val = nz(src[getloc(t2pos)])
t3pos = ta.valuewhen(bool(ph), bar_index, 2)
t3val = nz(src[getloc(t3pos)])

b1pos = ta.valuewhen(bool(pl), bar_index, 0)
b1val = nz(src[getloc(b1pos)])
b2pos = ta.valuewhen(bool(pl), bar_index, 1)
b2val = nz(src[getloc(b2pos)])
b3pos = ta.valuewhen(bool(pl), bar_index, 2)
b3val = nz(src[getloc(b3pos)])

getloval(l1, l2) =>
    _ret1 = l1 == 1 ? b1val : l1 == 2 ? b2val : l1 == 3 ? b3val : 0
    _ret2 = l2 == 1 ? b1val : l2 == 2 ? b2val : l2 == 3 ? b3val : 0
    [_ret1, _ret2]

getlopos(l1, l2) =>
    _ret1 = l1 == 1 ? b1pos : l1 == 2 ? b2pos : l1 == 3 ? b3pos : 0
    _ret2 = l2 == 1 ? b1pos : l2 == 2 ? b2pos : l2 == 3 ? b3pos : 0
    [_ret1, _ret2]

gethival(l1, l2) =>
    _ret1 = l1 == 1 ? t1val : l1 == 2 ? t2val : l1 == 3 ? t3val : 0
    _ret2 = l2 == 1 ? t1val : l2 == 2 ? t2val : l2 == 3 ? t3val : 0
    [_ret1, _ret2]

gethipos(l1, l2) =>
    _ret1 = l1 == 1 ? t1pos : l1 == 2 ? t2pos : l1 == 3 ? t3pos : 0
    _ret2 = l2 == 1 ? t1pos : l2 == 2 ? t2pos : l2 == 3 ? t3pos : 0
    [_ret1, _ret2]

// Line definitions
var line l1 = na
var line l2 = na
var line l3 = na
var line t1 = na
var line t2 = na
var line t3 = na

// Delete old lines
line.delete(l1)
line.delete(l2)
line.delete(l3)
line.delete(t1)
line.delete(t2)
line.delete(t3)

countlinelo = 0
countlinehi = 0
for p1 = 1 to PPnum - 1 by 1
    uv1 = 0.0
    uv2 = 0.0
    up1 = 0
    up2 = 0
    for p2 = PPnum to p1 + 1 by 1
        [val1, val2] = getloval(p1, p2)
        [pos1, pos2] = getlopos(p1, p2)
        if val1 > val2
            diff = (val1 - val2) / (pos1 - pos2)
            hline = val2 + diff
            lloc = bar_index
            lval = src
            valid = true
            for x = pos2 + 1 - prd to bar_index by 1
                if nz(src[getloc(x + prd)]) < hline
                    valid := false
                    valid
                lloc := x
                lval := hline
                hline := hline + diff
                hline

            if valid
                uv1 := hline
                uv2 := val2
                up1 := lloc
                up2 := pos2
                break
    dv1 = 0.0
    dv2 = 0.0
    dp1 = 0
    dp2 = 0
    for p2 = PPnum to p1 + 1 by 1
        [val1, val2] = gethival(p1, p2)
        [pos1, pos2] = gethipos(p1, p2)
        if val1 < val2
            diff = (val2 - val1) / (pos1 - pos2)
            hline = val2 - diff
            lloc = bar_index
            lval = src
            valid = true
            for x = pos2 + 1 - prd to bar_index by 1
                if nz(src[getloc(x + prd)]) > hline
                    valid := false
                    break
                lloc := x
                lval := hline
                hline := hline - diff
                hline

            if valid
                dv1 := hline
                dv2 := val2
                dp1 := lloc
                dp2 := pos2
                break

    if up1 != 0 and up2 != 0
        countlinelo := countlinelo + 1
        l1 := countlinelo == 1 ? line.new(up2 - prd, uv2, up1, uv1, color = color.new(color.blue, 0)) : l1
        l2 := countlinelo == 2 ? line.new(up2 - prd, uv2, up1, uv1, color = color.new(color.blue, 0)) : l2
        l3 := countlinelo == 3 ? line.new(up2 - prd, uv2, up1, uv1, color = color.new(color.blue, 0)) : l3
        l3

    if dp1 != 0 and dp2 != 0
        countlinehi := countlinehi + 1
        t1 := countlinehi == 1 ? line.new(dp2 - prd, dv2, dp1, dv1, color = color.new(color.red, 0)) : t1
        t2 := countlinehi == 2 ? line.new(dp2 - prd, dv2, dp1, dv1, color = color.new(color.red, 0)) : t2
        t3 := countlinehi == 3 ? line.new(dp2 - prd, dv2, dp1, dv1, color = color.new(color.red, 0)) : t3
        t3

Overview

ezTrend Lines identifies pivot highs and pivot lows on the chosen oscillator line using configurable pivot periods and checks up to three pivot points. By identifying these high and low swing points, the script draws trend lines directly across the oscillator values. Users can adjust oscillator lengths, MACD parameters, and pivot point periods to customize trend line sensitivity.

Details

Published by

ezPappi on GitHub

Draws

Separate pane below the chart

Markets

Stocks

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.

Settings

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

SettingTypeDefaultVariable
IndicatorstringRSIindi
SourcesourcecloseSrc
RSI Lengthint12rsilen
CCI Lengthint20ccilen
Momentum Lengthint10momlen
Pivot Point Periodint10prd
Number of Pivot Point to checkint3PPnum
MACD Fast Lengthint12fastLength
MACD Slow Lengthint26slowLength
MACD Signal Lengthint9signalLength
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

114 stars

This indicator combines a scaled Forecast Oscillator with a Point of Force state detector. The Forecast Oscillator calculates the percentage deviation of price from its linear regression curve and normalizes the output between 0 and 1, plotting a line in a sep

Indicator v4 Oscillators & momentumSupport & resistance Repaints

The indicator scores whether a counter-move against the dominant structure is maturing and whether price has started turning back. It plots a composite score in a separate pane from weighted context, correction maturity, and exhaustion, scaled by trigger and a

Indicator v6 TrendOscillators & momentum
Updated 3 days ago · MIT GitHub repository of Directional Probability Engine v2 [WavesUnchained]
4 stars

This indicator is a live strategy scanner for cryptocurrency pairs. It runs six strategies on the current chart, tracks their wins and losses, and rates them to show the best one for this pair and timeframe. It uses ATR for adaptive TP/SL, auto-scales based on

Indicator v5 Oscillators & momentumVolatility & bands
Updated 2 days ago · None stated GitHub repository of Crypto Pair Selector v2 STEPFUN

Parabolic RSI

by YooooungLee
4 stars

This indicator calculates the RSI oscillator using a user-defined length. It then applies a custom Parabolic SAR function to the RSI values to generate dynamic trend levels that function as support and resistance zones. The SAR levels are plotted in a separate

Indicator v6 Oscillators & momentumSupport & resistance
Updated 10 months ago · Apache-2.0 GitHub repository of Parabolic RSI

EMA · RSI

by Tomas-Cyberia
1 stars

The EMA RSI indicator plots multiple moving averages including EMAs and MAs on the price chart and the RSI oscillator in a separate pane. It identifies when a trending asset returns to support with RSI in oversold, using green signals and confirmations at key

Indicator v6 TrendMoving averages
Updated 5 days ago · None stated GitHub repository of EMA · RSI

More Oscillators & momentum 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