Indicator · Pine Script v6 · On the chart

Previous Day High-Low (PDHL)

by realanthonyc

This indicator plots the previous trading day's high and low on the price chart, together with the developing high and low of the current session.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code108
Settings2inputs
LicenceMPL-2.0
Last update8 months ago27 Feb 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

108 lines of Pine Script v6 from pdhl.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

pdhl.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © realanthonyc https://www.tradingview.com/u/realanthonyc

//@version=6
// --------------------------------------------------------------------
//  Previous Day High-Low (PDHL)
//  On Github: https://github.com/realanthonyc/PDHL
//  v1.1.0
// --------------------------------------------------------------------
indicator("Previous Day High-Low (PDHL)", shorttitle = "PDHL", format = format.price, overlay = true, precision = 2, max_lines_count = 450)

// === Inputs ===
string sessionInput = input.session("0930-1600", "Trading Session", tooltip = "Only prices within this time window are recorded. Use 0930-1600 for US Stocks or 0000-0000 for Crypto.")
int midHour = input.int(12, "Initial Position Hour", minval = 0, maxval = 23, tooltip = "The X-axis position before this hour will be fixed here.")
string timeZone = syminfo.timezone

// === Colors ===
color colorCore = color.rgb(235, 143, 5)
color colorExt = color.new(color.yellow, 0)

// === Fetch Last Trading Day's Data ===
// Referencing high[1] on Daily timeframe ensures we get the most recently closed daily bar.
float pdhRaw = request.security(syminfo.tickerid, "D", high[1], lookahead = barmerge.lookahead_on)
float pdlRaw = request.security(syminfo.tickerid, "D", low[1], lookahead = barmerge.lookahead_on)

// === Session & Price Tracking ===
bool inSession = not na(time(timeframe.period, sessionInput, timeZone))
bool isNewDay = ta.change(time("D", timeZone)) != 0
bool isSessionStart = inSession and (not inSession[1] or isNewDay)

var float stablePrevHigh = na
var float stablePrevLow = na
var float currentSessionHigh = na
var float currentSessionLow = na

// Update Previous Day values and reset Current Session values at the start of a new session
if isSessionStart
    stablePrevHigh := pdhRaw
    stablePrevLow := pdlRaw
    currentSessionHigh := high
    currentSessionLow := low
else if inSession
    currentSessionHigh := math.max(nz(currentSessionHigh, high), high)
    currentSessionLow := math.min(nz(currentSessionLow, low), low)

// === X-Axis Calculation Logic ===
int endHourParsed = int(str.tonumber(str.substring(sessionInput, 5, 7)))
int endMinParsed = int(str.tonumber(str.substring(sessionInput, 7, 9)))
bool isFullDay = sessionInput == "0000-0000"
int finalEndHour = isFullDay and endHourParsed == 0 ? 23 : endHourParsed
int finalEndMin = isFullDay and endHourParsed == 0 ? 59 : endMinParsed

get_x_pos(t) =>
    // Session end for the bar's day
    int sessionEndTs = timestamp(timeZone, year(t, timeZone), month(t, timeZone), dayofmonth(t, timeZone), finalEndHour, finalEndMin)
    int midTs = timestamp(timeZone, year(t, timeZone), month(t, timeZone), dayofmonth(t, timeZone), midHour, 0)
    
    int xPos = sessionEndTs
    
    bool isToday = year(t, timeZone) == year(timenow, timeZone) and month(t, timeZone) == month(timenow, timeZone) and dayofmonth(t, timeZone) == dayofmonth(timenow, timeZone)
    
    if isToday
        if t < midTs
            xPos := midTs
        else
            // Dynamic push forward by 1 hour, capped at session end
            xPos := math.min(t + 3600000, sessionEndTs)
    else
        // For historical days: fix at the session end of that day
        xPos := sessionEndTs
    
    xPos

// === Drawing Logic ===
var line liveCore = na
var line liveTop = na
var line liveBot = na

if inSession and not na(stablePrevHigh) and not na(stablePrevLow)
    int targetX = get_x_pos(time)
    
    if isSessionStart
        // Create new lines for the current session
        // When lines exceed max_lines_count (450), oldest lines are auto-deleted by Pine Script.
        liveCore := line.new(targetX, stablePrevLow, targetX, stablePrevHigh, xloc = xloc.bar_time, color = colorCore, width = 2)
        liveTop := line.new(targetX, stablePrevHigh, targetX, stablePrevHigh, xloc = xloc.bar_time, color = colorExt, width = 2)
        liveBot := line.new(targetX, stablePrevLow, targetX, stablePrevLow, xloc = xloc.bar_time, color = colorExt, width = 2)
    else if not na(liveCore)
        // Update lines dynamically during the session
        line.set_x1(liveCore, targetX)
        line.set_y1(liveCore, stablePrevLow)
        line.set_x2(liveCore, targetX)
        line.set_y2(liveCore, stablePrevHigh)
        
        // Yellow Extensions
        if not na(currentSessionHigh) and currentSessionHigh > stablePrevHigh
            line.set_xy1(liveTop, targetX, stablePrevHigh)
            line.set_xy2(liveTop, targetX, currentSessionHigh)
        else
            line.set_xy1(liveTop, na, na)
            line.set_xy2(liveTop, na, na)
           
        if not na(currentSessionLow) and currentSessionLow < stablePrevLow
            line.set_xy1(liveBot, targetX, stablePrevLow)
            line.set_xy2(liveBot, targetX, currentSessionLow)
        else
            line.set_xy1(liveBot, na, na)
            line.set_xy2(liveBot, na, na)

Overview

Previous Day High-Low (PDHL) reads the last closed daily high and low and locks those values at the start of each session. A session window limits which bars are recorded, and an hour setting controls where the horizontal lines sit on the time axis before that hour. Lines extend toward the session end. It is an overlay indicator and does not generate trade entries or exits.

Details

Published by

realanthonyc on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Support & resistance, Sessions & time

Markets

Stocks, Crypto

Timeframes

M15-H1

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
Trading Sessionsession0930-1600sessionInput
Initial Position Hourint12midHour
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 builds Market Profile Time Price Opportunity (TPO) structures across defined session timeframes directly on the main price chart. It visualizes the Point of Control (POC) and Value Area boundaries using dynamic box drawings. An integrated multi-

Indicator v5 Support & resistanceScreeners & dashboards
Updated 1 year ago · MPL-2.0 GitHub repository of Market Profile with Screener
257 stars

This indicator plots auto trade signals for E-mini S&P 500 futures on the price chart. It computes an EMA200 filter along with day ETH RTH session levels and percentage-based entry zones. Signals trigger CALL or PUT cases when price crosses defined thresholds

Indicator v6 TrendSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of Auto Trade Futures ES
219 stars

This indicator plots reference levels for previous daily high and low prices directly on the price chart. It requests daily timeframe data using the security function and plots the offset values as continuous lines, displaying resistance in red and support in

Indicator v4 Support & resistanceSessions & time
Updated 5 years ago · None stated GitHub repository of 昨日高低點標示

Golden Bullet Strategy

by TradersPost
218 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

Moon Dev GEX Arrows

by moondevonyt
92 stars

This overlay indicator plots option strike walls and an optional session VWAP on the price chart for SPY or ES. It spaces major strikes by the selected instrument, draws a set number of strikes on each side, and marks wall-trap and sweep events after a cooldow

Indicator v5 Support & resistanceSessions & time
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev GEX Arrows

Key Levels

by cryptorife
75 stars

This indicator plots reference levels and session markers directly on the price chart. It calculates and draws lines for the daily open, weekly open, monthly open, previous day OHLC, and previous week extremes, along with a selectable day-of-week range and ini

Indicator v4 Support & resistanceSessions & time Repaints
Updated 3 years ago · GPL-3.0 GitHub repository of Key Levels

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