//@version=5 // PipAtlas - Previous Day & Week High/Low. MIT License, original PipAtlas code. // Education only, never financial advice. https://pipatlas.com indicator("PipAtlas Previous Day & Week High/Low", shorttitle = "PipAtlas PDH/PDL", overlay = true, max_labels_count = 20) showD = input.bool(true, "Previous day high/low") showW = input.bool(true, "Previous week high/low") showM = input.bool(false, "Previous month high/low") showLb = input.bool(true, "Price labels at the right edge") colD = input.color(color.new(#1E90FF, 0), "Day colour") colW = input.color(color.new(#FF8C00, 0), "Week colour") colM = input.color(color.new(#BA55D3, 0), "Month colour") // high[1]/low[1] with lookahead_on returns the FINISHED previous period only, // so the levels never change during the current day, week or month. [dH, dL] = request.security(syminfo.tickerid, "D", [high[1], low[1]], lookahead = barmerge.lookahead_on) [wH, wL] = request.security(syminfo.tickerid, "W", [high[1], low[1]], lookahead = barmerge.lookahead_on) [mH, mL] = request.security(syminfo.tickerid, "M", [high[1], low[1]], lookahead = barmerge.lookahead_on) // a level is only useful on a chart below its own timeframe okD = showD and timeframe.isintraday okW = showW and (timeframe.isintraday or timeframe.isdaily) okM = showM and not timeframe.ismonthly plot(okD ? dH : na, "Previous day high", colD, 1, plot.style_stepline) plot(okD ? dL : na, "Previous day low", colD, 1, plot.style_stepline) plot(okW ? wH : na, "Previous week high", colW, 1, plot.style_stepline) plot(okW ? wL : na, "Previous week low", colW, 1, plot.style_stepline) plot(okM ? mH : na, "Previous month high", colM, 1, plot.style_stepline) plot(okM ? mL : na, "Previous month low", colM, 1, plot.style_stepline) tag(bool on, float price, string txt, color col) => var label lb = na if barstate.islast label.delete(lb) lb := na if on and showLb and not na(price) lb := label.new(bar_index + 2, price, txt + " " + str.tostring(price, format.mintick), style = label.style_label_left, color = color.new(col, 85), textcolor = col, size = size.small) tag(okD, dH, "PDH", colD) tag(okD, dL, "PDL", colD) tag(okW, wH, "PWH", colW) tag(okW, wL, "PWL", colW) tag(okM, mH, "PMH", colM) tag(okM, mL, "PML", colM) alertcondition(okD and ta.cross(close, dH), "Crossed previous day high", "{{ticker}} crossed the previous day high - an observation, not a signal") alertcondition(okD and ta.cross(close, dL), "Crossed previous day low", "{{ticker}} crossed the previous day low - an observation, not a signal") alertcondition(okW and ta.cross(close, wH), "Crossed previous week high", "{{ticker}} crossed the previous week high - an observation, not a signal") alertcondition(okW and ta.cross(close, wL), "Crossed previous week low", "{{ticker}} crossed the previous week low - an observation, not a signal")