Skip to content
All library documents

Pivot Points from Sliding-Window Highs and Lows

Article Quant Q&A · Author: xendi

Summary

The document asks how to reproduce TradingView’s Pivot Points High Low indicator for use in code. The replies describe a standard pivot approach: scan a rolling window and mark its middle observation as a high pivot when it is the maximum, or as a low pivot when it is the minimum. One reply also points to a Pine-style implementation that uses separate left and right lookback lengths, can use highs and lows or closing prices, and carries forward the most recent detected pivot for display.

This gives a practical conceptual recipe for identifying local turning points, but it does not establish that TradingView’s built-in indicator uses precisely this algorithm. The suggested window lengths are configurable, and pivot confirmation requires observations on the right side of the candidate point, so signals are recognized with delay. The discussion offers an implementation clue rather than a validated comparison against TradingView output.

Key ideas

  • A pivot high can be defined as a local maximum within a sliding window.
  • A pivot low can be defined as a local minimum within a sliding window.
  • Separate left and right window lengths determine which neighboring bars qualify a pivot.
  • A pivot requiring bars to its right is confirmed only after those bars arrive.
  • The replies do not verify that this method exactly matches TradingView’s built-in indicator.

Tags

Full text
# Which Pivot Point Algorithm Does TradingView Use?


# Which Pivot Point Algorithm Does TradingView Use?












TradingView has an indicator in their standard/built-in library called "Pivot Points High Low." When combined with Renko, it gives a really clean signal and I'd like to use it in code.

The problem is, this indicator wasn't coded in Pine script. It's probably being calculated on their backend. I want to use whatever algorithm they used in my Python code so I ask you all here: Do you know what's in use there?

## Answer by durotan (score 1)

https://quant.stackexchange.com/a/63354

here you are bro

```
study("Pivots HL",overlay = true)
x = input(title = "left", type = input.integer, defval = 100)
y = input(title = "right", type = input.integer, defval = 100)
source = input(title = "Source", type = input.string, defval="High/Low", options = ["High/Low","Close"])

src_high = source == "Close" ? close : high
src_low = source == "Close" ? close : low

pivot_high = pivothigh(src_high,x,y)
pivot_low = pivotlow(src_low,x,y)
hbars = highestbars(src_high,x)
lbars = lowestbars(src_low,x)

if na(pivot_high)
    pivot_high := pivot_high[1]
if na(pivot_low)
    pivot_low :=pivot_low[1]

if pivot_high != pivot_high[1]
    line.new(bar_index + hbars, pivot_high, bar_index, pivot_high, xloc = xloc.bar_index, color = color.lime)
if pivot_low != pivot_low[1]
    line.new(bar_index + lbars, pivot_low, bar_index, pivot_low, xloc = xloc.bar_index, color = color.red)
```

## Answer by OTmn (score 0)

https://quant.stackexchange.com/a/53723

I'm not a gourou in finiancial trading indicators but the algo seams simple to implement.

It uses a sliding window on the data.

Lets say the sliding window is 3 and you first trying to find the High pivot points:

You slide your window from the begining and whenever the middle (out of the 3) figure is a Max value, it is labelled as a pivot point.

For the lows, you are looking for the middle to be a Min instead of Max.

If im right you should have such a configuration on the indicator (length of the sliding window maybe).

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.