So I’m basically building a custom indicator and trying to retrieve the time the previous daily high was made.
I’m using:
PDH = request.security(syminfo.tickerid, ‘D’, high[1])
To retrieve the previous daily high price but is it possible to retrieve the time the high was made?
Would greatly appreciate any help with this, been bugging me for hours!
Many thanks in advance!
You can use the below function to convert time
to a date-time string.
f_timeToString(_t) =>
str.tostring(year(_t), "0000") + "." + str.tostring(month(_t), "00") + "." + str.tostring(dayofmonth(_t), "00") + " " +
str.tostring(hour(_t), "00") + ":" + str.tostring(minute(_t), "00") + ":" + str.tostring(second(_t), "00")
To get the time and value, I would simply use var
variables. Update them when it is a new day or if there is a new high.
//@version=5
indicator("My script", overlay=true, max_labels_count = 500)
f_timeToString(_t) =>
str.tostring(year(_t), "0000") + "." + str.tostring(month(_t), "00") + "." + str.tostring(dayofmonth(_t), "00") + " " +
str.tostring(hour(_t), "00") + ":" + str.tostring(minute(_t), "00") + ":" + str.tostring(second(_t), "00")
var int daily_high_time = na
var int prev_daily_high_time = na
var float daily_high = na
var float prev_daily_high = na
is_new_day = ta.change(time("D"))
prev_daily_high_time := is_new_day ? daily_high_time : prev_daily_high_time
prev_daily_high := is_new_day ? daily_high : prev_daily_high
daily_high_time := is_new_day ? time : (high > daily_high) ? time : daily_high_time
daily_high := is_new_day ? high : (high > daily_high) ? high : daily_high
if (is_new_day)
s = "Daily High: " + str.tostring(prev_daily_high) + "\nTime:\n" + f_timeToString(prev_daily_high_time)
label.new(prev_daily_high_time, prev_daily_high, s, xloc=xloc.bar_time)
bgcolor(is_new_day ? color.new(color.blue, 85) : na)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments