本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// ─────────────────────────────────────────────────────────────────
// ███████╗██████╗ ██████╗ ██╗ █████╗ ██████╗
// ██╔════╝██╔══██╗██╔═══██╗██║ ██╔══██╗██╔══██╗
// █████╗ ██║ ██║██║ ██║██║ ███████║██████╔╝
// ██╔══╝ ██║ ██║██║ ██║██║ ██╔══██║██╔══██╗
// ███████╗██████╔╝╚██████╔╝███████╗██║ ██║██████╔╝
// ╚══════╝╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═════╝
// ─────────────────────────────────────────────────────────────────
// ███╗ ███╗ █████╗ ██████╗ ██╗ ██╗███████╗████████╗███████╗
// ████╗ ████║██╔══██╗██╔══██╗██║ ██╔╝██╔════╝╚══██╔══╝██╔════╝
// ██╔████╔██║███████║██████╔╝█████╔╝ █████╗ ██║ ███████╗
// ██║╚██╔╝██║██╔══██║██╔══██╗██╔═██╗ ██╔══╝ ██║ ╚════██║
// ██║ ╚═╝ ██║██║ ██║██║ ██║██║ ██╗███████╗ ██║ ███████║
// ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝
// ─────────────────────────────────────────────────────────────────
// © Edolab Markets
//@version=6
indicator("Edo PDH/PDL Levels", overlay = true, max_lines_count = 500, max_labels_count = 500)
// ================== SETTINGS — LEVELS ==================
showDay = input.bool(true, "Previous Day (PDH / PDL)", group = "Levels")
showWeek = input.bool(true, "Previous Week (PWH / PWL)", group = "Levels")
showMonth = input.bool(false, "Previous Month (PMH / PML)", group = "Levels")
showYear = input.bool(false, "Previous Year (PYH / PYL)", group = "Levels")
showMid = input.bool(false, "Show previous range midpoint (50%)", group = "Levels", tooltip = "Equilibrium of each previous period's range.")
// ================== SETTINGS — STYLE ==================
dayCol = input.color(#5B9FAD, "Day", inline = "c1", group = "Style")
weekCol = input.color(#E6B800, "Week", inline = "c1", group = "Style")
monthCol = input.color(#9C6ADE, "Month", inline = "c2", group = "Style")
yearCol = input.color(#ef5350, "Year", inline = "c2", group = "Style")
lineStyle = input.string("Dashed", "Line Style", options = ["Solid", "Dashed", "Dotted"], group = "Style")
extendRgt = input.bool(true, "Extend right", group = "Style")
extendR = input.int(8, "Right offset (bars)", minval = 0, maxval = 60, group = "Style")
showLabels = input.bool(true, "Show labels", group = "Style")
labelSize = input.string("Small", "Label Size", options = ["Tiny", "Small", "Normal"], group = "Style")
themeMode = input.string("Dark", "Theme Mode", options = ["Dark", "Light"], group = "Style", tooltip = "Match your TradingView background theme.")
// ================== SETTINGS — PANEL ==================
showPanel = input.bool(true, "Show Panel", group = "Panel")
panelPos = input.string("Top Right", "Panel Position", options = ["Top Right", "Top Left", "Bottom Right", "Bottom Left"], group = "Panel")
panelSize = input.string("Small", "Panel Size", options = ["Tiny", "Small", "Normal"], group = "Panel")
// ================== THEME ==================
isDark = themeMode == "Dark"
textCol = isDark ? #ffffff : #131722
headerBg = isDark ? #2a2e39 : #d1d4dc
subBg = isDark ? #363a45 : #e0e3eb
cellBg = isDark ? #1e222d : #f0f3fa
cellTxt = isDark ? #d1d4dc : #363a45
styTV = lineStyle == "Solid" ? line.style_solid : lineStyle == "Dotted" ? line.style_dotted : line.style_dashed
lblSizeTxt = labelSize == "Tiny" ? size.tiny : labelSize == "Normal" ? size.normal : size.small
panSizeTxt = panelSize == "Tiny" ? size.tiny : panelSize == "Normal" ? size.normal : size.small
fmt(float v) => na(v) ? "—" : str.tostring(v, format.mintick)
// ================== PREVIOUS-PERIOD VALUES (no repaint) ==================
// high[1]/low[1] of each HTF period are already closed -> lookahead is safe and non-repainting.
[pdh, pdl] = request.security(syminfo.tickerid, "D", [high[1], low[1]], lookahead = barmerge.lookahead_on)
[pwh, pwl] = request.security(syminfo.tickerid, "W", [high[1], low[1]], lookahead = barmerge.lookahead_on)
[pmh, pml] = request.security(syminfo.tickerid, "M", [high[1], low[1]], lookahead = barmerge.lookahead_on)
[pyh, pyl] = request.security(syminfo.tickerid, "12M", [high[1], low[1]], lookahead = barmerge.lookahead_on)
// ================== CROSS EVENTS (computed every bar for consistency) ==================
xPDH = ta.crossover(close, pdh)
xPDL = ta.crossunder(close, pdl)
xPWH = ta.crossover(close, pwh)
xPWL = ta.crossunder(close, pwl)
crossPDH = not na(pdh) and xPDH
crossPDL = not na(pdl) and xPDL
crossPWH = not na(pwh) and xPWH
crossPWL = not na(pwl) and xPWL
// ================== DRAW LEVELS ==================
var line[] lvlLines = array.new<line>()
var label[] lvlLabels = array.new<label>()
drawLevel(float price, string txt, color col) =>
if not na(price)
x1 = bar_index - 60
x2 = bar_index + extendR
ln = line.new(x1, price, x2, price, color = col, width = 1, style = styTV, extend = extendRgt ? extend.right : extend.none)
lvlLines.push(ln)
if showLabels
lb = label.new(x2, price, txt + " " + str.tostring(price, format.mintick), style = label.style_label_left, color = color.new(col, 90), textcolor = col, size = lblSizeTxt)
lvlLabels.push(lb)
if barstate.islast
// clear previous frame
if lvlLines.size() > 0
for i = 0 to lvlLines.size() - 1
line.delete(lvlLines.get(i))
if lvlLabels.size() > 0
for i = 0 to lvlLabels.size() - 1
label.delete(lvlLabels.get(i))
lvlLines.clear()
lvlLabels.clear()
if showDay
drawLevel(pdh, "PDH", dayCol)
drawLevel(pdl, "PDL", dayCol)
if showMid
drawLevel(math.avg(pdh, pdl), "PD 50%", dayCol)
if showWeek
drawLevel(pwh, "PWH", weekCol)
drawLevel(pwl, "PWL", weekCol)
if showMid
drawLevel(math.avg(pwh, pwl), "PW 50%", weekCol)
if showMonth
drawLevel(pmh, "PMH", monthCol)
drawLevel(pml, "PML", monthCol)
if showMid
drawLevel(math.avg(pmh, pml), "PM 50%", monthCol)
if showYear
drawLevel(pyh, "PYH", yearCol)
drawLevel(pyl, "PYL", yearCol)
if showMid
drawLevel(math.avg(pyh, pyl), "PY 50%", yearCol)
// ================== PANEL ==================
if showPanel and barstate.islast
panelPosTV = switch panelPos
"Top Right" => position.top_right
"Top Left" => position.top_left
"Bottom Right" => position.bottom_right
"Bottom Left" => position.bottom_left
=> position.top_right
var table panel = table.new(panelPosTV, 3, 5, frame_color = isDark ? #363a45 : #b2b5be, frame_width = 1, border_color = isDark ? #434651 : #c8cbda, border_width = 1)
table.cell(panel, 0, 0, "EDO PDH/PDL", text_color = textCol, bgcolor = headerBg, text_size = panSizeTxt)
table.merge_cells(panel, 0, 0, 2, 0)
table.cell(panel, 0, 1, "D", text_color = showDay ? dayCol : cellTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 1, 1, showDay ? fmt(pdh) : "—", text_color = cellTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 2, 1, showDay ? fmt(pdl) : "—", text_color = cellTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 0, 2, "W", text_color = showWeek ? weekCol : cellTxt, bgcolor = subBg, text_size = panSizeTxt)
table.cell(panel, 1, 2, showWeek ? fmt(pwh) : "—", text_color = cellTxt, bgcolor = subBg, text_size = panSizeTxt)
table.cell(panel, 2, 2, showWeek ? fmt(pwl) : "—", text_color = cellTxt, bgcolor = subBg, text_size = panSizeTxt)
table.cell(panel, 0, 3, "M", text_color = showMonth ? monthCol : cellTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 1, 3, showMonth ? fmt(pmh) : "—", text_color = cellTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 2, 3, showMonth ? fmt(pml) : "—", text_color = cellTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 0, 4, "Y", text_color = showYear ? yearCol : cellTxt, bgcolor = subBg, text_size = panSizeTxt)
table.cell(panel, 1, 4, showYear ? fmt(pyh) : "—", text_color = cellTxt, bgcolor = subBg, text_size = panSizeTxt)
table.cell(panel, 2, 4, showYear ? fmt(pyl) : "—", text_color = cellTxt, bgcolor = subBg, text_size = panSizeTxt)
// ================== ALERTS ==================
alertcondition(crossPDH, "Cross above PDH", "Edo PDH/PDL — Price crossed above previous day high on {{ticker}}")
alertcondition(crossPDL, "Cross below PDL", "Edo PDH/PDL — Price crossed below previous day low on {{ticker}}")
alertcondition(crossPWH, "Cross above PWH", "Edo PDH/PDL — Price crossed above previous week high on {{ticker}}")
alertcondition(crossPWL, "Cross below PWL", "Edo PDH/PDL — Price crossed below previous week low on {{ticker}}")