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.
1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Number of Days to Display
int
2
daysToShow
Line Colour
color
#B0B0B0
lineColorInput
Line Width
int
1
lineWidthInput
Line Style
string
Solid
lineStyleInput
Show Labels
bool
true
showLabels
Label Position
string
Middle
labelPosInput
Label Colour
color
#B0B0B0
labelColorInput
Label Size
string
Small
labelSizeInput
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.
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
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
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
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
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
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