Jayadev Rana Get a custom script
Free Pine Script Indicators / Previous Day Levels
Free indicator · Pine Script v6

Previous Day Levels

Yesterday's high and low drawn automatically on any chart and timeframe, with the range shaded, breakout markers and alerts. Non-repainting: it reads the previous completed daily candle.

IndicatorPine Script v6OverlayFree

Get the codeDownload .pine.txt

Snapshots

Yesterday's high (green) and low (red) as step lines, with the day's range shaded grey, on BTCUSDT 1h.
Yesterday's high (green) and low (red) as step lines, with the day's range shaded grey, on BTCUSDT 1h.
The same two levels before the shaded fill is added.
The same two levels before the shaded fill is added.
The complete script in the TradingView Pine Editor.
The complete script in the TradingView Pine Editor.

How it works

  1. request.security reads high[1] and low[1] from the daily timeframe, so the levels are yesterday's finished values.
  2. lookahead is only safe here because of the [1]: the script never uses data from an unfinished day.
  3. Create an alert on "Previous Day Levels" and pick "Broke yesterday's high" or "Broke yesterday's low".

Settings

SettingDefaultWhat it does
High colourgreenColour of yesterday's high line
Low colourredColour of yesterday's low line

Source code

In TradingView: open the Pine Editor, create a new indicator, paste the code, then click "Add to chart".

previous-day-levels.pine.txtGitHubDownload
//@version=6
indicator("Previous Day Levels", overlay = true)

// 1. Settings: the colours of the two lines
highColor = input.color(color.green, "High colour")
lowColor  = input.color(color.red, "Low colour")

// 2. The safe way to read yesterday (no repainting)
noRepaint = barmerge.lookahead_on

// 3. Yesterday's high and low, taken from the daily chart
prevHigh = request.security(syminfo.tickerid, "D", high[1], lookahead = noRepaint)
prevLow  = request.security(syminfo.tickerid, "D", low[1], lookahead = noRepaint)

// 4. Draw them as step lines that jump to the new level each day
pHigh = plot(prevHigh, "Prev day high", highColor, 2, plot.style_stepline)
pLow  = plot(prevLow, "Prev day low", lowColor, 2, plot.style_stepline)

// 5. Shade yesterday's range
fill(pHigh, pLow, color.new(color.gray, 90))

// 6. Did price break out of yesterday's range?
breakUp   = ta.crossover(close, prevHigh)
breakDown = ta.crossunder(close, prevLow)
plotshape(breakUp, "Break up", shape.triangleup, location.belowbar, highColor)
plotshape(breakDown, "Break down", shape.triangledown, location.abovebar, lowColor)

// 7. Alerts
alertcondition(breakUp, "Broke yesterday's high", "{{ticker}} broke the high")
alertcondition(breakDown, "Broke yesterday's low", "{{ticker}} broke the low")

Watch it built

This script is written and explained step by step in the video lesson.

Need a custom indicator or strategy?

Non-repainting Pine Script v6, backtested with real costs, alert and webhook ready. Fixed quote within 24 hours.

Free and open source under the Mozilla Public License 2.0. Educational content only, not financial advice. Backtest results are historical and include the costs stated; past performance does not predict future results. © Jayadev Rana · Privacy · Terms