I'm trying to code a script that draws a line from a starting candle to another candle if some conditions are meet. If more candles meet the condition another line from the starting candle will be drawn, just like a "fan of lines" from the starting candle.
Example image There is already a solution with answer to this question here How to draw a fan in Pine v5? Lines connecting open/close in a range?
My question is that I want to do this not just on the starting candle but for all subsequent candles after this. Is this possible?
I have tried to increase the start_index from the example given by just increasing it with
start_index := bar_index-start_index+1
Full code below
t0 = input.time(timestamp("20 Jul 2021 00:00 +0300"), confirm = true) //Range Start
t1 = input.time(timestamp("20 Jul 2021 00:00 +0300"), confirm = true) //Range End
plot(t0, "t0")
plot(t1, "t1")
first_bar = time >= t0 and time[1] < t0
in_range = time > t0 and time <= t1
post_bar = time > t1 and time[1] <= t1
var float start_high = na
var int start_index = na
var float start_BodyHigh = na
if first_bar
start_high := high
start_index := bar_index //Gets the first bar_index number
start_BodyHigh := math.max(open[bar_index-start_index], close[bar_index-start_index])
plot(start_high, "start_high")
plot(start_index, "start_index")
plot(start_BodyHigh, "start_BodyHigh")
//Find highest from start_index to actual bar_index
//highest_in_range = ta.highest(high, bar_index-start_index)
var float highest_in_range = na
if high < start_high and high > high[1]
highest_in_range := high
plot(highest_in_range, "highest_in_range")
if in_range and not first_bar and high < high[bar_index-start_index] and high > start_BodyHigh
line.new(x1 = start_index, y1 = start_high, x2 = bar_index[1], y2 = high[1], color = color.white, style = line.style_dotted, width = 1)
if post_bar
num_bars = bar_index[1] - start_index
delta = close[1] - start_high
info_text = "Start Bar : " + str.tostring(start_index) + "\nEnd Bar : " + str.tostring(bar_index[1]) + "\nNumber of bars : " + str.tostring(num_bars) + "\nPrice delta : " + str.tostring(delta)
label.new(x = bar_index[1], y = high[1], style = label.style_label_lower_left, size = size.small, text = info_text)
start_index := bar_index-start_index+1
start_high := high[bar_index-start_index]