Indicator · Pine Script v5 · On the chart

Last n Swing High Low Table

by mikeyhu70· code credited to congacindy

Detects swing highs and swing lows from left and right bar counts and keeps the most recent ones, with their dates, in a table on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code67
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update6 months ago15 Apr 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

67 lines of Pine Script v5 from Swing/Last n Swing High Low Table.ps, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Last n Swing High Low Table.ps
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © congacindy

//@version=5
indicator("Last n Swing High Low Table", overlay = true)

// Inputs
leftBars = input.int(12, "Left Bars", minval=1)
rightBars = input.int(12, "Right Bars", minval=1)
nswing = input.int(5, "Number of Swing?", minval=1)
nStore= input.int(10, "Number of Swing?", minval=1)

// Get swing high and low
pivotHigh = ta.pivothigh(high, leftBars, rightBars)
pivotLow = ta.pivotlow(low, leftBars, rightBars)
txt_col_bull = input.color(color.rgb(62, 227, 169), 'Text/Frame Color', group='Dashboard')
txt_col_bear = input.color(color.rgb(223, 17, 140), 'Text/Frame Color', group='Dashboard')
txt_col = input.color(color.rgb(182, 186, 200), 'Text/Frame Color', group='Dashboard')
dash_loc = input.string('Top Right', 'Dashboard Location', options=['Top Right', 'Bottom Right', 'Top Left', 'Bottom Left'], group='Dashboard')
text_size = input.string('Tiny', 'Dashboard Size', options=['Tiny', 'Small', 'Normal', 'Large'], group='Dashboard')


// Store last 10 swing high and low values
var float[] lastHighs = array.new_float(nswing)
var float[] lastLows = array.new_float(nswing)
var int[] lastHighDates = array.new_int(nswing)
var int[] lastLowDates = array.new_int(nswing)

if pivotHigh
    array.unshift(lastHighs, high[rightBars])
    array.unshift(lastHighDates, time[rightBars])
    if array.size(lastHighs) > nStore
        array.pop(lastHighs)
        array.pop(lastHighDates)

if pivotLow
    array.unshift(lastLows, low[rightBars])
    array.unshift(lastLowDates, time[rightBars])
    if array.size(lastLows) > nStore
        array.pop(lastLows)
        array.pop(lastLowDates)


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

// Create table
var table swingTable = table.new(table_position, 4, 11, border_color=txt_col,border_width=1,frame_color=txt_col,frame_width=1)


// Populate table
if barstate.islast
    table.cell(swingTable, 0, 0, "Date", text_color=txt_col, text_size=table_text_size)
    table.cell(swingTable, 1, 0, "Lows", text_color=txt_col, text_size=table_text_size)
    table.cell(swingTable, 2, 0, "Date", text_color=txt_col, text_size=table_text_size)
    table.cell(swingTable, 3, 0, "High", text_color=txt_col, text_size=table_text_size)

    //table.cell(swingTable, 0, 1, str.tostring(array.get(lastHighs, 0), format.mintick), bgcolor=color.white, text_size = size.tiny)
    //table.cell(swingTable, 1, 1, str.format("{0,date,yyyy-MM-dd}", array.get(lastHighDates, 0)), bgcolor=color.white, text_size = size.tiny)
    //table.cell(swingTable, 2, 1, str.tostring(array.get(lastLows, 0), format.mintick), bgcolor=color.white, text_size = size.tiny)
    //table.cell(swingTable, 3, 1, str.format("{0,date,yyyy-MM-dd}", array.get(lastLowDates, 0)), bgcolor=color.white, text_size = size.tiny)

    for i = 0 to nswing-1
        table.cell(swingTable, 0, i+1, str.format("{0,date,yyyy-MM-dd}", array.get(lastLowDates, i)), text_color=txt_col_bull, text_size=table_text_size)
        table.cell(swingTable, 1, i+1, str.tostring(array.get(lastLows,i), format.mintick), text_color=txt_col_bull, text_size=table_text_size)
        table.cell(swingTable, 2, i+1, str.format("{0,date,yyyy-MM-dd}", array.get(lastHighDates, i)), text_color=txt_col_bear, text_size=table_text_size)
        table.cell(swingTable, 3, i+1, str.tostring(array.get(lastHighs, i), format.mintick), text_color=txt_col_bear, text_size=table_text_size)

Overview

Settings choose the bar counts, how many swings to track, and the table position, size and text colours. Swings are confirmed only after the right-hand bars close, so they appear with a delay. It is an information display with no trade signals.

Details

Published by

mikeyhu70 on GitHub

Code credit

congacindy, 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.

Settings

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

SettingTypeDefaultVariable
Left Barsint12leftBars
Right Barsint12rightBars
Number of Swing?int5nswing
Number of Swing?int10nStore
Text/Frame Colorcolorcolor.rgb(62, 227, 169)txt_col_bull
Text/Frame Colorcolorcolor.rgb(223, 17, 140)txt_col_bear
Text/Frame Colorcolorcolor.rgb(182, 186, 200)txt_col
Dashboard LocationstringTop Rightdash_loc
Dashboard SizestringTinytext_size
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
330 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 2 months ago · None stated GitHub repository of Multi Alert Long/Short [Alorse]

BZ-tracker

by Allen1212
303 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 2 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 6 weeks 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 3 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