Sessions and time
Day Separator
A dotted vertical line at the start of each new trading day with alternate days faintly shaded, which keeps a long intraday chart readable when the chart's own session breaks are turned off.
indicator
//@version=6
indicator("Day Separator", "Days", overlay = true, max_lines_count = 100)
shadeDays = input.bool(true, "Shade alternate days", group = "Settings")
lineCol = input.color(#787B86, "Separator", group = "Style")
shadeCol = input.color(#2962FF, "Shading", group = "Style")
newDay = timeframe.isintraday and timeframe.change("D")
var int dayCount = 0
if newDay
dayCount := dayCount + 1
line.new(bar_index, low, bar_index, high, xloc = xloc.bar_index, extend = extend.both, color = lineCol, style = line.style_dotted)
shaded = shadeDays and timeframe.isintraday and dayCount % 2 == 1
bgcolor(shaded ? color.new(shadeCol, 95) : na, title = "Alternate day")
alertcondition(newDay, "New trading day", "A new trading day has started on this chart")
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
- The day boundary is the exchange's, not your local midnight, so on an instrument that trades overnight the day changes in the middle of a move.
- TradingView keeps a limited number of drawings, so the oldest separators are dropped as you scroll further back.
- Nothing is drawn on a daily or higher chart, where every bar is already a day.
Written from this description
Draw a vertical dotted line at the start of every new trading day on an intraday chart and shade alternate days faintly so each day is easy to separate by eye.
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.