Skip to content
GetProfitable
Search
Sessions and time

Session Highlighter

Shades two configurable trading sessions on an intraday chart, so the hours that actually matter for an instrument are visible instead of remembered.

indicator
//@version=6
indicator("Session Highlighter", "Sessions", overlay = true)

sessionOne = input.session("0930-1600", "Session 1", group = "Sessions")
sessionTwo = input.session("0300-0800", "Session 2", group = "Sessions")
zone = input.string("America/New_York", "Time zone", group = "Sessions")
showTwo = input.bool(true, "Show session 2", group = "Sessions")
colOne = input.color(#2962FF, "Session 1", group = "Style")
colTwo = input.color(#FF9800, "Session 2", group = "Style")

inOne = not na(time(timeframe.period, sessionOne, zone))
inTwo = not na(time(timeframe.period, sessionTwo, zone))

bgcolor(inOne ? color.new(colOne, 92) : na, title = "Session 1")
bgcolor(showTwo and inTwo ? color.new(colTwo, 92) : na, title = "Session 2")

openedOne = inOne and not inOne[1]
alertcondition(openedOne, "Session 1 opened", "The first session has opened")
This runs in TradingView, not here
Pine Script only executes inside TradingView. Paste the source into the Pine Editor and add it to a chart to see it plotted.

What it will not do

  • Sessions are given in the exchange time zone you choose, not your local one. Check the shading against a known open before trusting it.
  • On a daily or higher chart there is no intraday session to shade, so nothing is drawn.

Written from this description

Shade the background during two configurable sessions with their own time zone and colours, and alert when the first session opens.

Educational only, not financial advice. The maths is simple arithmetic on the numbers you enter; it knows nothing about your broker, fees, slippage or the market. Something wrong with it? Say so in Site Feedback.