Indicator · Pine Script v4 · On the chart

Price Change Rate by Pivot Points - Dynamic

by SammyEnigma· code credited to LonesomeTheBlue

This indicator calculates dynamic pivot highs and pivot lows over a configurable period to track price change rates and retracement levels.

View on GitHub

GitHub stars18on the repository
Pine versionv4older, still runs
Lines of code102
Settings6inputs
LicenceNone statedfile: MPL-2.0
Last update6 years ago15 Oct 2020

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

102 lines of Pine Script v4 from pivot-popints.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

pivot-popints.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LonesomeTheBlue

//@version=4
study("Price Change Rate by Pivot Points - Dynamic", overlay=true, max_bars_back = 2000)
prd = input(defval = 30, title="Pivot Point Period", minval = 5, maxval = 100)
showpivot = input(defval = true, title="Show Pivot Points")
showret = input(defval = true, title="Show retracement")
showprice = input(defval = false, title="Show Prices")
showline = input(defval = true, title="Show Lines")
showoncurr = input(defval = false, title="Show Label on current High/Low")


float ph = na, float pl = na
ph := pivothigh(prd, prd)
pl := pivotlow(prd, prd)

plotshape(ph and showpivot, text="H",  style=shape.labeldown, color=na, textcolor=color.blue, location=location.abovebar, transp=0, offset = -prd)
plotshape(pl and showpivot, text="L",  style=shape.labeldown, color=na, textcolor=color.blue, location=location.belowbar, transp=0, offset = -prd)

_highest(len) =>
    _hi = high
    _hloc = 0
    for i = 1 to len -1 
        if na(high[i])
            break
        if nz(high[i]) > _hi
            _hi := nz(high[i])
            _hloc := i
    [_hi, _hloc]

_lowest(len) =>
    _lo = low
    _hloc = 0
    for i = 1 to len -1
        if na(low[i])
            break
        if nz(low[i]) < _lo
            _lo := nz(low[i])
            _hloc := i
    [_lo, _hloc]
    

hcont = true
hcont := pl ? false : nz(hcont[1], true)
lcont = true
lcont := ph ? false : nz(lcont[1], true)

float lastphi = na, float lastplo = na
hiloc = 0, loloc = 0
lastphi := nz(lastphi[1])
lastplo := nz(lastplo[1])
hiloc := nz(hiloc[1]) + 1
loloc := nz(loloc[1]) + 1
hchg = false
if ph
    if (hcont and lastphi != 0 and ph > lastphi) or not hcont
        hchg := (hcont and lastphi != 0 and ph > lastphi)
        lastphi := ph
        hiloc := prd
        hcont := true

lchg = false
if pl
    if (lcont and lastplo != 0 and pl < lastplo) or not lcont
        lchg := (lcont and lastplo != 0 and pl < lastplo)
        lastplo := pl
        loloc := prd
        lcont := true

[lwd, h_locd] = _lowest(hiloc)
var line lnd = na
var label lbd = na
if hiloc != 0 and lastphi != 0
    if change(lastphi) == 0 or hchg
        line.delete(lnd)
        label.delete(lbd)
    if showline
        lnd := line.new(bar_index - hiloc, lastphi,  showoncurr ? bar_index - h_locd : bar_index - hiloc, lwd, color = color.red, style = line.style_arrow_right)
    prctxt = showprice ? tostring(lastphi) + "\n" + tostring(lwd) + "\n" : ""
    ret = ""
    ret := ret[1]
    ret := showret ? hcont ? tostring((lastphi - lwd) / (lastphi - lastplo), '#.###')  + "\n" : ret : ""
    txt =  prctxt + ret + "-% " +  tostring(((lastphi - lwd) / lastphi) * 100, '#.#') 
    lbd := label.new(showoncurr ? bar_index - h_locd : bar_index - hiloc, lwd, text = txt, color = color.red, textcolor = color.white, style = label.style_label_up)


[lwu, h_locu] = _highest(loloc)
var line lnu = na
var label lbu = na
if loloc != 0 and lastplo != 0
    if change(lastplo) == 0 or lchg
        line.delete(lnu)
        label.delete(lbu)
    if showline
        lnu := line.new(bar_index - loloc, lastplo, showoncurr ? bar_index - h_locu : bar_index - loloc, lwu, color = color.lime, style = line.style_arrow_right)
    prctxt = showprice ? tostring(lastplo) + "\n" + tostring(lwu) + "\n" : ""
    ret = ""
    ret := ret[1]
    ret := showret ? lcont ? tostring((lwu - lastplo) / (lastphi - lastplo), '#.###')  + "\n" : ret : ""
    txt = prctxt + ret + "+% " + tostring(((lwu - lastplo) / lastplo) * 100, '#.#') 
    lbu := label.new(showoncurr ? bar_index - h_locu : bar_index - loloc, lwu, text = txt, color = color.lime, textcolor = color.black, style = label.style_label_down)

Overview

Price Change Rate by Pivot Points - Dynamic plots visual markers at detected pivots and draws lines with labels displaying percentage movements, prices, and retracement ratios relative to recent high and low points directly on the main price chart. Settings allow users to customize visible elements such as prices, retracement values, trend lines, and label anchor locations.

Details

Published by

SammyEnigma on GitHub

Code credit

LonesomeTheBlue, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Support & resistance, Trend

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.

Settings

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

SettingTypeDefaultVariable
Pivot Point Periodint30prd
Show Pivot Pointsbooltrueshowpivot
Show retracementbooltrueshowret
Show Pricesboolfalseshowprice
Show Linesbooltrueshowline
Show Label on current High/Lowboolfalseshowoncurr
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

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 4 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 6 weeks ago · None stated GitHub repository of AI Trend

Ichimoku Cloud

by harryguiacorn
219 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
219 stars

This indicator identifies local swing highs and swing lows to construct a Zig Zag pattern on the main price chart. It evaluates pivot points based on a customizable number of surrounding left and right bars. Using persistent variables, the script tracks previo

Indicator v4 Support & resistanceTrend Repaints
Updated 5 years ago · None stated GitHub repository of Teaching: Finding Highs and Lows 6

Dynamic Linear Regression

by TradersPost
218 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 3 months ago · None stated GitHub repository of Dynamic Linear Regression

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