Indicator · Pine Script v5 · On the chart

Previous Day High and Low with Separators

by ivansoft· code credited to Algoryze

An indicator on the price chart that draws daily and weekly separator lines and marks the previous day's high and low.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code168
Settings12inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago1 Mar 2025

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

168 lines of Pine Script v5 from examples/202405/dayhighlow.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

dayhighlow.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Algoryze

//@version=5
indicator("Previous Day High and Low + Separators Daily/Weekly", overlay=true, max_lines_count = 500, max_boxes_count = 500, max_labels_count = 500)

// Function to check if a new day has started
_isNewDay(utcOffsetInMs) =>
    dow = dayofweek(time + utcOffsetInMs)
    dayChanged = dow != dow[1]
    dayChanged

// Function to check if a new week has started
_isNewWeek(utcOffsetInMs) =>
    woy = weekofyear(time + utcOffsetInMs)
    weekChanged = woy != woy[1]
    weekChanged

_bottomMarkText(barTime, utcOffsetInMs) =>
    var monthShortNames = array.from('', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')
    var weekdayShortNames = array.from('', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat')
    weekdayShort = array.get(weekdayShortNames, dayofweek(barTime + utcOffsetInMs))
    out = ''
         + weekdayShort
         + ' ' + str.tostring(dayofmonth(barTime + utcOffsetInMs))
         + ' ' + array.get(monthShortNames, month(barTime + utcOffsetInMs))
         + " '" + str.substring(str.tostring(year(barTime + utcOffsetInMs), '#'), 2)
         + ' ' + str.format_time(barTime, 'HH:mm')

// Function to get the highest and lowest prices of the previous day
_getPreviousDayHighLow(utcOffsetInMs) =>
    dow = dayofweek(time + utcOffsetInMs)
    var prevDayHigh = high
    var prevDayHighTime = time

    var prevDayLow = low
    var prevDayLowTime = time

    var dayHigh = high
    var dayHighTime = time

    var dayLow = low
    var dayLowTime = time

    if (dow != dow[1])
        dayHigh := high
        dayHighTime := time

        dayLow := low
        dayLowTime := time

        prevDayHigh := dayHigh[1]
        prevDayHighTime := dayHighTime[1]

        prevDayLow := dayLow[1]
        prevDayLowTime := dayLowTime[1]
    else
        if dayHigh < high
            dayHigh := high
            dayHighTime := time
        
        if dayLow > low
            dayLow := low
            dayLowTime := time

    [prevDayHigh, prevDayHighTime, prevDayLow, prevDayLowTime]

// Input for custom UTC offset
utcOffset = input.int(0, title="UTC Offset (in hours)", minval=-12, maxval=12)
utcOffsetInMs = utcOffset * 60 * 60 * 1000

// Daily separator inputs
var dailyGroup = 'Daily Separator'
dailySeparatorColor = input.color(color.orange, title='Color', group=dailyGroup)
dailySeparatorStyleInput = input.string('Solid', title='Style', options=['Solid', 'Dotted'], display=display.none, group=dailyGroup)
dailySeparatorWidthInput = input.int(1, title='Width', minval=1, display=display.none, group=dailyGroup)
dailySeparatorLabelTextColor = input.color(color.white, title='Label Text Color', group=dailyGroup)
dailySeparatorStyle = dailySeparatorStyleInput == 'Solid' ? line.style_solid : line.style_dotted

// Weekly separator inputs
var weeklyGroup = 'Weekly Separator'
weeklySeparatorColorInput = input.color(color.gray, title='Color', group=weeklyGroup)
weeklySeparatorStyleInput = input.string('Solid', title='Style', options=['Solid', 'Dotted'], display=display.none, group=weeklyGroup)
weeklySeparatorWidthInput = input.int(3, title='Width', minval=1, display=display.none, group=weeklyGroup)
weeklySeparatorStyle = weeklySeparatorStyleInput == 'Solid' ? line.style_solid : line.style_dotted

var prevDayHLGroup = 'Previous Day H&L'
prevDayHLColorInput = input.color(color.gray, title='Color', group=prevDayHLGroup)
prevDayHLTextColorInput = input.color(color.orange, title='Text Color', group=prevDayHLGroup)
prevDayHLStyleInput = input.string('Dotted', title='Style', options=['Solid', 'Dotted'], display=display.none, group=prevDayHLGroup)
prevDayHLWidthInput = input.int(3, title='Width', minval=1, display=display.none, group=prevDayHLGroup)
prevDayHLStyle = prevDayHLStyleInput == 'Solid' ? line.style_solid : line.style_dotted

var transpColor = color.new(color.white, 100)
var weekdayFullNames = array.from('', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')

var box weekdayTopLabelBox = na
var box[] weekdayTopLabels = array.new_box(0)
var label[] weekdayBottomLabels = array.new_label(0)

var string periodD = "D"
var string periodW = "W"
var string periodM = "M"
var string periodY = "12M"
var int mult = timeframe.multiplier
var bool isHourly = timeframe.isminutes and mult % 60 == 0
var bool isMinuteLessThan30 = timeframe.isminutes and mult < 30
var string tfAuto =
     timeframe.isseconds or isMinuteLessThan30 ? periodD :
     isHourly ? periodW :
     timeframe.isdaily ? periodM :
     timeframe.isweekly or timeframe.ismonthly ? periodY :
     periodW

pivotLevels = ta.pivot_point_levels('Traditional', timeframe.change(tfAuto))
pivot = array.get(pivotLevels, 0)
weekdayTopLabelBoxTop = array.get(pivotLevels, 5)
weekdayTopLabelBoxBottom = array.get(pivotLevels, 4)

weekdayBottomLabelLevel = array.get(pivotLevels, 6)

isNewPivot = pivot != pivot[1]
isNewDay = _isNewDay(utcOffsetInMs)
isNewWeek = _isNewWeek(utcOffsetInMs)

// Plot daily separator line
if isNewDay
    weekdayFull = array.get(weekdayFullNames, dayofweek(time + utcOffsetInMs))
    line.new(bar_index, low, bar_index, high, style=dailySeparatorStyle, width=dailySeparatorWidthInput, color=dailySeparatorColor, extend=extend.both)
    weekdayTopLabelBox := box.new(bar_index, weekdayTopLabelBoxTop, bar_index, weekdayTopLabelBoxBottom, xloc=xloc.bar_index, bgcolor=transpColor, border_color=transpColor, text=weekdayFull, text_color=dailySeparatorColor, text_size=size.small, text_halign = text.align_center, text_valign = text.align_top)
    array.push(weekdayTopLabels, weekdayTopLabelBox)
    array.push(weekdayBottomLabels, label.new(bar_index, weekdayBottomLabelLevel, text=_bottomMarkText(time, utcOffsetInMs), color=dailySeparatorColor, textcolor=dailySeparatorLabelTextColor , style=label.style_label_up))
else
    box.set_right(weekdayTopLabelBox, bar_index)

if isNewPivot and array.size(weekdayTopLabels) > 0
    for i = 0 to array.size(weekdayTopLabels) - 1
        box.set_top(array.get(weekdayTopLabels, i), weekdayTopLabelBoxTop)
        box.set_bottom(array.get(weekdayTopLabels, i), weekdayTopLabelBoxBottom)
        label.set_y(array.get(weekdayBottomLabels, i), weekdayBottomLabelLevel)

// Plot weekly separator line
if isNewWeek
    line.new(bar_index, low, bar_index, high, color=weeklySeparatorColorInput, style=weeklySeparatorStyle, width=weeklySeparatorWidthInput, extend=extend.both)

// Plot highest and lowest prices of the previous day
[prevDayHigh, prevDayHighTime, prevDayLow, prevDayLowTime] = _getPreviousDayHighLow(utcOffsetInMs)
var line prevDayHighLine = line.new(time, prevDayHigh, time, prevDayHigh, xloc=xloc.bar_time, color=prevDayHLColorInput, width=1)
var label prevDayHighLabel = label.new(time, prevDayHigh, xloc=xloc.bar_time, text='HOD', color=transpColor, textcolor=prevDayHLTextColorInput, style=label.style_label_down)//, style=label.style_label_lower_left)

var line prevDayLowLine = line.new(time, prevDayLow, time, prevDayLow, xloc=xloc.bar_time, color=prevDayHLColorInput, width=1)
var label prevDayLowLabel = label.new(time, prevDayLow, xloc=xloc.bar_time, text='LOD', color=transpColor, textcolor=prevDayHLTextColorInput, style=label.style_label_up)//, style=label.style_label_upper_left)

if isNewDay
    line.set_xy1(prevDayHighLine, prevDayHighTime, prevDayHigh)
    line.set_xy2(prevDayHighLine, prevDayHighTime, prevDayHigh)
    label.set_xy(prevDayHighLabel, prevDayHighTime, prevDayHigh)

    line.set_xy1(prevDayLowLine, prevDayLowTime, prevDayLow)
    line.set_xy2(prevDayLowLine, prevDayLowTime, prevDayLow)
    label.set_xy(prevDayLowLabel, prevDayLowTime, prevDayLow)
else
    t = time//chart.right_visible_bar_time
    line.set_x2(prevDayHighLine, t)
    label.set_x(prevDayHighLabel, t)

    line.set_x2(prevDayLowLine, t)
    label.set_x(prevDayLowLabel, t)

Overview

Daily separators carry a label with the weekday, date and time, weekly separators are drawn separately, and the previous day levels appear as dotted lines with text. A UTC offset in hours shifts where the day and week boundaries fall. Colour, line style and width are adjustable for each element.

Details

Published by

ivansoft on GitHub

Code credit

Algoryze, as written in the script's header

Draws

On the price chart

Markets

Any symbol

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.

Topics

pinescripttradingvew

Settings

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

SettingTypeDefaultVariable
UTC Offset (in hours)int0utcOffset
Colorcolorcolor.orangedailySeparatorColor
StylestringSoliddailySeparatorStyleInput
Widthint1dailySeparatorWidthInput
Label Text Colorcolorcolor.whitedailySeparatorLabelTextColor
Colorcolorcolor.grayweeklySeparatorColorInput
StylestringSolidweeklySeparatorStyleInput
Widthint3weeklySeparatorWidthInput
Colorcolorcolor.grayprevDayHLColorInput
Text Colorcolorcolor.orangeprevDayHLTextColorInput
StylestringDottedprevDayHLStyleInput
Widthint3prevDayHLWidthInput
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

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
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 昨日高低點標示

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 2 months 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 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