0

I am working thru my first script using Pine and came across a spot I have been struggling on for 2 hours.

All I am trying to do is show 'strValueBarAverage' above the current bar. After the bar has closed and moved onto the newest bar, I would like the original to be deleted and the newest bar to again have the 'strValueBarAverage' value above it. Right now, it is just layering each Bar's data above, making it unreadable. Code below and thank you.

if barstate.isrealtime and barstate.islast
myLabel = label.new(x=bar_index, y=close, color=color.orange, textcolor=color.white, style=label.style_circle)
label.set_text(id=myLabel, text=strValueBarAverage)
if not(barstate.islast)
    label.delete(myLabel)

1 Answers1

2

Then you don't need all those checks at all. Create the label and delete the previous one.

myLabel = label.new(x=bar_index, y=close, color=color.orange, text=strValueBarAverage, textcolor=color.white, style=label.style_circle)
label.delete(myLabel[1])
vitruvius
  • 15,740
  • 3
  • 16
  • 26
  • Ohhh that is brilliant... I didn't know they were being indexed... That is awesome! Thank you! – John OConnor Nov 23 '22 at 20:51
  • Pretty much everything has history in pinescript. You can access the historical values with the [History reference operator](https://www.tradingview.com/pine-script-docs/en/v4/language/Operators.html#history-reference-operator) – vitruvius Nov 23 '22 at 22:55