如何在图表的右上角显示文本



我想在图表的右上角显示最新的"每日 ATR 值"(当前股票代码(,但找不到操纵标签对象来执行此操作的方法......这可能吗?

看这里。该解决方案必须在单独的代码中运行,因为它使用与图表符号不同的比例来保持值位于顶部:

//@version=4
//@author=LucF, for PineCoders
// Indicator needs to be on "no scale".
study("", "Daily ATR", true, scale = scale.none)
atrLength = input(14)
barsRight = input(5)
// Adjust the conversion formatting string to the instrument: e.g., "#.########" for crypto.
numberFormat = input("#.####")
// Plot invisible value to give a large upper scale to indie space.
plotchar(10e10, "", "")
// Fetch daily ATR. We want the current daily value so we use a repainting security() call.
dAtr = security(syminfo.tickerid, "D", atr(atrLength), lookahead = barmerge.lookahead_on)
// Label-creating function puts label at the top of the large scale.
f_print(_txt) => var _lbl = label(na), label.delete(_lbl), _lbl := label.new(time + (time-time[1]) * barsRight, 10e10, _txt, xloc.bar_time, yloc.price, size = size.normal)
// Print value on last bar only, so code runs faster.
if barstate.islast
f_print(tostring(dAtr, numberFormat))

最新更新