I’m a novice to pine script who need some help figuring this puzzle out.
The text is not showing in the horizontal line. I tried label.style_label_center
and other lot of stuff, but nothing seems to work. Any help would be appreciated. Thank you!
my script output
expected output
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © cryptoweeknd
//@version=5
indicator ("Option Levels", overlay=true)
// Input Parameters
timeframeInput = input.timeframe("D", "", group='ADR', inline="A1")
labels_enabled = true
blue = color.blue
draw_line(_x1, _y1, _x2, _y2, _xloc, _extend, _color, _style, _width) =>
dline = line.new(x1=_x1, y1=_y1, x2=_x2, y2=_y2, xloc=_xloc, extend=_extend, color=_color, style=_style, width=_width)
line.delete(dline[1])
draw_label(_x, _y, _text, _color, _style, _textcolor, _size, _textalign) =>
dlabel = label.new(x=_x, y=_y, text=_text, color=_color, style=_style, textcolor=_textcolor, size=_size, textalign=_textalign)
label.delete(dlabel[1])
[h_high, h_low, h_close] = request.security(syminfo.tickerid, timeframeInput, [high, low, close])
showCPRInput = input(true, "", group='CPR', inline="D2")
var color_TC = input.color(defval=color.new(blue, 0), title='TC', group='CPR', inline="D2")
notHigherTimeframe = timeframe.period != '30' and timeframe.period != '45' and timeframe.period != '60' and timeframe.period != '120' and timeframe.period != '180' and timeframe.period != '240' and timeframe.period != 'D' and timeframe.period != 'W' and timeframe.period != 'M'
calculatePivot(high, low, close) =>
(high + low + close) / 3
calculateBC(high, low) =>
(high + low) / 2
calculateTC(pivot, bc) =>
pivot - bc + pivot
truncate(number, decimals) =>
factor = math.pow(10, decimals)
int(number * factor) / factor
//round(number * 10) / 10
pivot = calculatePivot(h_high, h_low, h_close)
bc = calculateBC(h_high, h_low)
tc = calculateTC(pivot, bc)
// Ensure TC is always above BC
if tc < bc
temp = tc
tc := bc
bc := temp
plot(showCPRInput ? truncate(tc, 2) : na, title='TC', color=color.new(color_TC, pivot[1] != pivot and notHigherTimeframe ? 100 : 0), style=plot.style_line, linewidth=2)
if labels_enabled
draw_label(bar_index, showCPRInput ? truncate(tc, 2) : na, 'TC', color.new(color_TC, 100), label.style_label_left, color_TC, size.normal, text.align_left)