Skip to content
GetProfitable
Search
Market structure

Previous Week High, Low and Close

Last week's high, low and close carried onto a daily or intraday chart, with the week's range shaded, so the wider frame stays on the screen while you work inside a much smaller one.

indicator
//@version=6
indicator("Previous Week High, Low and Close", "PW Levels", overlay = true)

shadeRange = input.bool(true, "Shade the prior week range", group = "Settings")
showClose = input.bool(true, "Show the prior week close", group = "Settings")
lineCol = input.color(#787B86, "Lines", group = "Style")
upCol = input.color(#26A69A, "Break above", group = "Style")
downCol = input.color(#EF5350, "Break below", group = "Style")

weekHigh = request.security(syminfo.tickerid, "W", high[1], lookahead = barmerge.lookahead_on)
weekLow = request.security(syminfo.tickerid, "W", low[1], lookahead = barmerge.lookahead_on)
weekClose = request.security(syminfo.tickerid, "W", close[1], lookahead = barmerge.lookahead_on)

highPlot = plot(weekHigh, "Prior week high", color = lineCol, style = plot.style_linebr)
lowPlot = plot(weekLow, "Prior week low", color = lineCol, style = plot.style_linebr)
plot(showClose ? weekClose : na, "Prior week close", color = color.new(lineCol, 40), style = plot.style_linebr)
fill(highPlot, lowPlot, color = shadeRange ? color.new(lineCol, 94) : na, title = "Prior week range")

brokeHigh = ta.crossover(close, weekHigh)
brokeLow = ta.crossunder(close, weekLow)
plotshape(brokeHigh, "Above prior week high", location = location.belowbar, style = shape.triangleup, color = upCol, size = size.tiny)
plotshape(brokeLow, "Below prior week low", location = location.abovebar, style = shape.triangledown, color = downCol, size = size.tiny)
alertcondition(brokeHigh, "Above prior week high", "Price crossed above the previous week high")
alertcondition(brokeLow, "Below prior week low", "Price crossed below the previous week low")
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

  • Weekly levels are read with lookahead so they are fixed from the first bar of the new week and do not repaint. That also means they say nothing about this week.
  • A level is a place where people have business, not a forecast. Price crossing it is a location, not an instruction.
  • On a weekly or higher chart these lines only restate the previous bar. Use them on daily and below.

Written from this description

Draw the previous week's high, low and close as horizontal lines on a daily or intraday chart, shade the area between the high and the low, and alert when price crosses the prior week's high or low.

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.