Indicator · Pine Script v6 · On the chart

NYSE Market Lines & Labels

by KayK-Pips

This indicator marks regular New York Stock Exchange (NYSE) session open (9:30 AM ET) and close (4:00 PM ET) times directly on the price chart.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code111
Settings8inputs
LicenceMIT
Last update1 year ago22 Jan 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

111 lines of Pine Script v6 from NYSE_Market_Open_Lines_with_Labels.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

NYSE_Market_Open_Lines_with_Labels.pine
//@version=6
// @description Displays NYSE market open and close times with customizable vertical lines and labels, automatically adjusting to your local timezone
indicator("NYSE Market Lines & Labels", "NYSE Times", overlay=true)

// Helper function to create line style
getLineStyle(string style) => 
    style == "solid" ? line.style_solid : style == "dashed" ? line.style_dashed : line.style_dotted

// Helper function to get label size
getLabelSize(string size) => 
    size == "small" ? size.small : size == "normal" ? size.normal : size.large

// Input group for appearance settings
var string GRP_OPEN = "Market Open Line"
var string GRP_CLOSE = "Market Close Line"
var string GRP_LABELS = "Labels"

// Open Line appearance settings
openLineColor = input.color(color.new(color.blue, 0), "Color", inline="open", group=GRP_OPEN)
openLineWidth = input.int(2, "Width", minval=1, maxval=4, inline="open", group=GRP_OPEN)
openLineStyle = input.string("solid", "Style", options=["solid", "dashed", "dotted"], inline="open", group=GRP_OPEN)

// Close Line appearance settings
closeLineColor = input.color(color.new(color.red, 0), "Color", inline="close", group=GRP_CLOSE)
closeLineWidth = input.int(2, "Width", minval=1, maxval=4, inline="close", group=GRP_CLOSE)
closeLineStyle = input.string("solid", "Style", options=["solid", "dashed", "dotted"], inline="close", group=GRP_CLOSE)

// Label settings
showLabels = input.bool(true, "Show Labels", inline="labels", group=GRP_LABELS)
labelSize = input.string("large", "Size", options=["small", "normal", "large"], inline="labels", group=GRP_LABELS)

// Constants for market times in Eastern Time (ET)
var int MARKET_OPEN_HOUR = 14  // 9:30 ET = 14:30 UTC
var int MARKET_OPEN_MINUTE = 30
var int MARKET_CLOSE_HOUR = 21  // 16:00 ET = 21:00 UTC
var int MARKET_CLOSE_MINUTE = 0

// Variables to track future lines and labels
var line futureOpenLine = na
var label futureOpenLabel = na
var line futureCloseLine = na
var label futureCloseLabel = na

// Check if current bar is exactly at market time
isExactMarketTime(int targetHour, int targetMinute) =>
    hour(time) == targetHour and minute(time) == targetMinute and dayofweek != dayofweek.sunday and dayofweek != dayofweek.saturday

// Check if we're before market open
isBeforeMarketOpen() =>
    currentHour = hour(time)
    currentMinute = minute(time)
    isWeekday = dayofweek != dayofweek.sunday and dayofweek != dayofweek.saturday
    
    isWeekday and (currentHour < MARKET_OPEN_HOUR or (currentHour == MARKET_OPEN_HOUR and currentMinute < MARKET_OPEN_MINUTE))

// Calculate bars until next market open
calcBarsUntilMarketOpen() =>
    currentHour = hour(time)
    currentMinute = minute(time)
    
    // Calculate total minutes for current time and target time
    currentTotalMinutes = currentHour * 60 + currentMinute
    targetTotalMinutes = MARKET_OPEN_HOUR * 60 + MARKET_OPEN_MINUTE
    
    // Calculate minutes until next market open
    minutesUntilOpen = if currentTotalMinutes < targetTotalMinutes
        targetTotalMinutes - currentTotalMinutes
    else
        (24 * 60) - currentTotalMinutes + targetTotalMinutes
    
    // Convert minutes to bars based on chart timeframe
    math.round(minutesUntilOpen / timeframe.multiplier)

// Draw historical vertical lines and labels
if isExactMarketTime(MARKET_OPEN_HOUR, MARKET_OPEN_MINUTE)
    line.new(bar_index, low - (high - low) * 2, bar_index, high + (high - low) * 2, color=openLineColor, width=openLineWidth, style=getLineStyle(openLineStyle), extend=extend.both)
    
    if showLabels
        label.new(bar_index, high + (high - low) * 0.5, "Market Open", color=color.new(color.white, 100), textcolor=openLineColor, style=label.style_label_down, size=getLabelSize(labelSize))

if isExactMarketTime(MARKET_CLOSE_HOUR, MARKET_CLOSE_MINUTE)
    line.new(bar_index, low - (high - low) * 2, bar_index, high + (high - low) * 2, color=closeLineColor, width=closeLineWidth, style=getLineStyle(closeLineStyle), extend=extend.both)
    
    if showLabels
        label.new(bar_index, high + (high - low) * 0.5, "Market Close", color=color.new(color.white, 100), textcolor=closeLineColor, style=label.style_label_down, size=getLabelSize(labelSize))

// Draw next market event line (only on the last bar)
if barstate.islast
    line.delete(futureOpenLine)
    label.delete(futureOpenLabel)
    line.delete(futureCloseLine)
    label.delete(futureCloseLabel)
    
    // Draw next market open line if we're before market open
    if isBeforeMarketOpen()
        barsUntilOpen = calcBarsUntilMarketOpen()
        futureOpenLine := line.new(bar_index + barsUntilOpen, low - (high - low) * 2, bar_index + barsUntilOpen, high + (high - low) * 2, color=color.new(openLineColor, 60), width=openLineWidth, style=getLineStyle(openLineStyle), extend=extend.both)
        
        if showLabels
            futureOpenLabel := label.new(bar_index + barsUntilOpen, high + (high - low) * 0.5, "Next Market Open", color=color.new(color.white, 100), textcolor=color.new(openLineColor, 60), style=label.style_label_down, size=getLabelSize(labelSize))

    // Draw next market close line
    if hour(time) == MARKET_CLOSE_HOUR and minute(time) == MARKET_CLOSE_MINUTE
        futureCloseLine := line.new(bar_index, low - (high - low) * 2, bar_index, high + (high - low) * 2, color=color.new(closeLineColor, 60), width=closeLineWidth, style=getLineStyle(closeLineStyle), extend=extend.both)
        
        if showLabels
            futureCloseLabel := label.new(bar_index, high + (high - low) * 0.5, "Next Market Close", color=color.new(color.white, 100), textcolor=color.new(closeLineColor, 60), style=label.style_label_down, size=getLabelSize(labelSize))

// Plot alert dots for market events
plotchar(isExactMarketTime(MARKET_OPEN_HOUR, MARKET_OPEN_MINUTE), "Market Open", "•", location.top, color.blue, size=size.large)
plotchar(isExactMarketTime(MARKET_CLOSE_HOUR, MARKET_CLOSE_MINUTE), "Market Close", "•", location.top, color.red, size=size.large)

Overview

NYSE Market Lines & Labels draws vertical lines and descriptive text labels at historical session boundaries and projects lines forward for upcoming session events on weekdays. User settings allow customization of line color, width, and style for open and close markers separately, alongside label visibility and font sizing. Fixed UTC offsets are used for timing, which may require adjustment across daylight saving time shifts.

Details

Published by

KayK-Pips on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Sessions & time

Markets

Stocks, Indices

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
Colorcolorcolor.new(color.blue, 0)openLineColor
Widthint2openLineWidth
StylestringsolidopenLineStyle
Colorcolorcolor.new(color.red, 0)closeLineColor
Widthint2closeLineWidth
StylestringsolidcloseLineStyle
Show LabelsbooltrueshowLabels
SizestringlargelabelSize
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

948 stars

This indicator counts down to a fixed Litecoin halving timestamp in August 2019, using Greenwich Mean Time. It subtracts the current time from that stamp and formats the remaining days, hours, minutes, and seconds. The day, hour, and minute of the target are u

Indicator v4 Sessions & time
Updated 10 days ago · GPL-3.0 GitHub repository of Litecoin Halving UTC Countdown
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

This indicator identifies and plots key options expiration dates on the price chart. It calculates monthly OpEx (the third Friday of each month), quarterly OpEx (March, June, September, December), and corresponding VIX expiration dates, drawing vertical lines

Indicator v6 Sessions & time
Updated 2 months ago · MIT GitHub repository of Expiration Highlights: Opex, Quarterly Opex & VIX with Vanna/Charm
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

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