Indicator · Pine Script v6 · On the chart

Adaptive Pivot Trend Levels [ChartPrime]

by theonetrade· code credited to ChartPrime

Adaptive Pivot Trend Levels [ChartPrime] calculates adaptive support and resistance levels on the price chart using pivot highs and pivot lows over a customizable length.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code158
Settings5inputs
LicenceMIT
Last update2 weeks ago8 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

158 lines of Pine Script v6 from assets/indicator/bit-exact/adaptive_pivot_trend_levels_chartprime_mDGDURJN.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

adaptive_pivot_trend_levels_chartprime_mDGDURJN.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ChartPrime


//@version=6
indicator("Adaptive Pivot Trend Levels [ChartPrime]", overlay = true, max_lines_count = 500)



// --------------------------------------------------------------------------------------------------------------------}
// 📌 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
// --------------------------------------------------------------------------------------------------------------------{

Length = input.int(5)
actvLevels = input.bool(true, "Active", inline = "c")
crossLevels = input.bool(true, "Crossed", inline = "c")

colorUP = input.color(color.rgb(36, 224, 133), "", inline = "color")
colorDN = input.color(color.rgb(230, 36, 165), "", inline = "color")


type level 
    line l 
    bool isBelow
    label count

var pivots = array.new<float>()
var levels = array.new<level>()



active = 0 
var crossed = 0
var start = 0

// --------------------------------------------------------------------------------------------------------------------}
// 📌 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
// --------------------------------------------------------------------------------------------------------------------{

ph = ta.pivothigh(Length, Length)
pl = ta.pivotlow(Length, Length)


if not na(ph)
    l = line.new(bar_index-Length, ph, bar_index, ph)
    count = label.new(bar_index, ph, "", color = color(na), style = label.style_label_left)

    pivots.push(ph)
    levels.push(level.new(l, false, count))


if not na(pl)
    l = line.new(bar_index-Length, pl, bar_index, pl)
    count = label.new(bar_index, ph, "", color = color(na), style = label.style_label_left)

    pivots.push(pl)
    levels.push(level.new(l, true, count))




if pivots.size() > 10
    pivots.shift()


trendLine = pivots.avg()

Uptrend   = low  >= trendLine
Dntrend   = high <= trendLine
TColor = Uptrend ? colorUP : Dntrend ? colorDN : color.gray

upTrend = TColor == colorUP or TColor == color.gray and TColor[1] == colorUP and TColor[2] == colorUP
dnTrend = TColor == colorDN or TColor == color.gray and TColor[1] == colorDN and TColor[2] == colorDN



upChange = ta.change(upTrend) 
dnChange = ta.change(dnTrend) 

TrendChange = upChange or dnChange

if TrendChange
    crossed := 0
    start := bar_index


// --------------------------------------------------------------------------------------------------------------------}
// 📌 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
// --------------------------------------------------------------------------------------------------------------------{

if not TrendChange
    for i in levels

        if start > i.l.get_x2()

            i.l.delete()
            i.count.delete()

            levels.remove(levels.indexof(i))


        else 
            
            active += 1
         
            i.l.set_x2(bar_index)
            i.l.set_color(color.new(TColor, 100))

            if actvLevels
                
    
                i.count.set_xy(bar_index, i.l.get_y1())

                i.l.set_color(TColor)
                i.l.set_style(line.style_dashed)

                i.count.set_text(str.tostring(active))
                i.count.set_textcolor(color.new(chart.fg_color, 60))
    

            if i.isBelow
                if low < i.l.get_y1()
                    crossed += 1
                    i.count.delete()

                    i.l.set_color(color.new(TColor, crossLevels ? 50 : 100))
                    i.l.set_style(line.style_dotted)
                    levels.remove(levels.indexof(i))

            else 
                if high > i.l.get_y1()
                    crossed += 1
                    i.count.delete()
                    i.l.set_color(color.new(TColor, crossLevels ? 50 : 100))
                    i.l.set_style(line.style_dotted)
                    levels.remove(levels.indexof(i))



var tbl = table.new(position.top_right, 100, 100, chart.bg_color)

if barstate.islast

    tbl.cell(0, 0, "Trend", text_halign = text.align_left, text_color = chart.fg_color)
    tbl.cell(1, 0, (upTrend ? "↑" : Dntrend ? "↓" : "-"), text_color = TColor)

    tbl.cell(0, 1, "Active Levels", text_halign = text.align_left, text_color = chart.fg_color)
    tbl.cell(1, 1,  str.tostring(active), text_color = TColor)

    tbl.cell(0, 2, "Crossed Levels", text_halign = text.align_left, text_color = chart.fg_color)
    tbl.cell(1, 2, str.tostring(crossed), text_color = TColor)

pt = plot(trendLine, "Trend Line", style = plot.style_stepline, color = TColor)
plot(trendLine, "Trend Line Shadow", style = plot.style_stepline, color = color.new(TColor, 70), linewidth = 5)
pc = plot(close, display = display.none, editable = false)

fill(pc, pt, trendLine, close, color(na), color.new(TColor, 70))
// --------------------------------------------------------------------------------------------------------------------{

Overview

Adaptive Pivot Trend Levels [ChartPrime] tracks recent pivot prices to compute a dynamic average trend line, classifying the current market state into uptrend, downtrend, or neutral. Horizontal levels extend from pivot points with dynamic line styling and counts, updating visual properties based on whether price remains above or below the level. Settings allow toggling active and crossed levels and configuring uptrend and downtrend colors.

Details

Published by

theonetrade on GitHub

Code credit

ChartPrime, as written in the script's header

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

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Lengthint5Length
ActivebooltrueactvLevels
CrossedbooltruecrossLevels
colorUPcolorcolor.rgb(36, 224, 133)colorUP
colorDNcolorcolor.rgb(230, 36, 165)colorDN
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

575 stars

This indicator detects equal highs and lows by comparing prices within user-defined left and right bars using a tolerance percentage. It plots horizontal lines on the price chart for equal highs in one color and lows in another. A screener allows input of mult

Indicator v5 Support & resistanceTrend
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows with Screener

Swing labels

by tradoor-terminal
320 stars

Calculates swing highs and swing lows on the price chart using pivot high and pivot low detection over a specified length. It places labels above pivot highs and below pivot lows to highlight key structural swing points. The indicator measures and displays the

Indicator v6 Support & resistanceTrend
Updated 3 days ago · AGPL-3.0 GitHub repository of Swing labels

Function - Linear Regression

by ricardosantos79
261 stars

This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up

Indicator v5 TrendSupport & resistance
Updated 5 years ago · None stated GitHub repository of Function - Linear Regression

AI Trend

by dearvn
257 stars

AI Trend is an indicator that plots pivot points, trend lines, and support and resistance levels directly on the price chart. It marks high and low pivots based on user-defined length, draws trend lines that check for violations at specified points, and identi

Indicator v5 TrendSupport & resistance
Updated 2 months ago · None stated GitHub repository of AI Trend

Dynamic Linear Regression

by TradersPost
228 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 4 months ago · None stated GitHub repository of Dynamic Linear Regression

Ichimoku Cloud

by harryguiacorn
220 stars

This indicator plots Ichimoku Cloud elements on the price chart, including Tenkan-sen, Kijun-sen, Senkou Span A and B lines with optional Chikou Span. It signals trend changes via Tenkan-sen and Kijun-sen crosses and places arrows at Kijun-sen direction shifts

Indicator v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ichimoku Cloud

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