Indicator · Pine Script v5 · On the chart

High Low - Candle Origin

by Sagar4575· code credited to Sagar

High Low - Candle Origin is an overlay indicator that draws the current and previous period high and low as lines starting at the exact candle that formed each extreme.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code277
Settings34inputs
LicenceMIT
Last update3 months ago10 Jul 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

277 lines of Pine Script v5 from daily_high_low_candle_origin.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

daily_high_low_candle_origin.pine
// © 2026 Sagar
//
// This indicator is provided free of charge for public use.
//
// You are allowed to use, modify, and share this indicator,
// provided that proper credit is given to the original author.
//
// Claiming authorship, removing this notice, or representing
// this indicator as your own work is strictly prohibited.

//@version=5
indicator("High Low – Candle Origin (Institutional)", overlay=true)

// ─────────────────────────────
// PERIOD MODE
// ─────────────────────────────
// Choose which period the "Current" / "Previous" High-Low lines track.
// The chart's own timeframe must be SMALLER than the chosen period
// (e.g. Period Mode = "1 Hour" needs a chart timeframe below 1H).
periodMode = input.string("Daily", "Period Mode", options=["1 Hour", "4 Hour", "Daily", "Weekly"], group="Period Settings")

// Resolution string fed to timeframe.change() / timeframe.in_seconds()
periodTF = switch periodMode
    "1 Hour" => "60"
    "4 Hour" => "240"
    "Weekly" => "W"
    => "D"

// Short label used to auto-build default label text (e.g. "Current Daily High")
modeLabel = switch periodMode
    "1 Hour" => "Hourly"
    "4 Hour" => "4H"
    "Weekly" => "Weekly"
    => "Daily"

// ─────────────────────────────
// SAFETY (MANDATORY)
// ─────────────────────────────
if timeframe.in_seconds() >= timeframe.in_seconds(periodTF)
    runtime.error("Chart timeframe must be smaller than the selected Period Mode timeframe.")

// ─────────────────────────────
// GENERAL SETTINGS
// ─────────────────────────────
showCurrentHigh = input.bool(true,  "Show Current High")
showCurrentLow  = input.bool(true,  "Show Current Low")
showPrevHigh    = input.bool(true,  "Show Previous High")
showPrevLow     = input.bool(true,  "Show Previous Low")
rightExtendBars = input.int(50,     "Right Extension (bars)", minval=10)

// ─────────────────────────────
// CURRENT HIGH – GROUP
// ─────────────────────────────
currHighColor      = input.color(color.gray,   "Line Color",         group="Current High")
currHighStyle      = input.string("dashed",    "Line Style",         group="Current High", options=["solid","dashed","dotted"])
currHighWidth      = input.int(1,              "Line Width",         group="Current High", minval=1, maxval=4)
showCurrHighLabel  = input.bool(true,          "Show Label",         group="Current High")
currHighLabelText  = input.string("",          "Label Text (blank = auto)", group="Current High")
currHighLabelColor = input.color(color.gray,   "Label Color",        group="Current High")
currHighLabelSize  = input.string("small",     "Label Size",         group="Current High", options=["tiny","small","normal","large"])

// ─────────────────────────────
// CURRENT LOW – GROUP
// ─────────────────────────────
currLowColor       = input.color(color.gray,   "Line Color",         group="Current Low")
currLowStyle       = input.string("dashed",    "Line Style",         group="Current Low",  options=["solid","dashed","dotted"])
currLowWidth       = input.int(1,              "Line Width",         group="Current Low",  minval=1, maxval=4)
showCurrLowLabel   = input.bool(true,          "Show Label",         group="Current Low")
currLowLabelText   = input.string("",          "Label Text (blank = auto)", group="Current Low")
currLowLabelColor  = input.color(color.gray,   "Label Color",        group="Current Low")
currLowLabelSize   = input.string("small",     "Label Size",         group="Current Low",  options=["tiny","small","normal","large"])

// ─────────────────────────────
// PREVIOUS HIGH – GROUP
// ─────────────────────────────
prevHighColor      = input.color(color.new(color.gray, 60), "Line Color",  group="Previous High")
prevHighStyle      = input.string("dashed",    "Line Style",         group="Previous High", options=["solid","dashed","dotted"])
prevHighWidth      = input.int(1,              "Line Width",         group="Previous High", minval=1, maxval=4)
showPrevHighLabel  = input.bool(true,          "Show Label",         group="Previous High")
prevHighLabelText  = input.string("",          "Label Text (blank = auto)", group="Previous High")
prevHighLabelColor = input.color(color.new(color.gray, 60), "Label Color", group="Previous High")
prevHighLabelSize  = input.string("small",     "Label Size",         group="Previous High", options=["tiny","small","normal","large"])

// ─────────────────────────────
// PREVIOUS LOW – GROUP
// ─────────────────────────────
prevLowColor       = input.color(color.new(color.gray, 60), "Line Color",  group="Previous Low")
prevLowStyle       = input.string("dashed",    "Line Style",         group="Previous Low",  options=["solid","dashed","dotted"])
prevLowWidth       = input.int(1,              "Line Width",         group="Previous Low",  minval=1, maxval=4)
showPrevLowLabel   = input.bool(true,          "Show Label",         group="Previous Low")
prevLowLabelText   = input.string("",          "Label Text (blank = auto)", group="Previous Low")
prevLowLabelColor  = input.color(color.new(color.gray, 60), "Label Color", group="Previous Low")
prevLowLabelSize   = input.string("small",     "Label Size",         group="Previous Low",  options=["tiny","small","normal","large"])

// ─────────────────────────────
// HELPERS
// ─────────────────────────────
f_style(s) =>
    s == "solid"  ? line.style_solid  :
     s == "dotted" ? line.style_dotted :
     line.style_dashed

f_size(s) =>
    s == "tiny"   ? size.tiny   :
     s == "normal" ? size.normal :
     s == "large"  ? size.large  :
     size.small

// Auto label text: use user text if provided, otherwise build from Period Mode
f_label(userText, prefix, suffix) =>
    userText == "" ? prefix + " " + modeLabel + " " + suffix : userText

finalCurrHighText = f_label(currHighLabelText, "Current", "High")
finalCurrLowText  = f_label(currLowLabelText,  "Current", "Low")
finalPrevHighText = f_label(prevHighLabelText, "Previous", "High")
finalPrevLowText  = f_label(prevLowLabelText,  "Previous", "Low")

// ─────────────────────────────
// PERIOD CHANGE (based on selected Period Mode)
// ─────────────────────────────
isNewPeriod = timeframe.change(periodTF)
rightX      = bar_index + rightExtendBars

// ─────────────────────────────
// CURRENT PERIOD HIGH / LOW
// ─────────────────────────────
var float currHigh    = na
var float currLow     = na
var int   currHighBar = na
var int   currLowBar  = na

if isNewPeriod
    currHigh    := high
    currLow     := low
    currHighBar := bar_index
    currLowBar  := bar_index
else
    if high > currHigh
        currHigh    := high
        currHighBar := bar_index
    if low < currLow
        currLow    := low
        currLowBar := bar_index

// ─────────────────────────────
// PREVIOUS PERIOD VALUES (LOCKED)
// ─────────────────────────────
var float prevHigh    = na
var float prevLow     = na
var int   prevHighBar = na
var int   prevLowBar  = na

if isNewPeriod and not na(currHigh[1])
    prevHigh    := currHigh[1]
    prevLow     := currLow[1]
    prevHighBar := currHighBar[1]
    prevLowBar  := currLowBar[1]

// ─────────────────────────────
// CURRENT PERIOD LINES (UPDATING)
// ─────────────────────────────
var line currHighLine = na
var line currLowLine  = na

if showCurrentHigh and not na(currHigh)
    if na(currHighLine)
        currHighLine := line.new(currHighBar, currHigh, rightX, currHigh, color=currHighColor, style=f_style(currHighStyle), width=currHighWidth)
    else
        line.set_xy1(currHighLine, currHighBar, currHigh)
        line.set_xy2(currHighLine, rightX, currHigh)
        line.set_color(currHighLine, currHighColor)
        line.set_style(currHighLine, f_style(currHighStyle))
        line.set_width(currHighLine, currHighWidth)

if showCurrentLow and not na(currLow)
    if na(currLowLine)
        currLowLine := line.new(currLowBar, currLow, rightX, currLow, color=currLowColor, style=f_style(currLowStyle), width=currLowWidth)
    else
        line.set_xy1(currLowLine, currLowBar, currLow)
        line.set_xy2(currLowLine, rightX, currLow)
        line.set_color(currLowLine, currLowColor)
        line.set_style(currLowLine, f_style(currLowStyle))
        line.set_width(currLowLine, currLowWidth)

// ─────────────────────────────
// PREVIOUS PERIOD LINES (FIXED PRICE)
// ─────────────────────────────
var line prevHighLine = na
var line prevLowLine  = na

if isNewPeriod and not na(prevHigh)
    line.delete(prevHighLine)
    line.delete(prevLowLine)

    if showPrevHigh
        prevHighLine := line.new(prevHighBar, prevHigh, rightX, prevHigh, color=prevHighColor, style=f_style(prevHighStyle), width=prevHighWidth)

    if showPrevLow
        prevLowLine := line.new(prevLowBar, prevLow, rightX, prevLow, color=prevLowColor, style=f_style(prevLowStyle), width=prevLowWidth)

if not isNewPeriod
    if showPrevHigh and not na(prevHighLine)
        line.set_xy2(prevHighLine, rightX, prevHigh)
        line.set_color(prevHighLine, prevHighColor)
        line.set_style(prevHighLine, f_style(prevHighStyle))
        line.set_width(prevHighLine, prevHighWidth)
    if showPrevLow and not na(prevLowLine)
        line.set_xy2(prevLowLine, rightX, prevLow)
        line.set_color(prevLowLine, prevLowColor)
        line.set_style(prevLowLine, f_style(prevLowStyle))
        line.set_width(prevLowLine, prevLowWidth)

// ─────────────────────────────
// LABELS (FULLY CUSTOMIZABLE)
// ─────────────────────────────
var label currHighLabel = na
var label currLowLabel  = na
var label prevHighLabel = na
var label prevLowLabel  = na

// Current High Label
if showCurrentHigh and not na(currHigh)
    if showCurrHighLabel
        if na(currHighLabel)
            currHighLabel := label.new(rightX, currHigh, finalCurrHighText, style=label.style_none, textcolor=currHighLabelColor, size=f_size(currHighLabelSize))
        else
            label.set_xy(currHighLabel, rightX, currHigh)
            label.set_text(currHighLabel, finalCurrHighText)
            label.set_textcolor(currHighLabel, currHighLabelColor)
            label.set_size(currHighLabel, f_size(currHighLabelSize))
    else
        label.delete(currHighLabel)
        currHighLabel := na

// Current Low Label
if showCurrentLow and not na(currLow)
    if showCurrLowLabel
        if na(currLowLabel)
            currLowLabel := label.new(rightX, currLow, finalCurrLowText, style=label.style_none, textcolor=currLowLabelColor, size=f_size(currLowLabelSize))
        else
            label.set_xy(currLowLabel, rightX, currLow)
            label.set_text(currLowLabel, finalCurrLowText)
            label.set_textcolor(currLowLabel, currLowLabelColor)
            label.set_size(currLowLabel, f_size(currLowLabelSize))
    else
        label.delete(currLowLabel)
        currLowLabel := na

// Previous High Label
if showPrevHigh and not na(prevHigh)
    if showPrevHighLabel
        if isNewPeriod
            label.delete(prevHighLabel)
            prevHighLabel := label.new(rightX, prevHigh, finalPrevHighText, style=label.style_none, textcolor=prevHighLabelColor, size=f_size(prevHighLabelSize))
        else
            label.set_xy(prevHighLabel, rightX, prevHigh)
            label.set_text(prevHighLabel, finalPrevHighText)
            label.set_textcolor(prevHighLabel, prevHighLabelColor)
            label.set_size(prevHighLabel, f_size(prevHighLabelSize))
    else
        label.delete(prevHighLabel)
        prevHighLabel := na

// Previous Low Label
if showPrevLow and not na(prevLow)
    if showPrevLowLabel
        if isNewPeriod
            label.delete(prevLowLabel)
            prevLowLabel := label.new(rightX, prevLow, finalPrevLowText, style=label.style_none, textcolor=prevLowLabelColor, size=f_size(prevLowLabelSize))
        else
            label.set_xy(prevLowLabel, rightX, prevLow)
            label.set_text(prevLowLabel, finalPrevLowText)
            label.set_textcolor(prevLowLabel, prevLowLabelColor)
            label.set_size(prevLowLabel, f_size(prevLowLabelSize))
    else
        label.delete(prevLowLabel)
        prevLowLabel := na

Overview

The period can be 1 hour, 4 hour, daily or weekly, and the chart timeframe must be smaller than the chosen period or the script stops with an error. Lines are extended to the right by a set number of bars, with separate colour, style, width and label settings for each of the four levels. Current levels update as price moves.

Details

Published by

Sagar4575 on GitHub

Code credit

Sagar, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Support & resistance, Sessions & time

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.

Settings

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

SettingTypeDefaultVariable
Period ModestringDailyperiodMode
Show Current HighbooltrueshowCurrentHigh
Show Current LowbooltrueshowCurrentLow
Show Previous HighbooltrueshowPrevHigh
Show Previous LowbooltrueshowPrevLow
Right Extension (bars)int50rightExtendBars
Line Colorcolorcolor.graycurrHighColor
Line StylestringdashedcurrHighStyle
Line Widthint1currHighWidth
Show LabelbooltrueshowCurrHighLabel
Label Text (blank = auto)stringcurrHighLabelText
Label Colorcolorcolor.graycurrHighLabelColor
Show all 34 settings
SettingTypeDefaultVariable
Label SizestringsmallcurrHighLabelSize
Line Colorcolorcolor.graycurrLowColor
Line StylestringdashedcurrLowStyle
Line Widthint1currLowWidth
Show LabelbooltrueshowCurrLowLabel
Label Text (blank = auto)stringcurrLowLabelText
Label Colorcolorcolor.graycurrLowLabelColor
Label SizestringsmallcurrLowLabelSize
Line Colorcolorcolor.new(color.gray, 60)prevHighColor
Line StylestringdashedprevHighStyle
Line Widthint1prevHighWidth
Show LabelbooltrueshowPrevHighLabel
Label Text (blank = auto)stringprevHighLabelText
Label Colorcolorcolor.new(color.gray, 60)prevHighLabelColor
Label SizestringsmallprevHighLabelSize
Line Colorcolorcolor.new(color.gray, 60)prevLowColor
Line StylestringdashedprevLowStyle
Line Widthint1prevLowWidth
Show LabelbooltrueshowPrevLowLabel
Label Text (blank = auto)stringprevLowLabelText
Label Colorcolorcolor.new(color.gray, 60)prevLowLabelColor
Label SizestringsmallprevLowLabelSize
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
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 昨日高低點標示

Golden Bullet Strategy

by TradersPost
218 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

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 indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers