'Unable to modify label text in the past for a simple Pine Script
I'm trying to modify the text for labels already plotted on the chart, but I'm not able to. Example: in this Pivot script I want to change the black check mark symbol to a red X when price moves above the high of the Pivot Candle. Meaning that all Pivot Candles whose highs are lower than current price should be red Xs. In this image the red circles represent what should be red Xs, while the green circles are right as they are. Thank you in advance!
//@version=4
study("change labels in the past", overlay=true)
// Pivot definition
highPiv = pivothigh(high, 2, 2)
barcolor(highPiv ? color.blue : na, offset=-2)
// If price at the current time is higher than any High Pivot, change the Pivot Icon to a red X (oonly the ones currently under the price line)
HighVal = valuewhen(highPiv, high[2], 0)
priceOverHigh = close > HighVal
if highPiv
a=label.new(bar_index[2], close[2], text="✔️", style=label.style_label_down, color=color.new(color.black, 100), size=size.normal)
if priceOverHigh
label.set_text(id=a, text="❌")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
