Pine script Array unable to delete previous label and text is displaying on top of each other, script plots text on break of bollinger

//@version=5enter code here`indicator(“Clean”, overlay=true)

enter code hereshowlast = input(defval=false, title=”Show only Last Label”)

enter code hereshowsignals = input.string(defval=”Full”, title=”Show Signal Names”, enter code hereoptions=[‘Full’, ‘Length’])

enter code herelen3= input.int(50, minval=1, title=”Ma Length 1″)
enter code herelen4= input.int(100, minval=1, title=”Ma Length 2″)
enter code herelen5= input.int(200, minval=1, title=”Ma Length 3″)
enter code herelen6= input.int(200, minval=1, title=”Ma Length 4″)

enter code hereout3 = ta.sma(close, len3)
enter code hereout4 = ta.sma(close, len4)
enter code hereout5 = ta.sma(close, len5)
enter code hereout6 = ta.sma(close, len6)

enter code here// BB Multiplier 3
enter code hereBB_sdev31 = input.float(3, minval=0.001, maxval=50, title=”BB Multiplier”)
enter code here// BB Multiplier for 200 2nd deviation
enter code hereBB_sdev32 = input.float(4, minval=0.001, maxval=50, title=”BB Multiplier”) enter code here200 2nd Dev”)

enter code heredev33 = BB_sdev31 * ta.stdev(close, len3)
enter code heredev34 = BB_sdev31 * ta.stdev(close, len4) enter code heredev35 = BB_sdev31 * ta.stdev(close, len5)
enter code heredev36 = BB_sdev32 * ta.stdev(close, len6)

enter code here// Bollinger Length 3 50 sma

enter code hereupper6 = ta.sma(close, len3) + dev33
enter code herelower6 = ta.sma(close, len3) – dev33

enter code herep11 = plot(upper6, title=”BB Upper 1″, color=#0000ff)
enter code herep12 = plot(lower6, title=”BB Lower 1″, color=#0000ff)

enter code here// Bollinger Length 4 100 sma

enter code hereupper8 = ta.sma(close, len4) + dev34
enter code herelower8 = ta.sma(close, len4) – dev34

enter code herep15 = plot(upper8, title=”BB Upper 2″, color=#FFFF00)
enter code herep16 = plot(lower8, title=”BB Lower 2″, color=#FFFF00)

enter code here// Bollinger Length 5 200 sma

enter code hereupper10 = ta.sma(close, len5) + dev35
enter code herelower10 = ta.sma(close, len5) – dev35

enter code herep19 = plot(upper10, title=”BB Upper 3″, color=#800080)
enter code herep20 = plot(lower10, title=”BB Lower 3″, color=#800080)

enter code here// Bollinger length 6 200 sma dev 4 +

enter code hereupper11 = ta.sma(close, len6) + dev36
enter code herelower11 = ta.sma(close, len6) – dev36

enter code herep21 = plot(upper11, title=”BB Upper 4 2nd dev”, color=#ff00ff)
enter code herep22 = plot(lower11, title=”BB Lower 4 2nd dev”, color=#ff00ff)

enter code here// color definitions
enter code herebuySignal1_col = input(defval=color.green, title=”BB Lower 200″)
enter code hereshortSignal1_col = input(defval=color.red, title=” BB Upper 200″)

enter code herehundred_col = input(defval=color.yellow, title=”BB Lower 100″)

enter code herefifty_col = input(defval=color.blue, title=”BB Lower 50″)

enter code here// label and color array

enter code heresignal_lbl = array.new_label(6)
enter code herelabel_col = input(defval=color.gray, title=”Label”)

enter code herecolorarray = array.new_color(4)
enter code herearray.set(colorarray, 0, buySignal1_col)
enter code herearray.set(colorarray, 1, shortSignal1_col)
enter code herearray.set(colorarray, 2, hundred_col)
enter code herearray.set(colorarray, 3, fifty_col)
enter code here//Bollinger cross exp

enter code herebuySignal1 = low <= lower10 and close >= lower10 //200
enter code hereshortSignal1 = high >= upper10 and close <= upper10 //200

enter code herebuySignal2 = low <= lower8 and close >= lower8 // 100
enter code hereshortSignal2 = high >= upper8 and close <= upper8 //100

enter code herebuySignal3 = low <= lower6 and close >= lower6 //50
enter code hereshortSignal3 = high >= upper6 and close <= upper6 //50 enter code here//100 and 50
enter code herebuySignal4 = low <= lower6 and low <= lower8 and close >= lower6
enter code hereshortSignal4 = high >= upper6 and high >= upper8 and close <= upper6 enter code here//200 and 100
enter code herebuySignal5 = low <= lower8 and low <= lower10 and close >= lower8
enter code hereshortSignal5 = high >= upper8 and high >= upper10 and close <= upper8 enter code here//price below all
enter code herebuySignal6 = low <= lower6 and low <= lower8 and low <= lower10 and close enter code here>= lower6
enter code hereshortSignal6 = high >= upper6 and high >= upper8 and high >= upper10 and enter code hereclose <= upper6

enter code here// adding to lbl array

enter code hereif buySignal1 ? close : na

`enter code here`array.insert(signal_lbl, 0, label.new(x=bar_index[1], y=math.min(low, `enter code here`low[1]), text="200", color=color.new(label_col, 100), `enter code here`textcolor=color.new(buySignal1_col,50), style=label.style_label_up))

enter code hereif shortSignal1 ? close : na
enter code here array.set(signal_lbl, 1, label.new(x=bar_index .)[1]y=math.min(high, enter code herehigh[1]) , text=”200″, color=color.new(label_col, 100), enter code heretextcolor=color.new(shortSignal1_col,50), style=label.style_label_down))

enter code hereif buySignal2 ? close : na
enter code here array.set(signal_lbl, 2, label.new(x=bar_index .)[1]y=math.min(low, enter code herelow[1]) , text=”100″, color=color.new(label_col, 100), enter code heretextcolor=color.new(hundred_col,50), style=label.style_label_up))

enter code hereif shortSignal2 ? close : na and shortSignal3 ? close : na
enter code here array.set(signal_lbl, 3, label.new(x=bar_index, y=math.min(high, enter code herehigh[1]) , text=”100″, color=color.new(label_col, 100), enter code heretextcolor=color.new(hundred_col,50), style=label.style_label_down))

enter code hereif buySignal3 ? close : na
enter code here array.set(signal_lbl, 4, label.new(x=bar_index .)[1]y=math.min(low, enter code herelow[1]) , text=”50″, color=color.new(label_col, 100), enter code heretextcolor=color.new(fifty_col,50), style=label.style_label_up))

enter code hereif shortSignal3 ? close: na
enter code herearray.set(signal_lbl, 5, label.new(x=bar_index, y=math.min(high, enter code herehigh[1]) , text=”50″, color=color.new(label_col, 100), enter code heretextcolor=color.new(fifty_col,50), style=label.style_label_down))

Leave a Comment