first_red_bar_index = ta.barssince(close < open)[1] + 1 second_red_bar_index = ta.barssince(close < open)[first_red_bar_index+ 1] + first_red_bar_index + 1 first_green_bar_index = ta.barssince(close > open)[1] + 1 second_green_bar_index = ta.barssince(close > open)[first_green_bar_index + 1] + first_green_bar_index + 1 x = bar_index y = high // txt1 = str.tostring(second_red_bar_index) // label.new(x, y, txt1, color = color.white, textcolor = color.black, size = size.large) txt2 = str.tostring(second_green_bar_index) label.new(x, y, txt2, color = color.yellow, textcolor = color.black, size = size.large) HHV = ta.highest(high, second_red_bar_index)[1] LLV = ta.lowest(low, second_green_bar_index)[1] sell = low < LLV buy = high > HHVplotshape(sell, title = 'Sell', text = "SELL" , textcolor=color.black, style=shape.triangledown, location=location.abovebar, size= size.normal, color=color.black)plotshape(buy, title = 'Buy', text="BUY", textcolor=color.black, style=shape.triangleup, location=location.belowbar, size= size.normal, color=color.black)
I'm expecting a label on every bar. However, on some bars there is no label. How can I fix this?