Skip to content

Get the TradingView chart's lowest value with Pine Script

Get the TradingView chart’s lowest value with Pine Script

Section titled “Get the TradingView chart’s lowest value with Pine Script”

TL;DR
Walk a series with a persistent var so you always know the lowest value visible on the chart, regardless of timeframe or data gaps.

DifficultyBeginner
Time to implement10-15 min
CategoryUtility
//@version=5
indicator("Chart lowest", overlay=false)
var float chartLowest = na
chartLowest := na(chartLowest) ? low : math.min(chartLowest, low)
plot(chartLowest, "Lowest low on chart", color=color.red)
Remember. The result depends on how many bars TradingView loads. Zooming or requesting more history can change the chart-wide minimum.

TradingView charts can span years of data. When you need to mark the lowest low (or the lowest value of any custom series) for visual cues, alerts, or risk controls, scanning the entire visible history manually is not feasible. A lightweight helper function keeps a running minimum so you can reuse it across scripts.

  • Creating a persistent helper that tracks the lowest value in a series
  • Reusing the helper for lows, moving averages, or custom series with gaps
  • Displaying the chart-wide minimum and updating it when new data loads
  • Guarding against na values and history limitations
CallPurpose
varPersists the lowest value across bars.
math.min(a, b)Compares current data against the stored minimum.
nz(value, default)Provides a fallback when the persistent series is na.
plot(series)Visualises the running minimum on the chart.
timeframe.expand(Optional) Loads additional history if you need a longer window.
  1. Store the running minimum in a persistent variable
    Initialise the variable with the first value, then compare each new bar.

    var float lowestSeries = dataSeries
    lowestSeries := math.min(lowestSeries, dataSeries)
  2. Handle na inputs gracefully
    Data with gaps (e.g., conditional series) should skip na values.

    if not na(dataSeries)
    lowestSeries := math.min(lowestSeries, dataSeries)
  3. Expose the helper as a reusable function
    Wrap the logic so you can request the chart lowest for any series.

    chartLowest(series float) =>
    var float lowest = series
    if not na(series)
    lowest := math.min(lowest, series)
    lowest
//@version=5
indicator("Chart-wide lows", overlay=true)
chartLowest(series float) =>
var float lowest = series
if not na(series)
lowest := math.min(lowest, series)
lowest
lowestLow = chartLowest(low)
emaValue = ta.ema(close, 50)
lowestEMA = chartLowest(emaValue)
fridayClose = dayofweek == dayofweek.friday ? close : na
lowestFri = chartLowest(fridayClose)
plot(lowestLow, "Lowest low", color=color.red)
plot(lowestEMA, "Lowest EMA", color=color.orange)
plot(lowestFri, "Lowest Friday close", color=color.teal)
Why this works.
  • The `var` variable remembers prior minima, even when the helper is called multiple times.
  • Series with gaps (Friday closes) still update correctly because `na` values are ignored.
  • Multiple calls reuse the same logic to track different series simultaneously.
  • The chart-wide minimum is not necessarily the all-time low—it reflects only the bars currently loaded.
  • If you change symbols or zoom levels, the helper automatically recomputes after the new data loads.
  • To reset the minimum (e.g., for session-based tracking), reinitialise the var whenever your session boundary is reached.
  • For highest values, mirror the logic using math.max.

TradingView loads additional bars when you scroll back. More history can introduce lower lows, so the running minimum updates accordingly.

Reset the persistent variable when session.isfirstbar is true, or maintain separate minima per session using a dictionary.

  • A simple var + math.min pattern lets you track chart-wide minima for any series.
  • Always account for na values and the current history window.
  • Reuse the helper to highlight extremes, build alerts, or compute drawdown references.
  • Extend the idea to maxima or other cumulative statistics with minimal changes.

Adapted from tradingcode.net, optimised for Algo Trade Analytics users.