Indicator · Pine Script v6 · On the chart

Session Boxes

by insomniac-asif

Draws shaded boxes on the price chart for intraday futures sessions in New York time: pre-market from 4:00, the New York open from 9:30, lunch from 11:00, afternoon from 13:00 and the close from 15:00 to 16:00.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code113
Settings11inputs
LicenceMIT
Last update2 months ago20 Aug 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

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

session_boxes.pine
//@version=6
indicator("Session Boxes — Futures Signal Engine", overlay=true, max_boxes_count=500)

// ── Inputs ──────────────────────────────────────────────────────────────────
showPreMkt  = input.bool(true, "Pre-Market (4:00-9:30)")
showNYOpen  = input.bool(true, "NY Open (9:30-11:00)")
showLunch   = input.bool(true, "Lunch (11:00-13:00)")
showAftn    = input.bool(true, "Afternoon (13:00-15:00)")
showClose   = input.bool(true, "Close (15:00-16:00)")
showRange   = input.bool(true, "Show Session Range Labels")

preMktColor = input.color(color.new(color.blue, 90), "Pre-Market Color")
nyOpenColor = input.color(color.new(color.green, 90), "NY Open Color")
lunchColor  = input.color(color.new(color.yellow, 92), "Lunch Color")
aftnColor   = input.color(color.new(color.green, 90), "Afternoon Color")
closeColor  = input.color(color.new(color.orange, 90), "Close Color")

// ── Session tracking ────────────────────────────────────────────────────────
nyHour   = hour(time, "America/New_York")
nyMinute = minute(time, "America/New_York")

// Session boundary detection
isPreMktStart = nyHour == 4  and nyMinute == 0
isNYOpenStart = nyHour == 9  and nyMinute == 30
isLunchStart  = nyHour == 11 and nyMinute == 0
isAftnStart   = nyHour == 13 and nyMinute == 0
isCloseStart  = nyHour == 15 and nyMinute == 0
isCloseEnd    = nyHour == 16 and nyMinute == 0

// Track session highs/lows
var float sessHigh = na
var float sessLow  = na
var int   sessStart = na
var string sessName = ""

// ── NY Open session box ────────────────────────────────────────────────────
var float nyoHigh = na
var float nyoLow  = na
var int   nyoStart = na

if isNYOpenStart
    nyoHigh  := high
    nyoLow   := low
    nyoStart := bar_index

inNYOpen = nyHour >= 9 and nyMinute >= 30 and nyHour < 11
if inNYOpen and not isNYOpenStart
    nyoHigh := math.max(nz(nyoHigh, high), high)
    nyoLow  := math.min(nz(nyoLow, low), low)

if showNYOpen and isLunchStart and not na(nyoHigh)
    box.new(nyoStart, nyoHigh, bar_index, nyoLow, border_color=color.new(color.green, 60), bgcolor=nyOpenColor, border_width=1)
    if showRange
        label.new(nyoStart, nyoHigh, "NY Open\n" + str.tostring(nyoHigh - nyoLow, format.mintick) + " range", style=label.style_label_down, textcolor=color.green, color=color.new(color.green, 85), size=size.tiny)

// ── Lunch session box ───────────────────────────────────────────────────────
var float lnchHigh = na
var float lnchLow  = na
var int   lnchStart = na

if isLunchStart
    lnchHigh  := high
    lnchLow   := low
    lnchStart := bar_index

inLunch = nyHour >= 11 and nyHour < 13
if inLunch and not isLunchStart
    lnchHigh := math.max(nz(lnchHigh, high), high)
    lnchLow  := math.min(nz(lnchLow, low), low)

if showLunch and isAftnStart and not na(lnchHigh)
    box.new(lnchStart, lnchHigh, bar_index, lnchLow, border_color=color.new(color.yellow, 60), bgcolor=lunchColor, border_width=1)
    if showRange
        label.new(lnchStart, lnchHigh, "Lunch\n" + str.tostring(lnchHigh - lnchLow, format.mintick) + " range", style=label.style_label_down, textcolor=color.yellow, color=color.new(color.yellow, 85), size=size.tiny)

// ── Afternoon session box ───────────────────────────────────────────────────
var float aftnHigh = na
var float aftnLow  = na
var int   aftnStart = na

if isAftnStart
    aftnHigh  := high
    aftnLow   := low
    aftnStart := bar_index

inAftn = nyHour >= 13 and nyHour < 15
if inAftn and not isAftnStart
    aftnHigh := math.max(nz(aftnHigh, high), high)
    aftnLow  := math.min(nz(aftnLow, low), low)

if showAftn and isCloseStart and not na(aftnHigh)
    box.new(aftnStart, aftnHigh, bar_index, aftnLow, border_color=color.new(color.green, 60), bgcolor=aftnColor, border_width=1)
    if showRange
        label.new(aftnStart, aftnHigh, "Afternoon\n" + str.tostring(aftnHigh - aftnLow, format.mintick) + " range", style=label.style_label_down, textcolor=color.green, color=color.new(color.green, 85), size=size.tiny)

// ── Close session box ───────────────────────────────────────────────────────
var float clsHigh = na
var float clsLow  = na
var int   clsStart = na

if isCloseStart
    clsHigh  := high
    clsLow   := low
    clsStart := bar_index

inClose = nyHour >= 15 and nyHour < 16
if inClose and not isCloseStart
    clsHigh := math.max(nz(clsHigh, high), high)
    clsLow  := math.min(nz(clsLow, low), low)

// Draw close box at end of day or last bar
if showClose and (isCloseEnd or (barstate.islast and inClose)) and not na(clsHigh)
    box.new(clsStart, clsHigh, bar_index, clsLow, border_color=color.new(color.orange, 60), bgcolor=closeColor, border_width=1)

Overview

Each box spans the high and low of its window, and an optional label shows the range size. Each session can be switched off and has its own colour. It is a visual aid only and gives no signals.

Details

Published by

insomniac-asif on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Sessions & time

Markets

Indices, Oil & commodities

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
Pre-Market (4:00-9:30)booltrueshowPreMkt
NY Open (9:30-11:00)booltrueshowNYOpen
Lunch (11:00-13:00)booltrueshowLunch
Afternoon (13:00-15:00)booltrueshowAftn
Close (15:00-16:00)booltrueshowClose
Show Session Range LabelsbooltrueshowRange
Pre-Market Colorcolorcolor.new(color.blue, 90)preMktColor
NY Open Colorcolorcolor.new(color.green, 90)nyOpenColor
Lunch Colorcolorcolor.new(color.yellow, 92)lunchColor
Afternoon Colorcolorcolor.new(color.green, 90)aftnColor
Close Colorcolorcolor.new(color.orange, 90)closeColor
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 11 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