Indicator · Pine Script v5 · On the chart

Prior Day Levels

by g-moe· code credited to goodgains

Prior Day Levels plots horizontal reference lines for the previous day's high, low, close, and midpoint, plus the previous week's high, low, close, and midpoint.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code278
Settings40inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 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

278 lines of Pine Script v5 from Tradingview/prior-day-levels.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

prior-day-levels.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
indicator("Prior Day Levels", overlay = true)

// @keywords: prior-day-levels, prior-day-high, prior-day-low, prior-day-close, prior-day-mid, prior-week-high, prior-week-low, prior-week-close, prior-week-mid, horizontal-levels, daily-reference, weekly-reference, level-lines, session-time, extended-lines, level-styles, configurable-display, previous-period, reference-levels, overlay-levels

// prior day settings
pd_display_max = 'D'

use_pdh_levels = input.bool(true, title = 'PDH', group = 'Prior Day Settings', inline = '1')
css_pdh = input.color(color.new(color.gray,35), title = '', group = 'Prior Day Settings', inline = '1')
style_pdh = input.string('Solid', title = '', options = ['Solid', 'Dotted', 'Dashed'], group = 'Prior Day Settings', inline = '1')
width_pdh = input.int(1, title = '', minval = 1, maxval = 5, group = 'Prior Day Settings', inline = '1')

use_pdl_levels = input.bool(true, title = 'PDL', group = 'Prior Day Settings', inline = '2')
css_pdl = input.color(color.new(color.gray,35), title = '', group = 'Prior Day Settings', inline = '2')
style_pdl = input.string('Solid', title = '', options = ['Solid', 'Dotted', 'Dashed'], group = 'Prior Day Settings', inline = '2')
width_pdl = input.int(1, title = '', minval = 1, maxval = 5, group = 'Prior Day Settings', inline = '2')

use_pdc_levels = input.bool(false, title = 'PDC', group = 'Prior Day Settings', inline = '3')
css_pdc = input.color(color.new(color.gray,35), title = '', group = 'Prior Day Settings', inline = '3')
style_pdc = input.string('Solid', title = '', options = ['Solid', 'Dotted', 'Dashed'], group = 'Prior Day Settings', inline = '3')
width_pdc = input.int(1, title = '', minval = 1, maxval = 5, group = 'Prior Day Settings', inline = '3')

use_pdm_levels = input.bool(true, title = 'PDM', group = 'Prior Day Settings', inline = '4')
css_pdm = input.color(color.new(color.gray,35), title = '', group = 'Prior Day Settings', inline = '4')
style_pdm = input.string('Dashed', title = '', options = ['Solid', 'Dotted', 'Dashed'], group = 'Prior Day Settings', inline = '4')
width_pdm = input.int(1, title = '', minval = 1, maxval = 5, group = 'Prior Day Settings', inline = '4')


// prior week settings
pw_display_max = 'W'

use_pwh_levels = input.bool(true, title = 'PWH', group = 'Prior Week Settings', inline = '1')
css_pwh = input.color(color.new(color.yellow,35), title = '', group = 'Prior Week Settings', inline = '1')
style_pwh = input.string('Solid', title = '', options = ['Solid', 'Dotted', 'Dashed'], group = 'Prior Week Settings', inline = '1')
width_pwh = input.int(1, title = '', minval = 1, maxval = 5, group = 'Prior Week Settings', inline = '1')

use_pwl_levels = input.bool(true, title = 'PWL', group = 'Prior Week Settings', inline = '2')
css_pwl = input.color(color.new(color.yellow,35), title = '', group = 'Prior Week Settings', inline = '2')
style_pwl = input.string('Solid', title = '', options = ['Solid', 'Dotted', 'Dashed'], group = 'Prior Week Settings', inline = '2')
width_pwl = input.int(1, title = '', minval = 1, maxval = 5, group = 'Prior Week Settings', inline = '2')

use_pwc_levels = input.bool(false, title = 'PWC', group = 'Prior Week Settings', inline = '3')
css_pwc = input.color(color.new(color.yellow,35), title = '', group = 'Prior Week Settings', inline = '3')
style_pwc = input.string('Solid', title = '', options = ['Solid', 'Dotted', 'Dashed'], group = 'Prior Week Settings', inline = '3')
width_pwc = input.int(1, title = '', minval = 1, maxval = 5, group = 'Prior Week Settings', inline = '3')

use_pwm_levels = input.bool(true, title = 'PWM', group = 'Prior Week Settings', inline = '4')
css_pwm = input.color(color.new(color.yellow,35), title = '', group = 'Prior Week Settings', inline = '4')
style_pwm = input.string('Dashed', title = '', options = ['Solid', 'Dotted', 'Dashed'], group = 'Prior Week Settings', inline = '4')
width_pwm = input.int(1, title = '', minval = 1, maxval = 5, group = 'Prior Week Settings', inline = '4')



// session settings
sess_display_max = '30'
session_time = input.session('0930-1600', title = 'Session Time', group = 'Session Settings', inline = 'a')

use_sessh_levels = input.bool(false, title = 'Session H', group = 'Session Settings', inline = '1')
css_sessh = input.color(color.new(color.blue,35), title = '', group = 'Session Settings', inline = '1')
style_sessh = input.string('Solid', title = '', options = ['Solid', 'Dotted', 'Dashed'], group = 'Session Settings', inline = '1')
width_sessh = input.int(1, title = '', minval = 1, maxval = 5, group = 'Session Settings', inline = '1')

use_sessl_levels = input.bool(false, title = 'Session L', group = 'Session Settings', inline = '2')
css_sessl = input.color(color.new(color.blue,35), title = '', group = 'Session Settings', inline = '2')
style_sessl = input.string('Solid', title = '', options = ['Solid', 'Dotted', 'Dashed'], group = 'Session Settings', inline = '2')
width_sessl = input.int(1, title = '', minval = 1, maxval = 5, group = 'Session Settings', inline = '2')

use_sessm_levels = input.bool(true, title = 'Session M', group = 'Session Settings', inline = '4')
css_sessm = input.color(color.new(color.blue,35), title = '', group = 'Session Settings', inline = '4')
style_sessm = input.string('Dashed', title = '', options = ['Solid', 'Dotted', 'Dashed'], group = 'Session Settings', inline = '4')
width_sessm = input.int(1, title = '', minval = 1, maxval = 5, group = 'Session Settings', inline = '4')

// calc prior levels
tf_sec = timeframe.in_seconds('')
pd_can_display = tf_sec <= timeframe.in_seconds(pd_display_max) 
pw_can_display = tf_sec <= timeframe.in_seconds(pw_display_max)
sess_can_display = tf_sec <= timeframe.in_seconds(sess_display_max)

var float   track_pdh = 0.00
var int     track_pdhbn = 0
var float   track_pdl = 0.00
var int     track_pdlbn = 0

var float   track_pwh = 0.00
var int     track_pwhbn = 0
var float   track_pwl = 0.00
var int     track_pwlbn = 0

new_day = ta.change(time('D'))
new_week = ta.change(time('W'))

var float   pdh = 0.00
var int     pdhbn = 0
var float   pdl = 0.00
var int     pdlbn = 0
var float   pdc = 0.00
var int     pdcbn = 0
var float   pdm = 0.00

var float   pwh = 0.00
var int     pwhbn = 0
var float   pwl = 0.00
var int     pwlbn = 0
var float   pwc = 0.00
var int     pwcbn = 0
var float   pwm = 0.00


track_pdh   := new_day ? high : high > track_pdh[1]  ? high : track_pdh[1]
track_pdhbn := new_day ? time : high > track_pdh[1]  ? time : track_pdhbn[1]
track_pdl   := new_day ? low : low < track_pdl[1] ? low : track_pdl[1]
track_pdlbn := new_day ? time : low < track_pdl[1]  ? time : track_pdlbn[1]

track_pwh   := new_week ? high : high > track_pwh[1]  ? high : track_pwh[1]
track_pwhbn := new_week ? time : high > track_pwh[1]  ? time : track_pwhbn[1]
track_pwl   := new_week ? low : low < track_pwl[1] ? low : track_pwl[1]
track_pwlbn := new_week ? time : low < track_pwl[1]  ? time : track_pwlbn[1]


pdh     := new_day ? track_pdh[1] : pdh[1]
pdhbn   := new_day ? track_pdhbn[1] : pdhbn[1]
pdl     := new_day ? track_pdl[1] : pdl[1]
pdlbn   := new_day ? track_pdlbn[1] : pdlbn[1]
pdc     := new_day ? close[1] : pdc[1]
pdcbn   := new_day ? time[1] : pdcbn[1]
pdm     := (pdh + pdl) / 2

pwh     := new_week ? track_pwh[1] : pwh[1]
pwhbn   := new_week ? track_pwhbn[1] : pwhbn[1]
pwl     := new_week ? track_pwl[1] : pwl[1]
pwlbn   := new_week ? track_pwlbn[1] : pwlbn[1]
pwc     := new_week ? close[1] : pwc[1]
pwcbn   := new_week ? time[1] : pwcbn[1]
pwm     := (pwh + pwl) / 2



// [pdh, pdl, pdc, pdm] = request.security(syminfo.tickerid, 'D', [high[1], low[1], close[1], (high[1] + low[1]) / 2], lookahead = barmerge.lookahead_on)
// [pwh, pwl, pwc, pwm] = request.security(syminfo.tickerid, 'W', [high[1], low[1], close[1], (high[1] + low[1]) / 2], lookahead = barmerge.lookahead_on)

is_session = time(timeframe.period, str.format('{0}:1234567', session_time), 'America/New_York')
var sess_high = 0.0
var sess_low = 0.0
var sess_mid = 0.0
var int sess_bn = 0

var line l_sess_high = na
var line l_sess_low = na
var line l_sess_mid = na

if is_session
    if not is_session[1]
        sess_low := low
        sess_high := high
        sess_bn := time
    else 
        sess_low := math.min(low, sess_low)
        sess_high := math.max(high, sess_high)
else if not is_session
    sess_low := sess_low[1]
    sess_high := sess_high[1]
    
sess_mid := (sess_high + sess_low) / 2


// display levels
// var int new_day_bn = 0
// var int new_week_bn = 0
// new_day_bn := ta.change(time('D')) ? time : new_day_bn[1]
// new_week_bn := ta.change(time('W')) ? time : new_week_bn[1]

var line pdh_line = na
var line pdl_line = na
var line pdc_line = na
var line pdm_line = na

var line pwh_line = na
var line pwl_line = na
var line pwc_line = na
var line pwm_line = na

f_styles(style_input) =>
    return_style = switch style_input
        "Solid" => line.style_solid
        "Dotted" => line.style_dotted
        "Dashed" => line.style_dashed


// draw on chart load
if barstate.islastconfirmedhistory
    if pd_can_display
        if use_pdh_levels
            pdh_line := line.new(x1 = pdhbn, y1 = pdh, x2 = time+1, y2 = pdh, xloc = xloc.bar_time,
             extend = extend.right, color = css_pdh, width = width_pdh, style = f_styles(style_pdh))
        if use_pdl_levels
            pdl_line := line.new(x1 = pdlbn, y1 = pdl, x2 = time+1, y2 = pdl, xloc = xloc.bar_time,
             extend = extend.right, color = css_pdl, width = width_pdl, style = f_styles(style_pdl))
        if use_pdc_levels
            pdc_line := line.new(x1 = pdcbn, y1 = pdc, x2 = time+1, y2 = pdc, xloc = xloc.bar_time,
             extend = extend.right, color = css_pdc, width = width_pdc, style = f_styles(style_pdc))
        if use_pdm_levels
            pdm_line := line.new(x1 = pdcbn, y1 = pdm, x2 = time+1, y2 = pdm, xloc = xloc.bar_time,
             extend = extend.right, color = css_pdm, width = width_pdm, style = f_styles(style_pdm))
         
    if pw_can_display
        if use_pwh_levels
            pwh_line := line.new(x1 = pwhbn, y1 = pwh, x2 = time+1, y2 = pwh, xloc = xloc.bar_time,
             extend = extend.right, color = css_pwh, width = width_pwh, style = f_styles(style_pwh))
        if use_pwl_levels
            pwl_line := line.new(x1 = pwlbn, y1 = pwl, x2 = time+1, y2 = pwl, xloc = xloc.bar_time,
             extend = extend.right, color = css_pwl, width = width_pwl, style = f_styles(style_pwl))
        if use_pwc_levels
            pwc_line := line.new(x1 = pwcbn, y1 = pwc, x2 = time+1, y2 = pwc, xloc = xloc.bar_time,
             extend = extend.right, color = css_pwc, width = width_pwc, style = f_styles(style_pwc))
        if use_pwm_levels
            pwm_line := line.new(x1 = pwcbn, y1 = pwm, x2 = time+1, y2 = pwm, xloc = xloc.bar_time,
             extend = extend.right, color = css_pwm, width = width_pwm, style = f_styles(style_pwm))


    if sess_can_display         
        if use_sessh_levels
            l_sess_high := line.new(x1 = sess_bn, y1 = sess_high, x2 = time+1, y2 = sess_high, xloc = xloc.bar_time,
             extend = extend.right, color = css_sessh, width = width_sessh, style = f_styles(style_sessh))
        if use_sessl_levels
            l_sess_low := line.new(x1 = sess_bn, y1 = sess_low, x2 = time+1, y2 = sess_low, xloc = xloc.bar_time,
             extend = extend.right, color = css_sessl, width = width_sessl, style = f_styles(style_sessl))
        if use_sessm_levels
            l_sess_mid := line.new(x1 = sess_bn, y1 = sess_mid, x2 = time+1, y2 = sess_mid, xloc = xloc.bar_time,
             extend = extend.right, color = css_sessm, width = width_sessm, style = f_styles(style_sessm))


// update on new day or week session
if barstate.islast
    if pd_can_display
        if new_day
            if use_pdh_levels
                line.set_xy1(pdh_line, pdhbn, pdh)
                line.set_xy2(pdh_line, time+1, pdh)
            if use_pdl_levels
                line.set_xy1(pdl_line, pdlbn, pdl)
                line.set_xy2(pdl_line, time+1, pdl)
            if use_pdc_levels
                line.set_xy1(pdc_line, pdcbn, pdc)
                line.set_xy2(pdc_line, time+1, pdc)
            if use_pdm_levels
                line.set_xy1(pdm_line, pdcbn, pdm)
                line.set_xy2(pdm_line, time+1, pdm)

    if pw_can_display
        if new_week
            if use_pwh_levels
                line.set_xy1(pwh_line, pwhbn, pwh)
                line.set_xy2(pwh_line, time+1, pwh)
            if use_pwl_levels
                line.set_xy1(pwl_line, pwlbn, pwl)
                line.set_xy2(pwl_line, time+1, pwl)
            if use_pwc_levels
                line.set_xy1(pwc_line, pwcbn, pwc)
                line.set_xy2(pwc_line, time+1, pwc)
            if use_pwm_levels
                line.set_xy1(pwm_line, pwcbn, pwm)
                line.set_xy2(pwm_line, time+1, pwm)

    if sess_can_display
        if use_sessh_levels
            line.set_xy1(l_sess_high, sess_bn, sess_high)
            line.set_xy2(l_sess_high, time+1, sess_high)
        if use_sessl_levels
            line.set_xy1(l_sess_low, sess_bn, sess_low)
            line.set_xy2(l_sess_low, time+1, sess_low)
        if use_sessm_levels
            line.set_xy1(l_sess_mid, sess_bn, sess_mid)
            line.set_xy2(l_sess_mid, time+1, sess_mid)

Overview

Each level can be shown or hidden, and its color, line style, and width can be set independently. Daily levels default to gray and weekly levels to yellow; prior close is off by default and the midpoint uses a dashed style. It draws these lines on the price chart and does not generate trade signals.

Details

Published by

g-moe on GitHub

Code credit

goodgains, 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
PDHbooltrueuse_pdh_levels
css_pdhcolorcolor.new(color.gray,35)css_pdh
style_pdhstringSolidstyle_pdh
width_pdhint1width_pdh
PDLbooltrueuse_pdl_levels
css_pdlcolorcolor.new(color.gray,35)css_pdl
style_pdlstringSolidstyle_pdl
width_pdlint1width_pdl
PDCboolfalseuse_pdc_levels
css_pdccolorcolor.new(color.gray,35)css_pdc
style_pdcstringSolidstyle_pdc
width_pdcint1width_pdc
Show all 40 settings
SettingTypeDefaultVariable
PDMbooltrueuse_pdm_levels
css_pdmcolorcolor.new(color.gray,35)css_pdm
style_pdmstringDashedstyle_pdm
width_pdmint1width_pdm
PWHbooltrueuse_pwh_levels
css_pwhcolorcolor.new(color.yellow,35)css_pwh
style_pwhstringSolidstyle_pwh
width_pwhint1width_pwh
PWLbooltrueuse_pwl_levels
css_pwlcolorcolor.new(color.yellow,35)css_pwl
style_pwlstringSolidstyle_pwl
width_pwlint1width_pwl
PWCboolfalseuse_pwc_levels
css_pwccolorcolor.new(color.yellow,35)css_pwc
style_pwcstringSolidstyle_pwc
width_pwcint1width_pwc
PWMbooltrueuse_pwm_levels
css_pwmcolorcolor.new(color.yellow,35)css_pwm
style_pwmstringDashedstyle_pwm
width_pwmint1width_pwm
Session Timesession0930-1600session_time
Session Hboolfalseuse_sessh_levels
css_sesshcolorcolor.new(color.blue,35)css_sessh
style_sesshstringSolidstyle_sessh
width_sesshint1width_sessh
Session Lboolfalseuse_sessl_levels
css_sesslcolorcolor.new(color.blue,35)css_sessl
style_sesslstringSolidstyle_sessl
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

947 stars

Moving Average Channel plots separate simple moving averages for upper and lower bands on the price chart. It fills the space between bands with semi-transparent color and colors bars green above the upper band, red below the lower band, or gray in between. Us

Indicator v4 Moving averagesSupport & resistance
Updated 12 days ago · GPL-3.0 GitHub repository of Moving Average Channel

ICT Equal Highs and Lows

by ArunKBhaskar
575 stars

This overlay indicator finds pivot highs and lows on the price chart and compares the last two highs and the last two lows. When the percentage difference between a pair is below the Equal HL threshold, it treats them as equal levels and draws a box. Left and

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows
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]

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 2 months ago · MIT GitHub repository of Volume Profile and Indicator by DGT

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

Function - Linear Regression

by ricardosantos79
261 stars

This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up

Indicator v5 TrendSupport & resistance
Updated 4 years ago · None stated GitHub repository of Function - Linear Regression

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