Pine:如何对特定图表使用 label.new(绘制图表和下方指标时)

Pine: how to use label.new for a specific chart (when plotting the chart and an indicator below)

我想在价格图表而不是 CCI 图表上绘制最后一根柱线的指数(“5830”,见下面的截图)。

到目前为止,这是我的代码:

//@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)

知道怎么做吗?

此致

您已经使用了标签,因此将指标属性更改为 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)

此外,您可以将其设置为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))