I'm trying to delete a line on condition after it has been plotted.
So Im going through 2 steps;
Plot lines ONLY in the last X bars
Delete lines if a condition is met.
For the second case, it is not detecting any lines on the chart, I'm trying to put up a label everytime a line has been found however the labels do not plot. Here is what I've tried so far:
//@version=4
study(title='Testing', overlay=true, max_lines_count=30)
showLines = input(title="Show Lines ?", type=input.bool, defval=true)
if showLines == true and barstate.islast
line bullLine1 = na //bull line
BARS_BACK = 20
//Loop to plot a line
for i = BARS_BACK to 0
bullishcase = close[i+1] > high[i+2]
if bullishcase
bullLine1 := line.new(x1=bar_index[i + 2], y1=high[i + 2], x2=bar_index[i], y2=high[i + 2], extend=extend.right, color=color.blue)
//Loop to delete a line
for i = BARS_BACK to 0
if not na(bullLine1[i])
label.new(bar_index[i], high[i], "Line 1 found" )
I tried another approach to this issue by using this solution: How to delete a line when price breaks it in pine script? However, it works most of the times but sometimes it gives me the error "too many drawings. cannot clean the oldest". I'm not sure how I can go about that
question from:https://stackoverflow.com/questions/65649754/tradingview-delete-line-on-condition