我想在图表的右上角显示(当前报价的)最新的“每日ATR值”,但是找不到一种方法来操纵标签对象来执行此操作...是这可能吗?
答案 0 :(得分:1)
请参阅此处。该解决方案必须在单独的代码中运行,因为它使用与图表符号不同的比例来将值保持在顶部:http://www.pinecoders.com/faq_and_code/#how-can-i-print-a-value-at-the-top-right-of-the-chart
//@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))