Trying to move labels right side along with the plot lines movement without adding Input Tab (also on all previous days). So, we can see the which line is crossed the candle. I looked for the solution but, only found posts fixing those who are used drawlabel() function for labels. Didn't find post for plotchar().
I tried offset but it will set only for a particular timeframe. Say, when we set offset on a 5minute timeframe and we change the chart timeframe to 10minute, all the labels will mess up.
If we can't fix moving along with line, atleast need to fix to right side.
If anyone can guide me in the right direction that would be great.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pbghosh
//@version=5
indicator(title='Daily CPR', shorttitle='D-CPR', overlay=true, format=format.price, precision=2)
h = request.security(syminfo.tickerid, 'D', high[1], lookahead=barmerge.lookahead_on)
l = request.security(syminfo.tickerid, 'D', low[1], lookahead=barmerge.lookahead_on)
c = request.security(syminfo.tickerid, 'D', close[1], lookahead=barmerge.lookahead_on)
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() =>
(h + l + c) / 3
calculateBC() =>
(h + l) / 2
calculateTC() =>
calculatePivot() - calculateBC() + calculatePivot()
truncate(number, decimals) =>
factor = math.pow(10, decimals)
int(number * factor) / factor
//round(number * 10) / 10
pivot = calculatePivot()
tc = calculateTC()
bc = calculateBC()
if tc < bc
t = tc
tc := bc
bc := t
bc
r1Level = truncate(2 * pivot - l, 2)
r2Level = truncate(pivot + h - l, 2)
r3Level = truncate(h + 2 * (pivot - l), 2)
r4Level = truncate(h + 3 * (pivot - l), 2)
r5Level = truncate(h + 4 * (pivot - l), 2)
s1Level = truncate(2 * pivot - h, 2)
s2Level = truncate(pivot - (h - l), 2)
s3Level = truncate(l - 2 * (h - pivot), 2)
s4Level = truncate(l - 3 * (h - pivot), 2)
s5Level = truncate(l - 4 * (h - pivot), 2)
plot(series=notHigherTimeframe ? truncate(tc, 2) : na, title='TC', color=pivot[1] != pivot and notHigherTimeframe ? na : color.blue, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")?truncate(tc, 2):na, title='TC Label', color=color.blue, location=location.absolute, text="TC")
plot(series=notHigherTimeframe ? truncate(pivot, 2) : na, title='CP', color=pivot[1] != pivot and notHigherTimeframe ? na : color.fuchsia, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")?truncate(pivot, 2):na, title='CP Label', color=color.fuchsia, location=location.absolute, text="CP")
plot(series=notHigherTimeframe ? truncate(bc, 2) : na, title='BC', color=pivot[1] != pivot and notHigherTimeframe ? na : color.blue, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")?truncate(bc, 2):na, title='BC Label', color=color.blue, location=location.absolute, text="BC")
plot(series=notHigherTimeframe ? r1Level : na, title='R1', color=pivot[1] != pivot and notHigherTimeframe ? na : #FF4000, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")? r1Level :na, title='R1 Label', color=#FF4000, location=location.absolute, text="R1")
plot(series=notHigherTimeframe ? r2Level : na, title='R2', color=pivot[1] != pivot and notHigherTimeframe ? na : #FF4000, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")? r2Level :na, title='R2 Label', color=#FF4000, location=location.absolute, text="R2")
plot(series=notHigherTimeframe ? r3Level : na, title='R3', color=pivot[1] != pivot and notHigherTimeframe ? na : #FF4000, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")? r3Level :na, title='R3 Label', color=#FF4000, location=location.absolute, text="R3")
plot(series=notHigherTimeframe ? r4Level : na, title='R4', color=pivot[1] != pivot and notHigherTimeframe ? na : #FF4000, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")? r4Level :na, title='R4 Label', color=#FF4000, location=location.absolute, text="R4")
plot(series=notHigherTimeframe ? r5Level : na, title='R5', color=pivot[1] != pivot and notHigherTimeframe ? na : #FF4000, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")? r5Level :na, title='R5 Label', color=#FF4000, location=location.absolute, text="R5")
plot(series=notHigherTimeframe ? s1Level : na, title='S1', color=pivot[1] != pivot and notHigherTimeframe ? na : #FF4000, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")? s1Level :na, title='S1 Label', color=#FF4000, location=location.absolute, text="S1")
plot(series=notHigherTimeframe ? s2Level : na, title='S2', color=pivot[1] != pivot and notHigherTimeframe ? na : #FF4000, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")? s2Level :na, title='S2 Label', color=#FF4000, location=location.absolute, text="S2")
plot(series=notHigherTimeframe ? s3Level : na, title='S3', color=pivot[1] != pivot and notHigherTimeframe ? na : #FF4000, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")? s3Level :na, title='S3 Label', color=#FF4000, location=location.absolute, text="S3")
plot(series=notHigherTimeframe ? s4Level : na, title='S4', color=pivot[1] != pivot and notHigherTimeframe ? na : #FF4000, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")? s4Level :na, title='S4 Label', color=#FF4000, location=location.absolute, text="S4")
plot(series=notHigherTimeframe ? s5Level : na, title='S5', color=pivot[1] != pivot and notHigherTimeframe ? na : #FF4000, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")? s5Level :na, title='S5 Label', color=#FF4000, location=location.absolute, text="S5")
plot(series=notHigherTimeframe ? h : na, title='PDH', color=pivot[1] != pivot and notHigherTimeframe ? na : color.white, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")? h :na, title='PDH Label', color=color.white, location=location.absolute, text="PDH")
plot(series=notHigherTimeframe ? l : na, title='PDL', color=pivot[1] != pivot and notHigherTimeframe ? na : color.white, style=plot.style_line, linewidth=1)
plotchar(timeframe.change("D")? l :na, title='PDL Label', color=color.white, location=location.absolute, text="PDL")