'Pine: how to use label.new for a specific chart (when plotting the chart and an indicator below)
I would like to plot the index of the last bar ("5830", see screenshot below) on the prices chart instead of on the CCI chart.
Here is my code so far:
//@version=5
indicator("Mon script", overlay=false)
// CCI
cciSource = input.source(close, "Source CCI")
cci=ta.cci(close, 20)
plot(bar_index % 2 ? na: 100, color=color.gray, style=plot.style_linebr)
plot(bar_index % 2 ? na: -100, color=color.gray, style=plot.style_linebr)
plot(cci, title="CCI",color=color.fuchsia)
if (barstate.islast)
label.new(bar_index, open, str.tostring(bar_index, format.mintick), yloc = yloc.belowbar, style = label.style_none, textcolor = color.black, size = size.normal)
Any idea on how to do this ?
Best regards
Solution 1:[1]
You already used label, so change the indicator properties to overlay=true
//@version=5
indicator("Mon script", overlay=true)
// CCI
cciSource = input.source(close, "Source CCI")
cci=ta.cci(close, 20)
if (barstate.islast)
label.new(bar_index, low, str.tostring(bar_index, format.mintick), yloc = yloc.belowbar, style = label.style_label_up, textcolor = color.white, size = size.normal)
Also, you can make it as table
//@version=5
indicator("Mon script", overlay=true)
// CCI
cciSource = input.source(close, "Source CCI")
cci=ta.cci(close, 20)
var table table1 = na
var table2 = table.new(position.top_left, na, na)
if barstate.islastconfirmedhistory
var table3 = table.new(position = position.top_right, columns = 1, rows = 1, bgcolor = color.yellow, border_width = 1)
table.cell(table_id = table3, column = 0, row = 0, text = str.tostring(bar_index, format.mintick))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mazen Abduallah |

