Skip to content
GetProfitable
Search
Sessions and time

Session High and Low

The running high and low of the current session as two lines that reset when the next one opens, so the day's extremes sit on the chart without being measured by hand.

indicator
//@version=6
indicator("Session High and Low", "Sess HL", overlay = true)

sessionSpec = input.session("0930-1600", "Session", group = "Sessions")
zone = input.string("America/New_York", "Time zone", group = "Sessions")
showMid = input.bool(true, "Show midpoint", group = "Settings")
bull = input.color(#26A69A, "Session high", group = "Style")
bear = input.color(#EF5350, "Session low", group = "Style")
midCol = input.color(#787B86, "Midpoint", group = "Style")

inSession = not na(time(timeframe.period, sessionSpec, zone))
sessionStart = inSession and not inSession[1]

var float sessionHigh = na
var float sessionLow = na

if sessionStart
    sessionHigh := high
    sessionLow := low
else if inSession
    sessionHigh := math.max(sessionHigh, high)
    sessionLow := math.min(sessionLow, low)

pHigh = plot(inSession ? sessionHigh : na, "Session high", color = bull, style = plot.style_linebr)
pLow = plot(inSession ? sessionLow : na, "Session low", color = bear, style = plot.style_linebr)
plot(showMid and inSession ? (sessionHigh + sessionLow) / 2 : na, "Midpoint", color = color.new(midCol, 30), style = plot.style_linebr)
fill(pHigh, pLow, color = color.new(midCol, 95), title = "Session range")

newHigh = inSession and not sessionStart and high > sessionHigh[1]
newLow = inSession and not sessionStart and low < sessionLow[1]
plotshape(newHigh, "New session high", location = location.abovebar, style = shape.triangleup, color = bull, size = size.tiny)
plotshape(newLow, "New session low", location = location.belowbar, style = shape.triangledown, color = bear, size = size.tiny)
alertcondition(newHigh, "New session high", "Price made a new high for the session")
alertcondition(newLow, "New session low", "Price made a new low for the session")
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

  • These are the extremes so far, not finished levels. They move as the session goes on, which makes them a poor thing to backtest against.
  • Nothing is plotted outside the chosen session, and nothing at all on a daily or higher chart where the bar is already the session.
  • Session times are given in the exchange time zone you pick, not your local one. Check them against a known open first.
  • A new session high says the session is expanding, not that it will keep going. It is most common in exactly the hour a move is ending.

Written from this description

Track the high and low of the current session, plot them as two lines that reset at each session open, add the midpoint between them, and alert when a new session high or low is made.

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.