Reputation: 3
I'm trying to plot previous day's high/low, here's the code:
//@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])
This plots the lines starting from the opening of the new day. What I'd like to be able to do is start the lines from the exact points where the high/low was created(for better reference) and extend till the current bar.
Upvotes: 0
Views: 52
Reputation: 21342
You cannot do that with the security()
function. You need to keep track of the prices and their bar indices yourself.
Here is an example for the high
price:
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
Upvotes: 1