Reputation: 3
I borrowed code from an open source script. It draws pivot high/low trendlines. I also want it to draw horizontal support/resistances from each pivot but im not sure how its done.
I tried a few possibilities but because line.new() doesn't have offset or show_last, i couldn't fix my problem.
problem/solution: the x2 needs to be set after the pivot but bar_index[-1] is not possible
some bad outcomes I had: (1)the line is draw from the previous bar behind the pivot. (2) the line is drawn after 20 bars when the pivot is confirmed. (3) the lines are drawn except on the most recent pivot.
here is the code. top3 is the pivot high variable. The first if statement is what i wrote. The second if statement near the end is for diagonal trendlines
ltop3 = valuewhen(top3, top3, 1)
bst3 = 0
bst3 := top3 ? 1 : nz(bst3[1]) + 1
float t_angle3 = 0.0
t_angle3 := t_angle3[1]
if not na(ltop3) and not na(top3)
line tline = na
line hline = na
dt = time - time[1]
if top3
hline := line.new(bar_index - bst3 - rb3, high[bst3 + rb3], bar_index - rb3, high[bst3 + rb3], color = color.purple, extend = extend.right)
if ltop3 > top3
tline := line.new(bar_index - bst3[1] - rb3, high[bst3[1] + rb3], bar_index - rb3, high[rb3], color = color.red, extend = extend.right)
Upvotes: 0
Views: 849
Reputation: 3
Fixed. I set the y1 and y2 as pivot high and the x1 is 25 bars back offset so that is start from the pivot high
if top3
hline := line.new(bar_index[25], top3, bar_index, top3, color = color.purple, extend = extend.right)
Upvotes: 0