Indicator · Pine Script v5 · On the chart

My Period Separator All Timeframes

by dbruce1990· code credited to NotARobot_

This indicator draws custom higher-timeframe period separators and opening price horizontal lines directly on the price chart.

View on GitHub

Repaints

GitHub stars12on the repository
Pine versionv5runs as is
Lines of code74
Settings8inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago5 Sep 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

74 lines of Pine Script v5 from Reference_Indicators/Period_Separator/script.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

script.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
// © NotARobot_
// Borrowed heavily from © DedreduPlessis "Period Separator All Timeframes"
indicator("My Period Separator All Timeframes", overlay = true)

// Inputs
sepColorInput    = input.color(color.gray, "Separator Color")
sepStyleInput    = input.string("Dotted", "Separator Style", options = ["Solid", "Dashed", "Dotted"])
sepWidthInput    = input.int(1, "Separator Width", minval = 1)
sepTimeframeInput = input.timeframe("1M", "Separator Timeframe")

// HTF opening price line settings
showHTFOpenLine  = input.bool(true, "Show HTF Opening Price")
htfOpenPrice = request.security(syminfo.tickerid, sepTimeframeInput, open, lookahead = barmerge.lookahead_on)
htfOpenLineColor    = input.color(color.gray, "HTF Opening Price Color")
htfOpenLineWidth    = input.int(1, "HTF Opening Line Width", minval = 1)
htfOpenLineStyle    = input.string("Dashed", "HTF Line Style", options = ["Solid", "Dashed", "Dotted"])

// Create an array to store lines
var line[] htfOpenPriceLines = array.new_line()

// Function to get the line style
getLineStyle(string input) =>
    switch input
        "Solid"  => line.style_solid
        "Dashed" => line.style_dashed
        "Dotted" => line.style_dotted

// Function to draw the period separator
drawPeriodSeparator(color color, string style, int width, string timeframe) =>
    if timeframe.change(timeframe)
        line.new(
             x1     = bar_index,      // First bar index
             y1     = high + syminfo.mintick,  // Top point of the line
             x2     = bar_index,      // Second bar index (same for vertical line)
             y2     = low,            // Bottom point of the line
             extend = extend.both,    // Extends the line in both directions
             color  = color,          // Color of the line
             style  = getLineStyle(style), // Style of the line (dashed, dotted, etc.)
             width  = width           // Width of the line
         )

// Draw the period separator based on the selected timeframe and visible on the same or lower timeframes
if timeframe.in_seconds(timeframe.period) <= timeframe.in_seconds(sepTimeframeInput)
    drawPeriodSeparator(sepColorInput, sepStyleInput, sepWidthInput, sepTimeframeInput)

// Create a variable to store the bar index of the first candle in the period
var int firstBarInPeriod = na

// On the first bar of the period, store the current bar index for the open price line
if (timeframe.change(sepTimeframeInput)) 
    log.info(str.tostring(open))
    if array.size(htfOpenPriceLines) > 0
        // Update the last line's x2 to end at the current first bar of the new period
        line.set_x2(array.get(htfOpenPriceLines, array.size(htfOpenPriceLines) - 1), bar_index)

    // Create a new line for the current period and add it to the array
    firstBarInPeriod := bar_index
    newLine = line.new(
         x1     = firstBarInPeriod,   // First bar of the period
         y1     = htfOpenPrice,       // HTF opening price
         x2     = bar_index,          // Starting as the first bar of the period for now
         y2     = htfOpenPrice,       // HTF opening price
         extend = extend.none,        // Do not extend beyond the current period
         color  = htfOpenLineColor,
         style  = getLineStyle(htfOpenLineStyle),
         width  = htfOpenLineWidth
     )
    array.push(htfOpenPriceLines, newLine)  // Add the new line to the array

// Ensure the current line continues to the latest bar
if array.size(htfOpenPriceLines) > 0
    line.set_x2(array.get(htfOpenPriceLines, array.size(htfOpenPriceLines) - 1), bar_index)  // Extend the current line to the latest bar

Overview

Users can select the target timeframe, such as monthly, to display vertical separator lines alongside a horizontal line marking the higher timeframe's opening price. Customization options include line styles, colors, and widths for both separators and open lines. Because the script uses lookahead_on when requesting higher-timeframe data via security calls, historical bars fetch the higher timeframe context.

Details

Published by

dbruce1990 on GitHub

Code credit

NotARobot_, 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

Any timeframe

Risk Notes

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

Settings

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

SettingTypeDefaultVariable
Separator Colorcolorcolor.graysepColorInput
Separator StylestringDottedsepStyleInput
Separator Widthint1sepWidthInput
Separator Timeframetimeframe1MsepTimeframeInput
Show HTF Opening PricebooltrueshowHTFOpenLine
HTF Opening Price Colorcolorcolor.grayhtfOpenLineColor
HTF Opening Line Widthint1htfOpenLineWidth
HTF Line StylestringDashedhtfOpenLineStyle
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 8 weeks 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