RVK
RVK

Reputation: 1

How to display text in the top-right side of the chart

I would like to display the most recent 'Daily ATR value' (of the current ticker) in the top right hand site of chart, but can't find a way to manipulate a label object to do this... Is this possible?

Upvotes: 0

Views: 9090

Answers (2)

Dang Nguyen
Dang Nguyen

Reputation: 11

You can use table to display the value:

var tb = table.new(position.top_right, 1, 1, bgcolor = #1e222d, border_color = #373a46, border_width = 1, frame_color = #373a46, frame_width = 1)

tb.cell(0, 0, 'Your text here', text_color = color.white, text_size = size.large)

Upvotes: 1

PineCoders-LucF
PineCoders-LucF

Reputation: 8789

See here. The solution must run in separate code because it uses a different scale than the chart's symbol to keep the value at the top:

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

Upvotes: 4

Related Questions