Indicator · Pine Script v6 · On the chart

Previous Day Midpoint

by haydenfowler

The Previous Day Midpoint indicator calculates the midpoint of the prior day's high and low prices and projects horizontal line segments across each trading day directly on the main price chart.

View on GitHub

GitHub stars3on the repository
Pine versionv6current
Lines of code90
Settings8inputs
LicenceNone statedfile: MPL-2.0
Last update6 weeks ago7 Oct 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

90 lines of Pine Script v6 from prior-day-midpoint.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

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

//@version=6
indicator("Previous Day Midpoint", shorttitle="D-1 M", overlay=true, max_lines_count=500, max_labels_count=500)

// USER SETTINGS

daysToShow = input.int(2, title="Number of Days to Display", minval=1, maxval=100,
     tooltip="Number of midpoint segments to draw, including the segment covering today.")

lineColorInput = input.color(#B0B0B0, title="Line Colour", group="Line")
lineWidthInput = input.int(1, title="Line Width", minval=1, maxval=10, group="Line")
lineStyleInput = input.string("Solid", title="Line Style", options=["Solid", "Dotted", "Dashed"], group="Line")

showLabels      = input.bool(true, title="Show Labels", group="Label")
labelPosInput   = input.string("Middle", title="Label Position", options=["Left", "Middle", "Right"], group="Label")
labelColorInput = input.color(#B0B0B0, title="Label Colour", group="Label")
labelSizeInput  = input.string("Small", title="Label Size", options=["Tiny", "Small", "Normal", "Large", "Huge"], group="Label")

// STYLE MAPPING

lineStyle = switch lineStyleInput
    "Solid"  => line.style_solid
    "Dotted" => line.style_dotted
    "Dashed" => line.style_dashed
    => line.style_solid

labelSize = switch labelSizeInput
    "Tiny"   => size.tiny
    "Small"  => size.small
    "Normal" => size.normal
    "Large"  => size.large
    "Huge"   => size.huge
    => size.small

// TIMEFRAME GUARD — daily and below only

tfAllowed = timeframe.in_seconds() <= 86400

// DATA
// high[1]/low[1] are the previous *completed* daily bar; time/time_close are the
// current daily bar's open and close timestamps.

[prevHigh, prevLow, dayStart, dayEnd] = request.security(syminfo.tickerid, "D",
     [high[1], low[1], time, time_close], lookahead=barmerge.lookahead_on)

prevMid = (prevHigh + prevLow) / 2

newDay = na(dayStart[1]) or dayStart != dayStart[1]

// STORAGE — oldest at index 0, newest at the end

var line[]  midLines  = array.new<line>()
var label[] midLabels = array.new<label>()

// LABEL POSITION — a timestamp within the segment's day

labelX = switch labelPosInput
    "Left"   => dayStart
    "Middle" => dayStart + int((dayEnd - dayStart) / 2)
    "Right"  => dayEnd
    => dayStart + int((dayEnd - dayStart) / 2)

// DRAWING

if tfAllowed and newDay and not na(prevMid) and not na(dayStart) and not na(dayEnd)
    if array.size(midLines) >= daysToShow
        oldLine = array.shift(midLines)
        if not na(oldLine)
            line.delete(oldLine)
        if array.size(midLabels) > 0
            oldLabel = array.shift(midLabels)
            if not na(oldLabel)
                label.delete(oldLabel)

    array.push(midLines, line.new(x1=dayStart, y1=prevMid, x2=dayEnd, y2=prevMid,
         xloc=xloc.bar_time, color=lineColorInput, width=lineWidthInput, style=lineStyle))

    if showLabels
        array.push(midLabels, label.new(x=labelX, y=prevMid, xloc=xloc.bar_time, yloc=yloc.price,
             text="D-1 M", style=label.style_none, textcolor=labelColorInput, size=labelSize))

    // Labels are relative to today, so every stored label is renamed as it ages.
    // Newest is at the end of the array, so index i has age (labelCount - i).
    labelCount = array.size(midLabels)
    if labelCount > 0
        for i = 0 to labelCount - 1
            lb = array.get(midLabels, i)
            if not na(lb)
                label.set_text(lb, "D-" + str.tostring(labelCount - i) + " M")

Overview

Previous Day Midpoint renders a configurable number of recent daily midpoint lines alongside dynamic text labels that update relative to the current day. Users can adjust the segment appearance including line style, width, color, label position, and size. This indicator is limited to intraday and daily timeframes.

Details

Published by

haydenfowler on GitHub

Draws

On the price chart

Markets

Any symbol

Timeframes

M1-M5, 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
Number of Days to Displayint2daysToShow
Line Colourcolor#B0B0B0lineColorInput
Line Widthint1lineWidthInput
Line StylestringSolidlineStyleInput
Show LabelsbooltrueshowLabels
Label PositionstringMiddlelabelPosInput
Label Colourcolor#B0B0B0labelColorInput
Label SizestringSmalllabelSizeInput
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 5 weeks 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
368 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 3 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 8 days ago · MIT GitHub repository of Volume Profile and Indicator by DGT

Swing labels

by tradoor-terminal
320 stars

Calculates swing highs and swing lows on the price chart using pivot high and pivot low detection over a specified length. It places labels above pivot highs and below pivot lows to highlight key structural swing points. The indicator measures and displays the

Indicator v6 Support & resistanceTrend
Updated 3 days ago · AGPL-3.0 GitHub repository of Swing labels

BZ-tracker

by Allen1212
302 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 3 years ago · None stated GitHub repository of BZ-tracker

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