本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("PDH/PDL/EQ", overlay=true, max_lines_count=100, max_labels_count=100)
// --- Inputs ---
grpG = "Global UI Settings", grpCust = "Previous Custom TF Settings", grpD = "Previous Daily Settings"
showLabels = input.bool(true, "Master Label Switch", group=grpG)
dotOffset = input.int(3, "Dotted Line Margin (Bars)", minval=0, maxval=30, group=grpG)
solidBars = input.int(6, "Solid Tag Length (Bars)", minval=2, maxval=30, group=grpG)
textSizeIn = input.string("Small", "Label Text Size", options=["Tiny", "Small", "Normal", "Large"], group=grpG)
customTf = input.timeframe("240", "Select Custom TF (Default: 4H)", group=grpCust)
showPch = input.bool(false, "", inline="c1", group=grpCust), showLabPch = input.bool(false, "", inline="c1", group=grpCust), txtPch = input.string("PCH", "", inline="c1", group=grpCust), colPch = input.color(color.purple, "", inline="c1", group=grpCust), styPch = input.string("Solid", "", options=["Solid", "Dashed", "Dotted"], inline="c1", group=grpCust), widPch = input.int(1, "", inline="c1", group=grpCust)
showPcl = input.bool(false, "", inline="c2", group=grpCust), showLabPcl = input.bool(false, "", inline="c2", group=grpCust), txtPcl = input.string("PCL", "", inline="c2", group=grpCust), colPcl = input.color(color.purple, "", inline="c2", group=grpCust), styPcl = input.string("Solid", "", options=["Solid", "Dashed", "Dotted"], inline="c2", group=grpCust), widPcl = input.int(1, "", inline="c2", group=grpCust)
showPdh = input.bool(true, "", inline="d1", group=grpD), showLabPdh = input.bool(true, "", inline="d1", group=grpD), txtPdh = input.string("PDH", "", inline="d1", group=grpD), colPdh = input.color(#f23645, "", inline="d1", group=grpD), styPdh = input.string("Solid", "", options=["Solid", "Dashed", "Dotted"], inline="d1", group=grpD), widPdh = input.int(1, "", inline="d1", group=grpD)
showPdl = input.bool(true, "", inline="d2", group=grpD), showLabPdl = input.bool(true, "", inline="d2", group=grpD), txtPdl = input.string("PDL", "", inline="d2", group=grpD), colPdl = input.color(#089981, "", inline="d2", group=grpD), styPdl = input.string("Solid", "", options=["Solid", "Dashed", "Dotted"], inline="d2", group=grpD), widPdl = input.int(1, "", inline="d2", group=grpD)
showPdEq = input.bool(true, "", inline="d3", group=grpD), showLabPdEq = input.bool(true, "", inline="d3", group=grpD), txtPdEq = input.string("EQ", "", inline="d3", group=grpD), colPdEq = input.color(color.gray, "", inline="d3", group=grpD), styPdEq = input.string("Solid", "", options=["Solid", "Dashed", "Dotted"], inline="d3", group=grpD), widPdEq = input.int(1, "", inline="d3", group=grpD)
// --- Helpers & Drawing Engine ---
f_style(s) => s == "Dashed" ? line.style_dashed : s == "Dotted" ? line.style_dotted : line.style_solid
labSz = textSizeIn == "Tiny" ? size.tiny : textSizeIn == "Normal" ? size.normal : textSizeIn == "Large" ? size.large : size.small
f_draw(_ld, _ls, _lb, _shL, _shB, _t1, _y, _txt, _col, _sty, _wid) =>
if _shL and not na(_t1) and not na(_y)
tf_ms = timeframe.in_seconds() * 1000
t_mid = time + tf_ms * dotOffset
t_end = t_mid + tf_ms * solidBars
line.set_xy1(_ld, _t1, _y), line.set_xy2(_ld, t_mid, _y), line.set_color(_ld, _col), line.set_width(_ld, 1), line.set_style(_ld, line.style_dotted)
line.set_xy1(_ls, t_mid, _y), line.set_xy2(_ls, t_end, _y), line.set_color(_ls, _col), line.set_width(_ls, _wid), line.set_style(_ls, f_style(_sty))
if showLabels and _shB
label.set_xy(_lb, t_end, _y), label.set_text(_lb, _txt), label.set_textcolor(_lb, _col), label.set_size(_lb, labSz)
else
label.set_xy(_lb, na, na)
else
line.set_xy1(_ld, na, na), line.set_xy1(_ls, na, na), label.set_xy(_lb, na, na)
// --- Tracking Engine (Exact Candle Anchors) ---
c_time = time(customTf)
newCustom = not na(c_time) and (ta.change(c_time) != 0 or barstate.isfirst)
newDay = ta.change(time("D")) != 0 or barstate.isfirst
var float cur_ch = na, var int cur_ch_t = na, var float cur_cl = na, var int cur_cl_t = na
var float pc_h = na, var int pc_h_t = na, var float pc_l = na, var int pc_l_t = na
if newCustom
pc_h := cur_ch, pc_h_t := cur_ch_t, pc_l := cur_cl, pc_l_t := cur_cl_t
cur_ch := high, cur_ch_t := time, cur_cl := low, cur_cl_t := time
else
if high > cur_ch or na(cur_ch)
cur_ch := high, cur_ch_t := time
if low < cur_cl or na(cur_cl)
cur_cl := low, cur_cl_t := time
var float cur_do = na, var float cur_dh = na, var int cur_dh_t = na, var float cur_dl = na, var int cur_dl_t = na
var float pd_o = na, var float pd_h = na, var int pd_h_t = na, var float pd_l = na, var int pd_l_t = na
var float pd_c = na, var int d_anc = na
if newDay
pd_o := cur_do, pd_h := cur_dh, pd_h_t := cur_dh_t, pd_l := cur_dl, pd_l_t := cur_dl_t, pd_c := close[1], d_anc := time
cur_do := open, cur_dh := high, cur_dh_t := time, cur_dl := low, cur_dl_t := time
else
if high > cur_dh or na(cur_dh)
cur_dh := high, cur_dh_t := time
if low < cur_dl or na(cur_dl)
cur_dl := low, cur_dl_t := time
float pd_eq = not na(pd_c) and not na(pd_o) ? (pd_c >= pd_o ? (pd_c + pd_l) / 2.0 : (pd_c + pd_h) / 2.0) : na
// --- Objects & Render ---
var line pchD = line.new(na, na, na, na, xloc=xloc.bar_time), var line pchS = line.new(na, na, na, na, xloc=xloc.bar_time), var label pchB = label.new(na, na, "", xloc=xloc.bar_time, color=color.new(color.white, 100), style=label.style_label_lower_right)
var line pclD = line.new(na, na, na, na, xloc=xloc.bar_time), var line pclS = line.new(na, na, na, na, xloc=xloc.bar_time), var label pclB = label.new(na, na, "", xloc=xloc.bar_time, color=color.new(color.white, 100), style=label.style_label_lower_right)
var line pdhD = line.new(na, na, na, na, xloc=xloc.bar_time), var line pdhS = line.new(na, na, na, na, xloc=xloc.bar_time), var label pdhB = label.new(na, na, "", xloc=xloc.bar_time, color=color.new(color.white, 100), style=label.style_label_lower_right)
var line pdlD = line.new(na, na, na, na, xloc=xloc.bar_time), var line pdlS = line.new(na, na, na, na, xloc=xloc.bar_time), var label pdlB = label.new(na, na, "", xloc=xloc.bar_time, color=color.new(color.white, 100), style=label.style_label_lower_right)
var line pdeD = line.new(na, na, na, na, xloc=xloc.bar_time), var line pdeS = line.new(na, na, na, na, xloc=xloc.bar_time), var label pdeB = label.new(na, na, "", xloc=xloc.bar_time, color=color.new(color.white, 100), style=label.style_label_lower_right)
if barstate.islast
f_draw(pchD, pchS, pchB, showPch, showLabPch, pc_h_t, pc_h, txtPch, colPch, styPch, widPch)
f_draw(pclD, pclS, pclB, showPcl, showLabPcl, pc_l_t, pc_l, txtPcl, colPcl, styPcl, widPcl)
f_draw(pdhD, pdhS, pdhB, showPdh, showLabPdh, pd_h_t, pd_h, txtPdh, colPdh, styPdh, widPdh)
f_draw(pdlD, pdlS, pdlB, showPdl, showLabPdl, pd_l_t, pd_l, txtPdl, colPdl, styPdl, widPdl)
f_draw(pdeD, pdeS, pdeB, showPdEq, showLabPdEq, d_anc, pd_eq, txtPdEq, colPdEq, styPdEq, widPdEq)