Indicator · Pine Script v4 · On the chart

Pivots High/Low Analysis & Forecast [LuxAlgo]

by theonetrade· code credited to LuxAlgo

This indicator detects high and low pivots over a customizable length and analyzes patterns between consecutive pivot points.

View on GitHub

GitHub stars34on the repository
Pine versionv4older, still runs
Lines of code121
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

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

pivot_high_low_analysis_forecast_luxalgo_HBuT6e1v.pine
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=4
study("Pivots High/Low Analysis & Forecast [LuxAlgo]",overlay=true,max_lines_count=500,max_labels_count=500)
length     = input(50)
show_fcast = input(true,'Show Forecasted Pivots')

dash_loc = input("Bottom Right","Dashboard Location"
  ,options=["Top Right","Bottom Right","Top Left","Bottom Left"]
  ,group='Dashboard')

text_size = input('Normal',"Dashboard Size"
  ,options=["Tiny","Small","Normal","Large"]
  ,group='Dashboard')

txt_col = input(color.gray,'Text/Frame Color'
  ,group='Dashboard')
//----
barssince_ph = 0
barssince_pl = 0
rchange_ph = 0.
rchange_pl = 0.

//Get Current/Previous Pivots and their occurences
n = bar_index
dt = round(time-time[1])

ph = pivothigh(length,length)
pl = pivotlow(length,length)

ph_x2 = valuewhen(ph,n-length,1)
pl_x2 = valuewhen(pl,n-length,1)

ph_y2 = valuewhen(ph,ph,1)
pl_y2 = valuewhen(pl,pl,1)

//Display Lines/Labels
if ph
    barssince_ph := (n-length)-ph_x2
    rchange_ph := (ph - ph_y2)/ph_y2*100
    txt = str.format("Δ% : {0,number,#.##}\nΔt : {1}",rchange_ph, barssince_ph)
    
    css = ph > ph_y2 ? #2157f3 : #ff1100
    line.new(n-length,ph_y2,ph_x2,ph_y2,color=#ff1100,style=line.style_dotted)
    line.new(n-length,ph,n-length,ph_y2,color=css,style=line.style_arrow_both)
    
    label.new(n-length,max(ph,ph_y2),txt,
      color=#00000000,
      style=label.style_label_down,
      textcolor=color.gray,
      textalign=text.align_left,
      size=size.small)

if pl
    barssince_pl := (n-length)-pl_x2
    rchange_pl := (pl - pl_y2)/pl_y2*100
    txt = str.format("Δ% : {0,number,#.##}\nΔt : {1}",rchange_pl, barssince_pl)
    
    css = pl > pl_y2 ? #2157f3 : #ff1100
    line.new(n-length,pl_y2,pl_x2,pl_y2,color=#0cb51a,style=line.style_dotted)
    line.new(n-length,pl,n-length,pl_y2,color=css,style=line.style_arrow_both)
    
    label.new(n-length,min(pl,pl_y2),txt,
      color=#00000000,
      style=label.style_label_up,
      textcolor=color.gray,
      textalign=text.align_left,
      size=size.small)

//Stats
avg_barssince_ph = cum(barssince_ph)/cum(sign(barssince_ph))
avg_barssince_pl = cum(barssince_pl)/cum(sign(barssince_pl))

avg_rchange_ph = cum(rchange_ph)/cum(abs(sign(rchange_ph)))
avg_rchange_pl = cum(rchange_pl)/cum(abs(sign(rchange_pl)))

//Estimate future pivots positions
if show_fcast
    if ph
        x12 = n+min(int(avg_barssince_ph - length),500)
        line.delete(line.new(x12,high,x12,low
          ,extend=extend.both,color=#ff1100,style=line.style_dashed)[1])
        line.delete(line.new(n-length,ph,n,ph
          ,extend=extend.right,color=#ff1100,style=line.style_dotted)[1])

if pl
    x12 = n+min(int(avg_barssince_pl - length),500)
    line.delete(line.new(x12,high,x12,low
      ,extend=extend.both,color=#0cb51a,style=line.style_dashed)[1])
    line.delete(line.new(n-length,pl,n,pl
      ,extend=extend.right,color=#0cb51a,style=line.style_dotted)[1])

//Table
var table_position = dash_loc == 'Top Left' ? position.top_left :
  dash_loc == 'Bottom Left' ? position.bottom_left :
  dash_loc == 'Top Right' ? position.top_right : position.bottom_right

var table_text_size = text_size == 'Tiny' ? size.tiny :
  text_size == 'Small' ? size.small :
  text_size == 'Normal' ? size.normal : size.large

new_table = table.new(table_position,3,3
  ,border_color=txt_col,border_width=1
  ,frame_color=txt_col,frame_width=1)

if barstate.islast
    table.cell(new_table,0,1,'Pivot High',text_color=txt_col,text_size=table_text_size)
    table.cell(new_table,0,2,'Pivot Low',text_color=txt_col,text_size=table_text_size)
    
    table.cell(new_table,1,0,'E[Δt]',text_color=txt_col,text_size=table_text_size)
    table.cell(new_table,2,0,'E[Δ%]',text_color=txt_col,text_size=table_text_size)
    
    table.cell(new_table,1,1,tostring(avg_barssince_ph,'#.##'),text_color=txt_col,text_size=table_text_size)
    table.cell(new_table,1,2,tostring(avg_barssince_pl,'#.##'),text_color=txt_col,text_size=table_text_size)
    
    table.cell(new_table,2,1,tostring(avg_rchange_ph,'#.##'),text_color=txt_col,text_size=table_text_size)
    table.cell(new_table,2,2,tostring(avg_rchange_pl,'#.##'),text_color=txt_col,text_size=table_text_size)

//Plot
plot(ph,"Pivot High",#ff1100,2,plot.style_circles,offset=-length)
plot(pl,"Pivot Low",#0cb51a,2,plot.style_circles,offset=-length)

Overview

Pivots High/Low Analysis & Forecast [LuxAlgo] calculates and displays the percentage change and bar count elapsed between consecutive pivots directly on the price chart using connected lines and labels. An optional forecast projects future pivot timing based on the average duration between historical pivots. Additionally, it displays a customizable statistics dashboard table on the chart.

Details

Published by

theonetrade on GitHub

Code credit

LuxAlgo, as written in the script's header

Type

Indicator, Pine Script v4

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
lengthint50length
Show Forecasted Pivotsbooltrueshow_fcast
Dashboard LocationstringBottom Rightdash_loc
Dashboard SizestringNormaltext_size
Text/Frame Colorcolorcolor.graytxt_col
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 overlay indicator scans a pasted list of symbols for ICT liquidity sweep patterns using prior swing sweeps. The screening method looks back one, two, or three swings and can list long and short signals in a results table with adjustable rows, position, an

Indicator v5 SMC / ICT / price actionScreeners & dashboards
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Liquidity Sweep Pattern Scanner
368 stars

This indicator monitors multiple cryptocurrency symbols for trading signals. It calculates and plots entry prices, take profit, and stop loss levels for each symbol including BTCUSDT, ETHUSDT, BNBUSDT and others. Price crossovers trigger buy, sell or close ale

Indicator v5 Support & resistanceScreeners & dashboards
Updated 3 months ago · None stated GitHub repository of Multi Alert Long/Short [Alorse]

BZ-tracker

by Allen1212
302 stars

The BZ-tracker indicator marks ARK Invest buy and sell transactions on stock charts with labels. It plots green labels for purchases and red labels for sales, each annotated with a multiplier such as X1 or X2 to show the number of ARK ETFs trading the stock on

Indicator v4 Support & resistanceScreeners & dashboards
Updated 3 years ago · None stated GitHub repository of BZ-tracker
257 stars

This indicator overlays an intraday SPX and ES chart with a midnight session range, regular-trading-hours opening levels, and a VWAP projection box. It draws the midnight high, mid, and low, flags edge rejections within an absolute tolerance, and plots optiona

Indicator v6 TrendSupport & resistance
Updated 2 months ago · None stated GitHub repository of SPX Midnight Box + Snag Logic

Golden Bullet Strategy

by TradersPost
228 stars

The Golden Bullet Strategy is an overlay signal indicator based on Smart Money Concepts and time-based liquidity models. It identifies liquidity sweeps of a designated reference session range during a specified hunt window. It then confirms Market Structure Sh

Indicator v6 SMC / ICT / price actionSessions & time
Updated 4 months ago · None stated GitHub repository of Golden Bullet Strategy

More Support & resistance 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