Skip to content

Free TradingView indicator

Previous Period Levels

Plots the previous day, week and month high, low and close as non-repainting lines with labels and alerts.

Levelsv1.0TradingView (Pine Script v6) Non-repainting signals Alerts

What it does

The high, low and close of the previous day, week and month are some of the most watched reference prices in trading. They mark where the last completed period found its extremes and where it settled. This indicator draws them on your chart as horizontal lines that start fresh with each new period, with labels at the right edge.

Each group can be toggled on or off, so you can keep a clean chart with only the levels you use.

How it works

  1. The script requests the high, low and close of the daily, weekly and monthly bars of the current symbol.
  2. Only completed bars are used. With lookahead off, historical chart bars take the higher-timeframe value offset by one chart bar, and live bars take the previous higher-timeframe bar directly. The result is that a level never changes once its period has begun and is never taken from the future.
  3. Lines break at the start of each new period so that one day's levels do not join the next day's with a vertical line.
  4. Daily levels are hidden on daily and higher charts, weekly levels on weekly and higher, and monthly levels on monthly charts, because they add nothing there.
  5. Alerts fire on closed bars that close above the previous day or week high, or below the previous day or week low.

How to use it

These levels are a simple map of where the market has recently turned or settled:

  • Previous day high and low often act as intraday support and resistance. A clean close beyond them can signal a range expansion day.
  • The previous close is a neutral reference: price above it means the current period is trading higher than where the last one ended.
  • Weekly and monthly highs and lows matter more for swing trading on H1 to H4 charts.
  • Many traders watch for false breaks: price pierces the previous day high, fails to hold, and closes back below.

You can combine these levels with the support and resistance lesson's ideas and with your own entry method. Always define a stop-loss before trading a level.

Settings

InputDefaultWhat it changes
Show previous day high / lowonPDH and PDL.
Show previous day closeonPDC (dotted).
Show previous week high / lowonPWH and PWL.
Show previous week closeoffPWC (dotted).
Show previous month high / lowoffPMH and PML.
Show previous month closeoffPMC (dotted).
Day / week / month colorblue / purple / orangeLine colors.
Show labels on the last baronNames and prices at the right edge.

Limitations

  • The day boundary comes from the data feed. Forex feeds and brokers use different rollover times, so the "previous day" can differ between platforms.
  • Some symbols have separate regular and extended sessions; the levels follow whatever the chart's daily bar uses.
  • Levels are reference points, not predictions. Price can slice through them, especially around news.
  • Alerts cover the daily and weekly high and low only. Monthly levels are visual.

Pine Script source

In TradingView open Pine Editor, paste the code, click Save and then Add to chart.

FXP_PreviousPeriodLevels.pine

96 lines

// © FXPIPS ONLINE — https://fxpips.online/tradingview-indicators/previous-period-levels/
// License: MIT. Educational tool — not financial advice. Trading involves substantial risk.
//@version=6
indicator("FXP Previous Period Levels", shorttitle = "FXP Prev Levels", overlay = true, max_labels_count = 20)

// ── Inputs ─────────────────────────────────────────────────────────────
grpD     = "Previous day"
showD    = input.bool(true, "Show previous day high / low", group = grpD)
showDC   = input.bool(true, "Show previous day close", group = grpD)
dCol     = input.color(color.blue, "Day color", group = grpD)

grpW     = "Previous week"
showW    = input.bool(true, "Show previous week high / low", group = grpW)
showWC   = input.bool(false, "Show previous week close", group = grpW)
wCol     = input.color(color.purple, "Week color", group = grpW)

grpM     = "Previous month"
showM    = input.bool(false, "Show previous month high / low", group = grpM)
showMC   = input.bool(false, "Show previous month close", group = grpM)
mCol     = input.color(color.orange, "Month color", group = grpM)

grpVis   = "Display"
showLbl  = input.bool(true, "Show labels on the last bar", group = grpVis)

// ── Non-repainting previous-period values ──────────────────────────────
// Historical bars: take the higher-timeframe value and offset it one chart bar.
// Realtime bars: take the previous higher-timeframe bar directly.
int htfIdx = barstate.isrealtime ? 1 : 0
int chIdx  = barstate.isrealtime ? 0 : 1

[dH0, dL0, dC0] = request.security(syminfo.tickerid, "D", [high[htfIdx], low[htfIdx], close[htfIdx]], lookahead = barmerge.lookahead_off)
[wH0, wL0, wC0] = request.security(syminfo.tickerid, "W", [high[htfIdx], low[htfIdx], close[htfIdx]], lookahead = barmerge.lookahead_off)
[mH0, mL0, mC0] = request.security(syminfo.tickerid, "M", [high[htfIdx], low[htfIdx], close[htfIdx]], lookahead = barmerge.lookahead_off)

float pdh = dH0[chIdx]
float pdl = dL0[chIdx]
float pdc = dC0[chIdx]
float pwh = wH0[chIdx]
float pwl = wL0[chIdx]
float pwc = wC0[chIdx]
float pmh = mH0[chIdx]
float pml = mL0[chIdx]
float pmc = mC0[chIdx]

// Daily levels on a daily-or-higher chart (and so on) add nothing, so hide them there.
int chartSec = timeframe.in_seconds()
bool dOk = showD and chartSec < timeframe.in_seconds("D")
bool wOk = showW and chartSec < timeframe.in_seconds("W")
bool mOk = showM and chartSec < timeframe.in_seconds("M")
bool dcOk = showDC and chartSec < timeframe.in_seconds("D")
bool wcOk = showWC and chartSec < timeframe.in_seconds("W")
bool mcOk = showMC and chartSec < timeframe.in_seconds("M")

bool newD = timeframe.change("D")
bool newW = timeframe.change("W")
bool newM = timeframe.change("M")

// ── Plots (lines break at each new period) ─────────────────────────────
plot(dOk and not newD ? pdh : na, "PDH", color = dCol, style = plot.style_linebr)
plot(dOk and not newD ? pdl : na, "PDL", color = dCol, style = plot.style_linebr)
plot(dcOk and not newD ? pdc : na, "PDC", color = color.new(dCol, 40), style = plot.style_circles, linewidth = 1)
plot(wOk and not newW ? pwh : na, "PWH", color = wCol, linewidth = 2, style = plot.style_linebr)
plot(wOk and not newW ? pwl : na, "PWL", color = wCol, linewidth = 2, style = plot.style_linebr)
plot(wcOk and not newW ? pwc : na, "PWC", color = color.new(wCol, 40), style = plot.style_circles, linewidth = 1)
plot(mOk and not newM ? pmh : na, "PMH", color = mCol, linewidth = 2, style = plot.style_linebr)
plot(mOk and not newM ? pml : na, "PML", color = mCol, linewidth = 2, style = plot.style_linebr)
plot(mcOk and not newM ? pmc : na, "PMC", color = color.new(mCol, 40), style = plot.style_circles, linewidth = 1)

// ── Labels (reused, last bar only) ─────────────────────────────────────
var array<label> lbls = array.new_label()
if barstate.islast
    array<float>  vals  = array.from(pdh, pdl, pdc, pwh, pwl, pwc, pmh, pml, pmc)
    array<bool>   shown = array.from(dOk, dOk, dcOk, wOk, wOk, wcOk, mOk, mOk, mcOk)
    array<string> names = array.from("PDH", "PDL", "PDC", "PWH", "PWL", "PWC", "PMH", "PML", "PMC")
    array<color>  cols  = array.from(dCol, dCol, dCol, wCol, wCol, wCol, mCol, mCol, mCol)
    if array.size(lbls) == 0
        for i = 0 to 8
            array.push(lbls, label.new(bar_index, close, "", style = label.style_label_left, color = color.new(color.black, 100), size = size.small))
    for i = 0 to 8
        label lb = array.get(lbls, i)
        float v = array.get(vals, i)
        bool vis = showLbl and array.get(shown, i) and not na(v)
        label.set_xy(lb, bar_index + 1, vis ? v : close)
        label.set_text(lb, vis ? array.get(names, i) + "  " + str.tostring(v, format.mintick) : "")
        label.set_textcolor(lb, array.get(cols, i))

// ── Alerts (closed bars) ───────────────────────────────────────────────
bool upPDH = ta.crossover(close, pdh) and barstate.isconfirmed and not newD
bool dnPDL = ta.crossunder(close, pdl) and barstate.isconfirmed and not newD
bool upPWH = ta.crossover(close, pwh) and barstate.isconfirmed and not newW
bool dnPWL = ta.crossunder(close, pwl) and barstate.isconfirmed and not newW
alertcondition(upPDH, "Close above previous day high", "FXP Prev Levels: close above PDH on {{ticker}} {{interval}}")
alertcondition(dnPDL, "Close below previous day low", "FXP Prev Levels: close below PDL on {{ticker}} {{interval}}")
alertcondition(upPWH, "Close above previous week high", "FXP Prev Levels: close above PWH on {{ticker}} {{interval}}")
alertcondition(dnPWL, "Close below previous week low", "FXP Prev Levels: close below PWL on {{ticker}} {{interval}}")

Key inputs

Key inputs of Previous Period Levels
InputDefaultDescription
Show previous day high / lowtruePDH and PDL lines.
Show previous day closetruePDC line.
Show previous week high / lowtruePWH and PWL lines.
Show previous week closefalsePWC line.
Show previous month high / lowfalsePMH and PML lines.
Show previous month closefalsePMC line.
Show labels on the last bartrueLevel names and prices at the right edge of the chart.

Educational tools, not advice. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related tradingview indicators