Indicator · Pine Script v5 · On the chart

Daily Weekly Monthly Highs & Lows

by sbtnc

Draws dashed horizontal lines at the highs and lows of previous days, weeks and months on the price chart.

View on GitHub

Repaints

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code137
Settings12inputs
LicenceMPL-2.0
Last update9 months ago28 Jan 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

137 lines of Pine Script v5 from Day Week Month Highs & Lows.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

Day Week Month Highs & Lows.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sbtnc
// Created: 2020-01-12
// Last modified: 2022-02-09
// version 3.0

// @version=5
indicator("Daily Weekly Monthly Highs & Lows", "DWM HL", true, max_lines_count=500)

//--------------------------------------------------------------------
//                             Constants
//--------------------------------------------------------------------

var DAILY_LINE_STYLE    = line.style_dashed
var DAILY_LINE_WITDH    = 1
var WEEKLY_LINE_STYLE   = line.style_dashed
var WEEKLY_LINE_WIDTH   = 1
var MONTHLY_LINE_STYLE  = line.style_dashed
var MONTHLY_LINE_WIDTH  = 1

//--------------------------------------------------------------------
//                               Inputs
//--------------------------------------------------------------------

g_indicator             = "Highs & Lows"
g_style                 = "Style"
t_heads                 = "Extends previous highs and lows in the future."
t_gradient              = "Show a color gradient that highlights the recency of highs and lows."

var i_isDailyEnabled    = input     (true,          "Daily",                        inline="Daily",     group=g_indicator)
var i_dailyColor        = input     (color.green,   "",                             inline="Daily",     group=g_indicator)
var i_dailyLookback     = input.int (2,             "", 1,                          inline="Daily",     group=g_indicator)
var i_isWeeklyEnabled   = input     (true,          "Weekly",                       inline="Weekly",    group=g_indicator)
var i_weeklyColor       = input     (color.orange,  "",                             inline="Weekly",    group=g_indicator)
var i_weeklyLookback    = input.int (1,             "", 1,                          inline="Weekly",    group=g_indicator)
var i_isMonthlyEnabled  = input     (true,          "Monthly",                      inline="Monthly",   group=g_indicator)
var i_monthlyColor      = input     (color.red,     "",                             inline="Monthly",   group=g_indicator)
var i_monthlyLookback   = input.int (1,             "", 1,                          inline="Monthly",   group=g_indicator)
var i_areHeadsEnabled   = input     (false,         "Show Projections", t_heads,    inline="Head",      group=g_style)
var i_rightOffset       = input.int (20,            "", 1,                          inline="Head",      group=g_style)
var i_hasGradient       = input     (true,          "Show Gradient",    t_gradient,                     group=g_style)

//--------------------------------------------------------------------
//                        Variables declarations
//--------------------------------------------------------------------

var a_lastHighs                         = array.new_float(3)
var a_lastLows                          = array.new_float(3)
var canShowDaily                        = i_isDailyEnabled and timeframe.isintraday
var canShowWeekly                       = i_isWeeklyEnabled and (timeframe.isintraday or timeframe.isdaily)
var canShowMonthly                      = i_isMonthlyEnabled and not timeframe.ismonthly

[dailyTime, dailyHigh, dailyLow, isLastDaily]           = request.security(syminfo.tickerid, 'D', [time, high, low, barstate.islast], lookahead=barmerge.lookahead_on)
[weeklyTime, weeklyHigh, weeklyLow, isLastWeekly]       = request.security(syminfo.tickerid, 'W', [time, high, low, barstate.islast], lookahead=barmerge.lookahead_on)
[monthlyTime, monthlyHigh, monthlyLow, isLastMonthly]   = request.security(syminfo.tickerid, 'M', [time, high, low, barstate.islast], lookahead=barmerge.lookahead_on)

hasDailyTimeChanged                     = dailyTime != dailyTime[1]
hasWeekklyTimeChanged                   = weeklyTime != weeklyTime[1]
hasMonthlyTimeChanged                   = monthlyTime != monthlyTime[1]

//--------------------------------------------------------------------
//                              Functions 
//--------------------------------------------------------------------

f_getRightBarIndex() => bar_index + i_rightOffset

f_draw(bool _isNew, float _h, float _l, int _lookback, color _color, string _style, int _width) =>
    var line _high  = na
    var line _low   = na
    var _highs      = array.new_line()
    var _lows       = array.new_line()
    _end            = i_areHeadsEnabled ? f_getRightBarIndex() : bar_index
    
    if _isNew
        line.set_x2(_high, _end)
        line.set_x2(_low, _end)

        if i_hasGradient
            _size = array.size(_highs)
            if _size > 1
                for i = 0 to _size - 1
                    _c = color.from_gradient(i, 0, _size - 1, color.new(_color, 100), color.new(_color, 0))
                    line.set_color(array.get(_highs, i), _c)
                    line.set_color(array.get(_lows, i), _c)

        _high := line.new(bar_index, _h, bar_index, _h, color=_color, style=_style, width=_width)
        _low := line.new(bar_index, _l, bar_index, _l, color=_color, style=_style, width=_width)
        array.push(_highs, _high)
        array.push(_lows, _low)

        if array.size(_highs) > _lookback + 1
            line.delete(array.shift(_highs))
            line.delete(array.shift(_lows))

    if i_areHeadsEnabled and barstate.islast and array.size(_highs) > 1
        // Avoid updating the last/current high and low 
        for i = 0 to array.size(_highs) - 2
            line.set_x2(array.get(_highs, i), f_getRightBarIndex())
            line.set_x2(array.get(_lows, i), f_getRightBarIndex())

//--------------------------------------------------------------------
//                                Logic
//--------------------------------------------------------------------

if canShowDaily and hasDailyTimeChanged and not isLastDaily
    array.set(a_lastHighs, 0, dailyHigh)
    array.set(a_lastLows, 0, dailyLow)

if canShowWeekly and hasWeekklyTimeChanged and not isLastWeekly
    array.set(a_lastHighs, 1, weeklyHigh)
    array.set(a_lastLows, 1, weeklyLow)

if canShowMonthly and hasMonthlyTimeChanged and not isLastMonthly
    array.set(a_lastHighs, 2, monthlyHigh)
    array.set(a_lastLows, 2, monthlyLow)

//--------------------------------------------------------------------
//                          Plotting & styling
//--------------------------------------------------------------------

if canShowMonthly
    f_draw(hasMonthlyTimeChanged, monthlyHigh, monthlyLow, i_monthlyLookback, i_monthlyColor, MONTHLY_LINE_STYLE, MONTHLY_LINE_WIDTH)

if canShowWeekly
    f_draw(hasWeekklyTimeChanged, weeklyHigh, weeklyLow, i_weeklyLookback, i_weeklyColor, WEEKLY_LINE_STYLE, WEEKLY_LINE_WIDTH)

if canShowDaily
    f_draw(hasDailyTimeChanged, dailyHigh, dailyLow, i_dailyLookback, i_dailyColor, DAILY_LINE_STYLE, DAILY_LINE_WITDH)

// Plot invisible highs and lows for displaying their last values in `status line`, `scale`, `data window` as well for providing defaults alert conditions

plot(array.get(a_lastHighs, 0), "DH",   color.new(i_dailyColor, 100),   editable=false)
plot(array.get(a_lastLows, 0),  "DL",   color.new(i_dailyColor, 100),   editable=false)
plot(array.get(a_lastHighs, 1), "WH",   color.new(i_weeklyColor, 100),  editable=false)
plot(array.get(a_lastLows, 1),  "WL",   color.new(i_weeklyColor, 100),  editable=false)
plot(array.get(a_lastHighs, 2), "MH",   color.new(i_monthlyColor, 100), editable=false)
plot(array.get(a_lastLows, 2),  "ML",   color.new(i_monthlyColor, 100), editable=false)

Overview

Each period has its own colour and a lookback count for how many past periods to show. An optional gradient fades older levels, and projections extend previous levels to the right by a set offset. It requests higher-timeframe data with lookahead, and the daily and weekly levels need an intraday or daily chart.

Details

Published by

sbtnc on GitHub

Draws

On the price chart

Markets

Any symbol

Timeframes

M15-H1

Risk Notes

  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Topics

pine-scriptpinescriptpinescript-indicators

Settings

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

SettingTypeDefaultVariable
Dailybooltruei_isDailyEnabled
i_dailyColorcolorcolor.greeni_dailyColor
i_dailyLookbackint2i_dailyLookback
Weeklybooltruei_isWeeklyEnabled
i_weeklyColorcolorcolor.orangei_weeklyColor
i_weeklyLookbackint1i_weeklyLookback
Monthlybooltruei_isMonthlyEnabled
i_monthlyColorcolorcolor.redi_monthlyColor
i_monthlyLookbackint1i_monthlyLookback
Show Projectionsboolfalsei_areHeadsEnabled
i_rightOffsetint20i_rightOffset
Show Gradientbooltruei_hasGradient
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