'how can i extend the box in pinescript till the market tuches it and then after that replot it

I am working on an indicator in which i want to extend the box to the right and when the market touches it again. Then close the box an replot when my given conditions are met.

if buy_2
buy_2_box = 
     box.new(
     left   = bar_index[1],
     top    = close[1] > open[1] ? close[1] : open[1],
     right  = bar_index[1] + number_of_bars,
     bottom = close[1] > open[1] ? close[1] : open[1] ,
     border_color = color.new(color.aqua , 30)
     )


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source