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.
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
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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Pre-Market (4:00-9:30)
bool
true
showPreMkt
NY Open (9:30-11:00)
bool
true
showNYOpen
Lunch (11:00-13:00)
bool
true
showLunch
Afternoon (13:00-15:00)
bool
true
showAftn
Close (15:00-16:00)
bool
true
showClose
Show Session Range Labels
bool
true
showRange
Pre-Market Color
color
color.new(color.blue, 90)
preMktColor
NY Open Color
color
color.new(color.green, 90)
nyOpenColor
Lunch Color
color
color.new(color.yellow, 92)
lunchColor
Afternoon Color
color
color.new(color.green, 90)
aftnColor
Close Color
color
color.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.
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
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-
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
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
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
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
Indicatorv6SMC / ICT / price actionSessions & time