我正在尝试绘制前一天的高点/低点,这是代码:
//@version=5
indicator('PDHL', overlay=true)
show_pdhl = input(true, 'Show Previous Day High/Low')
[_from, p_high, p_low, p_mid, c_open] = request.security(syminfo.tickerid, 'D', [time, high[1], low[1], hl2[1], open], lookahead = barmerge.lookahead_on)
if show_pdhl
p_high_line = line.new(_from, p_high, time, p_high, xloc.bar_time, color=color.red)
line.delete(p_high_line[1])
p_high_label = label.new(bar_index, p_high, style=label.style_label_left, size=size.small, color=#ffffff, text='PDH', textcolor=color.red)
label.delete(p_high_label[1])
p_low_line = line.new(_from, p_low, time, p_low, xloc.bar_time, color=color.green)
line.delete(p_low_line[1])
p_low_label = label.new(bar_index, p_low, style=label.style_label_left, size=size.small, color=#ffffff, text='PDL', textcolor=color.green)
label.delete(p_low_label[1])
这绘制了从新一天开盘开始的线条。我想要做的是从创建高/低点的确切点开始绘制线条(为了更好的参考)并延伸到当前柱。
您无法使用
security()
功能来做到这一点。您需要自己跟踪价格及其条形指数。
以下是
high
价格的示例:
var prev_day_high = high
var prev_day_high_idx = bar_index
var prev_day_high_line = line.new(na, na, na, na)
var day_high = high
var day_high_idx = bar_index
is_new_day = ta.change(time("D"))
if (is_new_day)
prev_day_high := day_high
prev_day_high_idx := day_high_idx
// Create your lines here
day_high := high
day_high_idx := bar_index
else
// Update your lines' x2 here so they would extend to the current bar
if (high > day_high)
day_high := high
day_high_idx := bar_index