how to delete lines drawn once price has touched it

66 Views Asked by At

I am creating an indicator for trading view which marks out the 50% and 80% of a candle body and draws a horizontal line from there.

Currently, the indicator displays the lines correctly.

I am now trying to get the indicator to automatically delete the line once price has touched it in the future.

I am unable to do this.

I have created a couple indicators just by learning online what different code does.

I tried doing an if statement where it deletes the line once price has either equal to or greater than the line. The problem I faced with this is that it causes all of the lines to get deleted instead of that specific line.

regularSessionTicker = ticker.new(syminfo.prefix, syminfo.ticker, session.regular)
haTicker = ticker.standard(regularSessionTicker)


candleOpen = (request.security(haTicker, "240", open, gaps = barmerge.gaps_on))
candleClose = (request.security(haTicker, "240", close, gaps = barmerge.gaps_on))


bullOrders = candleOpen<candleClose

bearOrders = candleOpen>candleClose

bullIndex = ta.valuewhen(bullOrders, bar_index, 0)

bearIndex = ta.valuewhen(bearOrders, bar_index, 0)


bullBodySize = 0.0
bull50 = 0.0
bull80 = 0.0

if candleOpen<candleClose
    bullBodySize := math.abs(close-open)
    bull50 := (candleOpen + (0.5*bullBodySize))
    bull80 := (candleOpen + (0.2*bullBodySize))
   

bull50line = line.new(bullIndex, bull50, bullIndex+1, bull50, color = color.green, extend = extend.right)
bull80line = line.new(bullIndex, bull80, bullIndex+1, bull80, color = color.green, extend = extend.right)


bearBodySize = 0.0
bear50 = 0.0
bear80 = 0.0


if candleOpen>candleClose
    bearBodySize := math.abs(open-close)
    bear50 := (candleOpen - (0.5*bearBodySize))
    bear80 := (candleOpen - (0.2*bearBodySize))

bear50line = line.new(bearIndex, bear50, bearIndex+1, bear50, color= color.red, extend = extend.right)
bear80line = line.new(bearIndex, bear80, bearIndex+1, bear80, color= color.red, extend = extend.right)
0

There are 0 best solutions below