Indicator · Pine Script v6 · Own pane

Macros, Sessions, and Quarters

by riegodavid-git· code credited to psyplo

An indicator that draws time-based boxes for intraday timing.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code128
Settings17inputs
LicenceNone statedfile: MPL-2.0
Last update4 months ago25 Jun 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

128 lines of Pine Script v6 from pinescript/macro_session_quarters.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

macro_session_quarters.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © psyplo

//@version=6
indicator("Macros, Sessions, and Quarters - psyplo", "MSQ", overlay=false, max_boxes_count=500)

// === Inputs ===
windowMinutes = input.int(10, "Minutes Before/After Hour", minval=1, maxval=30)

boxColor = input.color(color.new(#2195f3, 100), "Macro Box Color")
borderColor = input.color(color.new(#000000, 0), "Macro Border Color")

// Session Ribbon Box Colors
asiaColor   = input.color(color.new(#FFD700, 100), "Asia Session Box Color")
londonColor = input.color(color.new(#FF00FF, 100), "London Session Box Color")
nyColor     = input.color(color.new(#00FF00, 100), "New York Session Box Color")
asiaBorderColor   = input.color(color.new(#000000, 0), "Asia Session Border Color")
londonBorderColor = input.color(color.new(#000000, 0), "London Session Border Color")
nyBorderColor     = input.color(color.new(#000000, 0), "New York Session Border Color")

// Customizable Quarter Colors
quarterColor1 = input.color(color.new(#FFD700, 100), "Quarter 1 Box Color")
quarterColor2 = input.color(color.new(#FFD700, 100), "Quarter 2 Box Color")
quarterColor3 = input.color(color.new(#FFD700, 100), "Quarter 3 Box Color")
quarterColor4 = input.color(color.new(#FFD700,100),  "Quarter 4 Box Color")
quarterBorderColor1 = input.color(color.new(#000000, 0), "Quarter 1 Border Color")
quarterBorderColor2 = input.color(color.new(#000000, 0), "Quarter 2 Border Color")
quarterBorderColor3 = input.color(color.new(#000000, 0), "Quarter 3 Border Color")
quarterBorderColor4 = input.color(color.new(#000000, 0),  "Quarter 4 Border Color")

// === Macro Time Window Logic ===
var box currentMacroBox = na
var float sessionHigh = na
var float sessionLow = na

isInMacroWindow() =>
    currentMinute = minute(time)
    currentMinute < windowMinutes or currentMinute >= (60 - windowMinutes)

inWindow = isInMacroWindow()
newWindow = inWindow and not inWindow[1]

if newWindow
    sessionHigh := high
    sessionLow := low
    currentMacroBox := box.new(left=bar_index, right=bar_index, top=high, bottom=low, bgcolor=boxColor, border_color=borderColor, force_overlay = true)
else if inWindow and not na(currentMacroBox)
    sessionHigh := math.max(sessionHigh, high)
    sessionLow := math.min(sessionLow, low)
    box.set_top(currentMacroBox, sessionHigh)
    box.set_bottom(currentMacroBox, sessionLow)
    box.set_right(currentMacroBox, bar_index)

windowEnded = not inWindow and inWindow[1]
if windowEnded and not na(currentMacroBox)
    box.set_right(currentMacroBox, bar_index)

// === Session Ribbon as Fixed Boxes ===
hourNow = hour(time, "Asia/Singapore")  // UTC+8

asiaSession   = hourNow >= 6 and hourNow < 12
londonSession = hourNow >= 12 and hourNow < 18
nySession     = hourNow >= 18 and hourNow < 24
sessionEnded  = hourNow == 0  // Reset at 12:00AM

var box sessionRibbonBox = na
var int sessionStartBar = na

var box[] quarterBoxes = array.new<box>()
var int quarterBars = math.round(90 / timeframe.multiplier)

// Reset on new session
if asiaSession and not asiaSession[1]
    sessionRibbonBox := box.new(left=bar_index, right=bar_index, top=1, bottom=0, bgcolor=asiaColor, border_color=asiaBorderColor)
    box.set_text(sessionRibbonBox, "Asia")
    box.set_text_color(sessionRibbonBox, color.black)
    box.set_text_size(sessionRibbonBox, size.normal)
    box.set_text_halign(sessionRibbonBox, text.align_center)
    box.set_text_valign(sessionRibbonBox, text.align_center)
    sessionStartBar := bar_index
    array.clear(quarterBoxes)
else if londonSession and not londonSession[1]
    sessionRibbonBox := box.new(left=bar_index, right=bar_index, top=1, bottom=0, bgcolor=londonColor, border_color=londonBorderColor)
    box.set_text(sessionRibbonBox, "London")
    box.set_text_color(sessionRibbonBox, color.black)
    box.set_text_size(sessionRibbonBox, size.normal)
    box.set_text_halign(sessionRibbonBox, text.align_center)
    box.set_text_valign(sessionRibbonBox, text.align_center)
    sessionStartBar := bar_index
    array.clear(quarterBoxes)
else if nySession and not nySession[1]
    sessionRibbonBox := box.new(left=bar_index, right=bar_index, top=1, bottom=0, bgcolor=nyColor, border_color=nyBorderColor)
    box.set_text(sessionRibbonBox, "New York")
    box.set_text_color(sessionRibbonBox, color.black)
    box.set_text_size(sessionRibbonBox, size.normal)
    box.set_text_halign(sessionRibbonBox, text.align_center)
    box.set_text_valign(sessionRibbonBox, text.align_center)
    sessionStartBar := bar_index
    array.clear(quarterBoxes)

if not na(sessionRibbonBox)
    box.set_right(sessionRibbonBox, bar_index)

if sessionEnded and not na(sessionRibbonBox)
    box.set_right(sessionRibbonBox, bar_index)
    sessionRibbonBox := na
    sessionStartBar := na

// --- Session Quarters Logic ---
if not na(sessionStartBar)
    quarterIndex = ((bar_index - sessionStartBar) / quarterBars)
    quarterStep = math.floor(quarterIndex)

    quarterColor = quarterStep == 0 ? quarterColor1 : quarterStep == 1 ? quarterColor2 : quarterStep == 2 ? quarterColor3 : quarterStep == 3 ? quarterColor4 : na

    quarterBorder = quarterStep == 0 ? quarterBorderColor1 : quarterStep == 1 ? quarterBorderColor2 : quarterStep == 2 ? quarterBorderColor3 : quarterStep == 3 ? quarterBorderColor4 : na

    if quarterStep < 4 and (array.size(quarterBoxes) <= quarterStep)
        qBox = box.new(left=bar_index, right=bar_index, top=2, bottom=1, bgcolor=quarterColor, border_color=quarterBorder)
        box.set_text(qBox, "Q" + str.tostring(quarterStep + 1))
        box.set_text_color(qBox, color.black)
        box.set_text_size(qBox, size.small)
        box.set_text_halign(qBox, text.align_center)
        box.set_text_valign(qBox, text.align_center)
        array.push(quarterBoxes, qBox)
    else if quarterStep < 4
        qBox = array.get(quarterBoxes, quarterStep)
        box.set_right(qBox, bar_index)

Overview

Macro boxes cover a set number of minutes before and after each hour and follow the high and low of that window. A session ribbon shows Asia, London and New York blocks using Singapore time, and quarter boxes divide the day into 90-minute sections based on the chart timeframe. Window length and all box and border colours are adjustable. The pane is separate, with macro boxes forced onto the price chart. It has no signals.

Details

Published by

riegodavid-git on GitHub

Code credit

psyplo, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

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
Minutes Before/After Hourint10windowMinutes
Macro Box Colorcolorcolor.new(#2195f3, 100)boxColor
Macro Border Colorcolorcolor.new(#000000, 0)borderColor
Asia Session Box Colorcolorcolor.new(#FFD700, 100)asiaColor
London Session Box Colorcolorcolor.new(#FF00FF, 100)londonColor
New York Session Box Colorcolorcolor.new(#00FF00, 100)nyColor
Asia Session Border Colorcolorcolor.new(#000000, 0)asiaBorderColor
London Session Border Colorcolorcolor.new(#000000, 0)londonBorderColor
New York Session Border Colorcolorcolor.new(#000000, 0)nyBorderColor
Quarter 1 Box Colorcolorcolor.new(#FFD700, 100)quarterColor1
Quarter 2 Box Colorcolorcolor.new(#FFD700, 100)quarterColor2
Quarter 3 Box Colorcolorcolor.new(#FFD700, 100)quarterColor3
Show all 17 settings
SettingTypeDefaultVariable
Quarter 4 Box Colorcolorcolor.new(#FFD700,100)quarterColor4
Quarter 1 Border Colorcolorcolor.new(#000000, 0)quarterBorderColor1
Quarter 2 Border Colorcolorcolor.new(#000000, 0)quarterBorderColor2
Quarter 3 Border Colorcolorcolor.new(#000000, 0)quarterBorderColor3
Quarter 4 Border Colorcolorcolor.new(#000000, 0)quarterBorderColor4
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

This indicator plots a Supertrend-based trend-following setup in a separate pane and skips conditions it treats as a sideways market. A volatility range is built from an ATR value, with RMA, SMA, EMA, or WMA smoothing, or from a fixed point distance. Optional

Indicator v5 TrendVolatility & bands
Updated 1 year ago · MPL-2.0 GitHub repository of Trend Following Setup - Sideways Market Skipper
549 stars

Range Volume Change compares volume inside a chosen session window with the same window on the previous day and plots that change as a percentage. It accumulates volume during the window and, when enabled, volume outside it, drawing growing columns in a separa

Indicator v5 VolumeSessions & time Repaints
Updated 10 months ago · None stated GitHub repository of Range Volume Change
257 stars

Donald SPX - Options Trading is an indicator designed to assist SPX index option traders by tracking session benchmarks and multi-timeframe moving average data. It calculates a 200-period weighted moving average (WMA) and requests multi-timeframe bar data from

Indicator v5 Moving averagesScreeners & dashboards Repaints
Updated 6 weeks ago · None stated GitHub repository of Donald SPX - Options Trading

Bar date/time

by be-thomas
65 stars

This indicator plots each bar's opening time as a numeric series in a separate pane. It uses Pine Script's built-in time value and draws one plot, not an overlay on price. There are no inputs, so the line follows the chart's bar timestamps without filters or o

Indicator v4 Sessions & time
Updated 5 days ago · GPL-3.0 GitHub repository of Bar date/time
46 stars

This indicator summarizes higher-timeframe candle range statistics by time of day and shows them in a table in a separate pane. It groups candles into slots for 5-minute, 15-minute, 1-hour, 4-hour, 8-hour, or 12-hour periods over a chosen lookback in days, and

Indicator v5 Screeners & dashboardsSessions & time Repaints
Updated 7 weeks ago · None stated GitHub repository of HTF Candle Stats by Time of Day
10 stars

This indicator plots the active hours of major global trading sessions including Tokyo, Berlin, London, Sydney, and New York. It dynamically adjusts session times based on whether the instrument is classified as a traditional market or crypto. The script uses

Indicator v4 Sessions & time
Updated 5 years ago · None stated GitHub repository of My Trading Sessions

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