The situation is as follows:
does not draw:
T_to = timestamp(year + 1, 3, 1, 0, 0)
does not draw:
T_to = timestamp(year, 12, 31, 0, 0) // ? current 2024 December = 31 с. day
draws:
T_to = timestamp(year, 12, 30, 0, 0)
code :
//@version=5
indicator("Q time high/low fix", overlay=true )
// Bar counter in period
var int count_bar = na
// for high and low
var float high_in_period = na
var float low_in_period = na
// Quarter period: from December 1 of the current year to March 31 of the next year
T_from = timestamp(year, 12, 1, 0, 0) // Time from [t...]
T_to = timestamp(year +1, 3, 1, 0, 0) // Time to [...t]. Correct end of March next year
// Debug marks for checking values
if (time == T_to) // ???
label.new(bar_index, high, "Time: " + str.tostring(time) + "nDate: " + str.format("{0}-{1}-{2}", year(time), month(time), dayofmonth(time)), color=color.yellow, style=label.style_label_down)
// If the current bar falls within the period
if (time >= T_from and time <= T_to)
// Initializing values on the first bar of the period
if na(count_bar)
count_bar := 0
high_in_period := high
low_in_period := low
// Increasing the bar counter
count_bar += 1
// Updating high and low
high_in_period := math.max(high_in_period, high)
low_in_period := math.min(low_in_period, low)
// After the period ends, we draw lines and reset the counters
if (time > T_to and not na(count_bar))
// lines high and low
line.new(x1=T_from, y1=high_in_period, x2=T_to, y2=high_in_period, color=color.green, width=2, xloc=xloc.bar_time)
line.new(x1=T_from, y1=low_in_period, x2=T_to, y2=low_in_period, color=color.red, width=2, xloc=xloc.bar_time)
// Reset the counters
count_bar := na
high_in_period := na
low_in_period := na
// END
I noticed that bars from January 1 to the required date are not taken into account for analysis in the code.
How to draw high and low lines in a given time range
with the transition to the new year (year+1) ?